executablebooks / sphinx-book-theme

A clean book theme for scientific explanations and documentation with Sphinx
https://sphinx-book-theme.readthedocs.io
BSD 3-Clause "New" or "Revised" License
413 stars 196 forks source link

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

Closed adam-grant-hendry closed 5 months ago

adam-grant-hendry commented 9 months ago

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 for event 'html-page-context' threw an exception (exception: toggle-primary-sidebar.html) Extension error (pydata_sphinx_theme): Handler 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

welcome[bot] commented 9 months ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
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! :tada: