Skip to content

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

@adam-grant-hendry

Description

@adam-grant-hendry

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions