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

UndefinedError("'style' is undefined") #1571

Closed
douglas-raillard-arm opened this issue Jul 12, 2024 · 10 comments
Closed

UndefinedError("'style' is undefined") #1571

douglas-raillard-arm opened this issue Jul 12, 2024 · 10 comments
Labels
Bug A bug Needed: replication Bug replication is required

Comments

@douglas-raillard-arm
Copy link

Problem

Doc builds with sphinx-rtd-theme seems to have stopped working in our CI. I cannot reproduce locally unfortunately, even with the same Python version (but not same distro version).

Reproducible Project

Project: https://gitlab.arm.com/tooling/lisa
I could not manage to reproduce the issue outside our CI, but the doc build can be achieved with:

git clone https://git.gitlab.arm.com/tooling/lisa.git
# This will be taken into account when the venv is created. A python3.11 binary needs to exist in the PATH.
export LISA_PYTHON=python3.11
cd lisa
# This will create a venv
source init_env
# Build the doc under ./doc/_build
lisa-doc-build

Error Logs/Results

This started failing this week out of the blue:
https://gitlab.arm.com/tooling/lisa/-/jobs/70959

reading sources... [ 75%] misc_utilities .. workflows/automated_testing
reading sources... [100%] workflows/index .. workloads
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets... copying static files... done
copying extra files... done
done
Traceback (most recent call last):
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 1119, in handle_page
    output = self.templates.render(templatename, ctx)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/jinja2glue.py", line 200, in render
    return self.environment.get_template(template).render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/themes/basic/page.html", line 10, in top-level template code
    {%- extends "layout.html" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx_rtd_theme/layout.html", line 23, in top-level template code
    <link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
    ^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'style' is undefined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/cmd/build.py", line 337, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/application.py", line 351, in build
    self.builder.build_update()
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 293, in build_update
    self.build(to_build,
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 362, in build
    self.write(docnames, list(updated_docnames), method)
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 567, in write
    self._write_parallel(sorted(docnames),
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 594, in _write_parallel
    self.write_doc(firstname, doctree)
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 665, in write_doc
    self.handle_page(docname, ctx, event_arg=doctree)
  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 1126, in handle_page
    raise ThemeError(__("An error happened in rendering the page %s.\nReason: %r") %
sphinx.errors.ThemeError: An error happened in rendering the page bisector/api.
Reason: UndefinedError("'style' is undefined")
Theme error:
An error happened in rendering the page bisector/api.
Reason: UndefinedError("'style' is undefined")

Expected Results

The doc should build successfully

Environment Info

  • Python Version: 3.11
  • Sphinx Version: 7.3.7
  • RTD Theme Version: 2.0.0
@douglas-raillard-arm douglas-raillard-arm added Bug A bug Needed: replication Bug replication is required labels Jul 12, 2024
@geo-martino
Copy link

geo-martino commented Jul 25, 2024

Second this. Receiving the exact same error out of almost nowhere when building pages on this repo here: https://github.com/geo-martino/musify.

Can be replicated by cloning the repo, installing the docs optional dependencies via pip install .[docs] and running make rebuild-html.

Logs here: https://github.com/geo-martino/musify/actions/runs/10099215047/job/27927927658

@zaufi
Copy link

zaufi commented Jul 29, 2024

Also hit this error w/ Sphinx 8.0.0 (also tried 7.4.7, 7.2.6) and sphinx_rtd_theme

@humitos
Copy link
Member

humitos commented Jul 31, 2024

Taking a look at the description of the issue I can say from this error line that the style variable is not present in the HTML context for Jinja.

  File "/home/ubuntu/builds/iyA2D7ai/0/tooling/lisa/tmp/tmp.0VAnEEbH4h-worktree/.lisa-venv-3.11/lib/python3.11/site-packages/sphinx_rtd_theme/layout.html", line 23, in top-level template code
    <link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />

I tried using Sphinx 8 in #1576 and all the tests run without issues. We will need a a minimal reproducible example that triggers this issue to be able to reproduce it.

@zaufi
Copy link

zaufi commented Jul 31, 2024

Also hit this error w/ Sphinx 8.0.0 (also tried 7.4.7, 7.2.6) and sphinx_rtd_theme

Reproduced in my pipeline w/ Sphinx 8.0.2:
https://github.com/zaufi/pytest-matcher/actions/runs/10182227565/job/28164231159#step:9:46

@humitos
Copy link
Member

humitos commented Jul 31, 2024

@zaufi can you provide a minimal reproducible example (including the step by step commands to run) that I can run in my local instance so I can debug it in deep?

@zaufi
Copy link

zaufi commented Jul 31, 2024

@zaufi can you provide a minimal reproducible example (including the step by step commands to run) that I can run in my local instance so I can debug it in deep?

Just tried to make a trivial project inside a test venv and I've failed to reproduce it even copying the config and some RST files out of my project.

But it 100% reproducible w/ my pet project in 3 steps:

$ git clone https://github.com/zaufi/pytest-matcher.git
Cloning into 'pytest-matcher'...
remote: Enumerating objects: 1100, done.
remote: Counting objects: 100% (404/404), done.
remote: Compressing objects: 100% (126/126), done.
remote: Total 1100 (delta 307), reused 352 (delta 274), pack-reused 696
Receiving objects: 100% (1100/1100), 315.09 KiB | 766.00 KiB/s, done.
Resolving deltas: 100% (602/602), done.

$ cd pytest-matcher/

$ hatch run doc:build
Running Sphinx v8.0.2
loading translations [en]... done
making output directory... done
Converting `source_suffix = ['.rst']` to `source_suffix = {'.rst': 'restructuredtext'}`.
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 7 source files that are out of date
updating environment: [new config] 7 added, 0 changed, 0 removed
reading sources... [100%] latest-changelog
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets...
copying static files... done
copying extra files... done
copying assets: done

Theme error:
An error happened in rendering the page api.
Reason: UndefinedError("'style' is undefined")

Where the doc:build is an alias for sphinx-build --color -j auto doc/ build/sphinx/html/. So, for example to add -v or other agrs you can use:

$ hatch run doc:sphinx-build -vv --color -j auto doc/ build/sphinx/html/

Traceback (most recent call last):
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/builders/html/__init__.py", line 1160, in handle_page
    output = self.templates.render(templatename, ctx)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/jinja2glue.py", line 201, in render
    return self.environment.get_template(template).render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/themes/basic/page.html", line 10, in top-level template code
    {%- extends "layout.html" %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx_rtd_theme/layout.html", line 23, in top-level template code
    <link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css" />
    ^^^^^^^^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'style' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/cmd/build.py", line 337, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/application.py", line 378, in build
    self.builder.build_update()
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 296, in build_update
    self.build(to_build,
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 366, in build
    self.write(docnames, list(updated_docnames), method)
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 610, in write
    self._write_parallel(sorted(docnames),
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/builders/__init__.py", line 637, in _write_parallel
    self.write_doc(firstname, doctree)
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/builders/html/__init__.py", line 675, in write_doc
    self.handle_page(docname, ctx, event_arg=doctree)
  File "/home/exher/tmp/pytest-matcher/.venv/doc/lib/python3.12/site-packages/sphinx/builders/html/__init__.py", line 1167, in handle_page
    raise ThemeError(__("An error happened in rendering the page %s.\nReason: %r") %
sphinx.errors.ThemeError: An error happened in rendering the page api.
Reason: UndefinedError("'style' is undefined")

Theme error:
An error happened in rendering the page api.
Reason: UndefinedError("'style' is undefined")

@humitos
Copy link
Member

humitos commented Aug 1, 2024

Thanks @zaufi for sharing those steps.

I was able to find the issue. The style variable was removed from the html_context and it's not passed anymore to Jinja templates. That's why it's failing. It was removed in this PR sphinx-doc/sphinx#11381.

However, we adapted our code already for that change and it should be working fine. Make sure you are installing the latest stable version of our theme, 2.0.0

If that doesn't work, please use our latest 2.1.0rc1 and let us know if that solves the issue. Thanks.

@zaufi
Copy link

zaufi commented Aug 1, 2024

Requiring sphinx < 8.0 and sphinx_rtd_theme >= 2.0 makes it work again.

Thank you!

ceblanton pushed a commit to NOAA-GFDL/fre-cli that referenced this issue Aug 5, 2024
…rror

Appears to be caused by a mismatch of sphinx and sphinx-rtd-theme
readthedocs/sphinx_rtd_theme#1571
@njzjz
Copy link

njzjz commented Aug 6, 2024

I got this error when sphinx==8.0.0 and sphinx-rtd-theme==0.5.1 were installed. Pining sphinx-rtd-theme to >=0.6 gives me the correct sphinx and sphinx-rtd-theme versions.

@humitos
Copy link
Member

humitos commented Aug 7, 2024

I'm closing this issue since it's not a problem in the latest versions of the theme. The problem comes from installing an older version of our theme with a newer version of Sphinx.

@humitos humitos closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2024
njzjz added a commit to njzjz/dpgen that referenced this issue Aug 9, 2024
See readthedocs/sphinx_rtd_theme#1571 (comment)

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
wanghan-iapcm pushed a commit to deepmodeling/dpgen that referenced this issue Aug 9, 2024
See
readthedocs/sphinx_rtd_theme#1571 (comment)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Chores**
- Updated the version constraint for the `sphinx_rtd_theme` package to
ensure compatibility, enhancing project stability and performance.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
ashwinvis added a commit to ENCCS/sphinx-lesson-template that referenced this issue Aug 30, 2024
Pinning a minimum version of `sphinx-rtd-theme >= 2.0.0` mitigate from getting old version of sphinx-rtd-theme.

readthedocs/sphinx_rtd_theme#1571 (comment)
ashwinvis added a commit to ENCCS/sphinx-lesson-template that referenced this issue Sep 2, 2024
Pinning a minimum version of `sphinx-rtd-theme >= 2.0.0` mitigate from getting old version of sphinx-rtd-theme.

readthedocs/sphinx_rtd_theme#1571 (comment)
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

6 participants
@humitos @zaufi @njzjz @douglas-raillard-arm @geo-martino and others