Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme error: UndefinedError("'style' is undefined") #1465

Closed
kuripart opened this issue May 1, 2023 · 15 comments
Closed

Theme error: UndefinedError("'style' is undefined") #1465

kuripart opened this issue May 1, 2023 · 15 comments
Labels
Bug A bug Needed: replication Bug replication is required

Comments

@kuripart
Copy link

kuripart commented May 1, 2023

Problem

Getting following error when building a Sphinx project:

#14 2.108 Theme error:
#14 2.108 An error happened in rendering the page about.
#14 2.108 Reason: UndefinedError("'style' is undefined")

conf.py includes the following:

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

Setting html_style doesn't fix the issue as well.

Reproducible Project

Please give a link to a public reproducible project or provide an example of the Restructured Text that gives an issue.

Place RST code here (if any).

Error Logs/Results

#14 2.108 Theme error:
#14 2.108 An error happened in rendering the page about.
#14 2.108 Reason: UndefinedError("'style' is undefined")

Expected Results

Setting any other html_theme eg: 'bizstyle' works as expected.

Environment Info

  • Python Version: 3.9
  • Sphinx Version: 7.0.0
  • RTD Theme Version: 1.2.0

Happy to share the Dockerfile and Pipifile setting if the info provided is not enough.

@kuripart kuripart added Bug A bug Needed: replication Bug replication is required labels May 1, 2023
@dvzrv
Copy link

dvzrv commented May 2, 2023

Hi! I am running into the same issue trying to build libcamera's documentation on Arch Linux.
This is with sphinx 7.0.0 and sphinx_rtd_theme 1.2.0 on Python 3.11.

@benjaoming
Copy link
Contributor

Hi! Thanks for stopping by and reporting this!

Do you have an open source repo that produces this error?

There's no variables or properties in the theme's Python code called style, so I wondered if it could be related to Jinja2 template code and found this:

{%- if sphinx_version_info < (4, 0) -%}
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
{%- endif %}

As you can see, this code is guarded to only be used on old versions of Sphinx. But could the variable substitution still be causing the error?

@alerque
Copy link

alerque commented May 2, 2023

The libcamera named by David as an example failure above has its repo here and is open source.

@benjaoming
Copy link
Contributor

Thanks! I'm wondering why some Sphinx 7 builds work fine. For instance, this build doesn't produce the error:

https://readthedocs.org/projects/test-builds/builds/20357244/

Chilipp added a commit to Chilipp/autodocsumm that referenced this issue May 2, 2023
Chilipp added a commit to Chilipp/autodocsumm that referenced this issue May 2, 2023
@dvzrv
Copy link

dvzrv commented May 2, 2023

@polyzen found a fix for the libcamera issue ❤️
https://paste.xinu.at/JfsPm/

@dvzrv
Copy link

dvzrv commented May 2, 2023

It turned out to be not sphinx_rtd_theme related (just the use of a removed keyword). Sorry for the noise!

@benjaoming
Copy link
Contributor

Thanks for sharing @dvzrv 👍

@ain-soph
Copy link

@benjaoming @dvzrv Hi, sorry for disturbing! I see there are still style (instead of styles[-1]) used in sphinx-rtd-theme layout.html. Is that still working for sphinx>=7.0.0?

<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />

@benjaoming
Copy link
Contributor

@ain-soph most people who ran into this issue were running an old version of sphinx-rtd-theme.

@ain-soph
Copy link

ain-soph commented May 14, 2023

@ain-soph most people who ran into this issue were running an old version of sphinx-rtd-theme.

I agree. But it seems in the most up-to-date sphinx-rtd-theme layout.html, it's still using style variable, which is already deprecated in sphinx>=7.0. I believe this would lead to compilation error for all docs using sphinx-rtd-theme on new sphinx versions.

<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />


https://www.sphinx-doc.org/en/master/changes.html

image

@benjaoming
Copy link
Contributor

benjaoming commented May 14, 2023

@ain-soph It seems to work fine with Sphinx 7 because that statement is guarded by a version clause - see:

#1465 (comment)

@ain-soph
Copy link

Oops... I didn't even notice this if condition. Quite silly I am! 😓 Thanks for your time!

@benjaoming
Copy link
Contributor

No worries, these issues are pretty complex to juggle 👍

@peterjc
Copy link

peterjc commented Jul 22, 2023

For anyone else hitting this after updating to Sphinx 7, make sure to also update the theme.

Working (old sphinx, old theme):

$ mamba list | grep sphinx
sphinx                    6.2.1              pyhd8ed1ab_0    conda-forge
sphinx_rtd_theme          0.4.3              pyhd3eb1b0_0  
sphinxcontrib-applehelp   1.0.4              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge

Failing (new sphinx, old theme):

$ mamba list | grep sphinx
sphinx                    7.0.1              pyhd8ed1ab_0    conda-forge
sphinx_rtd_theme          0.4.3              pyhd3eb1b0_0  
sphinxcontrib-applehelp   1.0.4              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge

Working (both sphinx and theme up to date):

$ mamba list | grep sphinx
sphinx                    6.2.1              pyhd8ed1ab_0    conda-forge
sphinx_rtd_theme          1.2.2              pyha770c72_0    conda-forge
sphinxcontrib-applehelp   1.0.4              pyhd8ed1ab_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.1              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jquery      4.1                pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge

Kartstig added a commit to Kartstig/flask-meter that referenced this issue Jul 27, 2023
@Kartstig
Copy link

I also encountered this as I didn't have some of my dependencies constrained and things upgraded into a failing state. I was able to use the last combination provided by @peterjc to get things working again.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug Needed: replication Bug replication is required
Projects
None yet
Development

No branches or pull requests

7 participants