readthedocs / sphinx_rtd_theme

Sphinx theme from Read the Docs
https://sphinx-rtd-theme.readthedocs.io/
MIT License
4.75k stars 1.73k forks source link

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

Closed kuripart closed 1 year ago

kuripart commented 1 year ago

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

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

dvzrv commented 1 year ago

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 commented 1 year ago

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:

https://github.com/readthedocs/sphinx_rtd_theme/blob/03a86b803cf7cf281748ef94345ba7c35953952a/sphinx_rtd_theme/layout.html#L27-L30

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 commented 1 year ago

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

benjaoming commented 1 year ago

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/

dvzrv commented 1 year ago

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

dvzrv commented 1 year ago

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

benjaoming commented 1 year ago

Thanks for sharing @dvzrv :+1:

ain-soph commented 1 year ago

@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?

https://github.com/readthedocs/sphinx_rtd_theme/blob/03a86b803cf7cf281748ef94345ba7c35953952a/sphinx_rtd_theme/layout.html#L28

benjaoming commented 1 year ago

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

ain-soph commented 1 year ago

@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.

https://github.com/readthedocs/sphinx_rtd_theme/blob/03a86b803cf7cf281748ef94345ba7c35953952a/sphinx_rtd_theme/layout.html#L28


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

image
benjaoming commented 1 year ago

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

https://github.com/readthedocs/sphinx_rtd_theme/issues/1465#issuecomment-1531262630

ain-soph commented 1 year ago

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

benjaoming commented 1 year ago

No worries, these issues are pretty complex to juggle :+1:

peterjc commented 1 year ago

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 commented 1 year ago

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!