Holzhaus / sphinx-multiversion

Sphinx extension for building self-hosted versioned docs.
https://holzhaus.github.io/sphinx-multiversion/
BSD 2-Clause "Simplified" License
148 stars 65 forks source link

Extension error (`pydata_sphinx_theme`) #106

Closed adam-grant-hendry closed 9 months ago

adam-grant-hendry commented 9 months ago

Problem

sphinx-multiversion returns the following error when pydata_sphinx_theme is used:

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

(NOTE: The actual extension being used is sphinx_book_theme, which builds off of pydata_sphinx_theme).

Command Run:

> sphinx-multiversion docs/src docs/build/html
Full Traceback: ``` Running Sphinx v6.2.1 [autosummary] generating autosummary for: index.rst building [mo]: targets for 0 po files that are out of date writing output... building [html]: targets for 1 source files that are out of date updating environment: [new config] 1 added, 0 changed, 0 removed reading sources... [100%] index looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [ 100%] index Extension error (pydata_sphinx_theme): Handler for event 'html-page-context' threw an exception (exception: toggle-primary-sidebar.html) Traceback (most recent call last): File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\events.py", line 96, in emit results.append(listener.handler(self.app, *args)) File "%USERPROFILE%\Code\external\my_project\.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 "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\pydata_sphinx_theme\__init__.py", line 219, in _remove_empty_templates rendered = app.builder.templates.render(tname, context) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\jinja2glue.py", line 196, in render return self.environment.get_template(template).render(context) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\jinja2\environment.py", line 1010, in get_template return self._load_template(name, globals) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\jinja2\environment.py", line 969, in _load_template template = self.loader.load(self, name, self.make_globals(globals)) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\jinja2\loaders.py", line 126, in load source, filename, uptodate = self.get_source(environment, name) File "%USERPROFILE%\Code\external\my_project\.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 "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\cmd\build.py", line 285, in build_main app.build(args.force_all, args.filenames) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\application.py", line 353, in build self.builder.build_update() File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\builders\__init__.py", line 311, in build_update self.build(to_build, File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\builders\__init__.py", line 378, in build self.write(docnames, list(updated_docnames), method) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\builders\__init__.py", line 586, in write self._write_serial(sorted(docnames)) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\builders\__init__.py", line 596, in _write_serial self.write_doc(docname, doctree) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\builders\html\__init__.py", line 672, in write_doc self.handle_page(docname, ctx, event_arg=doctree) File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\builders\html\__init__.py", line 1076, in handle_page newtmpl = self.app.emit_firstresult('html-page-context', pagename, File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\application.py", line 481, in emit_firstresult return self.events.emit_firstresult(event, *args, File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx\events.py", line 117, in emit_firstresult for result in self.emit(name, *args, allowed_exceptions=allowed_exceptions): File "%USERPROFILE%\Code\external\my_project\.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) Traceback (most recent call last): File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "%USERPROFILE%\Code\external\my_project\.venv\Scripts\sphinx-multiversion.exe\__main__.py", line 7, in File "%USERPROFILE%\Code\external\my_project\.venv\lib\site-packages\sphinx_multiversion\main.py", line 338, in main subprocess.check_call(cmd, cwd=current_cwd) File "C:\Program Files\Python38\lib\subprocess.py", line 364, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '('%USERPROFILE%\\Code\\external\\my_project\\.venv\\Scripts\\python.exe', '-R', '-m', 'sphinx', '-vvv', '-D', 'smv_metadata_path=%LOCALAPPDATA%\\Temp\\tmpkxpno37u\\versions.json', '-D', 'smv_current_version=0.1.0', '-c', '%USERPROFILE%\\Code\\external\\my_project\\docs\\src', '%LOCALAPPDATA%\\Temp\\tmpkxpno37u\\928fceb6dbdc58e43c0a55a1eed97cceb38cf5f8\\docs\\src', '%USERPROFILE%\\Code\\external\\my_project\\docs\\build\\html\\0.1.0')' returned non-zero exit status 2. ```

System Information:

OS: Windows 10 Python: 3.8.10 jinja2: 3.1.2 sphinx: 6.2.1 sphinx-multiversion: 0.2.4 pydata_sphinx_theme: 0.14.1 sphinx_book_theme: 1.0.1

MRE:

Project Layout:

my_project/
├─docs/
│ ├─src/
│ │ ├─conf.py
│ │ ├─index.rst
│ │ ├─_templates/
│ │ │ ├─page.html
│ │ │ └─versioning.html
│ │ └─__init__.py
│ └─__init__.py
└─src/
  └─my_project/
    └─__init__.py
conf.py ```python import importlib.resources as rsrc import os import sys from datetime import datetime, timezone from importlib import metadata # Project information project = 'my_project' author = 'John Doe' root_package = project version = metadata.version(project) release = version # Path setup with rsrc.path(root_package, '__init__.py') as file_: root = file_.parent.parent packages = [ root / root_package, root / r'docs', ] for pkg in packages: sys.path.insert(0, os.fspath(pkg.resolve())) # Extensions extensions: list[str] = [ 'sphinx_book_theme', 'sphinx.ext.napoleon', 'sphinx.ext.githubpages', 'sphinx_multiversion', ] # General Configuration templates_path = ['_templates'] source_suffix = '.rst' master_doc = 'index' # List of files relative to ``source`` to ignore when looking for source files exclude_patterns: list[str] = [ '_build', ] # Versioning Configuration smv_branch_whitelist = r'main' # HTML Output html_theme = 'sphinx_book_theme' html_sidebars = { '**': [ 'versioning.html', ] } ```
index.rst ```rst ######## my_project ######## Hello world! ```
page.html ```html {% extends "!page.html" %} {% block body %} {% if current_version and latest_version and current_version != latest_version %}

{% if current_version.is_released %} You're reading an old version of this documentation. If you want up-to-date information, please have a look at {{latest_version.name}}. {% else %} You're reading the documentation for a development version. For the latest released version, please have a look at {{latest_version.name}}. {% endif %}

{% endif %} {{ super() }} {% endblock %}% ```
versioning.html ```html {% if versions %}

{{ _('Versions') }}

{% endif %} ```
adam-grant-hendry commented 9 months ago

Linking pydata_sphinx_theme #1392 as this might also be helpful.

adam-grant-hendry commented 9 months ago

Closing as project is unmaintained and issue is related to pydata_sphinx_theme.