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

[BUG] PR #691 Broke PR #566 #768

Closed
adam-grant-hendry opened this issue Oct 17, 2023 · 1 comment · Fixed by #814
Closed

[BUG] PR #691 Broke PR #566 #768

adam-grant-hendry opened this issue Oct 17, 2023 · 1 comment · Fixed by #814
Labels
bug Something isn't working

Comments

@adam-grant-hendry
Copy link

Describe the bug

As noted in:

utilizing template overrides with the sphinx-book-theme results in the error:

Handler <function update_and_remove_templates at 0x000001A18C5BF700> for event 'html-page-context' threw an exception (exception: toggle-primary-sidebar.html)

The root cause was identified as PR #691, which reverted the following changes to __init__.py in PR #566:

  1. app.connect("config-inited", update_general_config) changed to app.connect("builder-inited", update_general_config)
  2. update_general_config parameter config removed (config-inited events issue two parameters)

The Sphinx class (from sphinx-docs) calls config.init_values() after the sphinx-book-theme extension is loaded, causing templates_path to be overridden and the path to sphinx_book_theme/theme/sphinx_book_theme/components lost.

Reproduce the bug

  1. Install sphinx-book-theme add add it to conf.py extensions
  2. Run sphinx-build -b html src build

Results in the following (see also pydata-sphinx-theme Issue #1511):

traceback:

Traceback (most recent call last):
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\events.py", line 96, in emit
results.append(listener.handler(self.app, *args))
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\pydata_sphinx_theme_init_.py", line 224, in update_and_remove_templates
context[section] = list(filter(remove_empty_templates, context[section]))
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\pydata_sphinx_theme_init
.py", line 219, in _remove_empty_templates
rendered = app.builder.templates.render(tname, context)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\jinja2glue.py", line 196, in render
return self.environment.get_template(template).render(context)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\jinja2\environment.py", line 1010, in get_template
return self._load_template(name, globals)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\jinja2\environment.py", line 969, in _load_template
template = self.loader.load(self, name, self.make_globals(globals))
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\jinja2\loaders.py", line 126, in load
source, filename, uptodate = self.get_source(environment, name)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\jinja2glue.py", line 217, in get_source
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: toggle-primary-sidebar.html

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

Traceback (most recent call last):
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\cmd\build.py", line 285, in build_main
app.build(args.force_all, args.filenames)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\application.py", line 353, in build
self.builder.build_update()
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\builders_init_.py", line 311, in build_update
self.build(to_build,
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\builders_init_.py", line 378, in build
self.write(docnames, list(updated_docnames), method)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\builders_init_.py", line 586, in write
self.write_serial(sorted(docnames))
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\builders_init
.py", line 596, in write_serial
self.write_doc(docname, doctree)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\builders\html_init
.py", line 672, in write_doc
self.handle_page(docname, ctx, event_arg=doctree)
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\builders\html_init_.py", line 1076, in handle_page
newtmpl = self.app.emit_firstresult('html-page-context', pagename,
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\application.py", line 481, in emit_firstresult
return self.events.emit_firstresult(event, *args,
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\events.py", line 117, in emit_firstresult
for result in self.emit(name, *args, allowed_exceptions=allowed_exceptions):
File "C:\Users\hendra11\Code\external\poetry_plugin_constrain.venv\lib\site-packages\sphinx\events.py", line 107, in emit
raise ExtensionError(__("Handler %r for event %r threw an exception") %
sphinx.errors.ExtensionError: Handler <function update_and_remove_templates at 0x000001B8B89F7AF0> for event 'html-page-context' threw an exception (exception: toggle-primary-sidebar.html)

Extension error (pydata_sphinx_theme):
Handler <function update_and_remove_templates at 0x000001B8B89F7AF0> for event 'html-page-context' threw an exception (exception: toggle-primary-sidebar.html)

List your environment

OS: Windows 10, 20H2
python: 3.8.10
Sphinx: 6.2.1
jinja2: 3.1.2
sphinx-book-theme: 1.0.1
pydata-sphinx-theme: 0.14.1

@adam-grant-hendry adam-grant-hendry added the bug Something isn't working label Oct 17, 2023
@welcome
Copy link

welcome bot commented Oct 17, 2023

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant