Skip to content

Sphinx >7.3.2 imports themes in env, even if not set via html_theme #12299

@lucyleeow

Description

@lucyleeow

Describe the bug

Noticed with Sphinx >7.3.2 and pydata-sphinx-theme.

  1. make a clean sphinx setup with sphinx-quickstart
  2. Don't change conf.py at all, default theme is 'alabaster' but pydata-sphinx-theme is installed in env
  3. run make html and I get the following error:
Extension error (pydata_sphinx_theme.pygment):
Handler <function overwrite_pygments_css at 0x7ff2b211eef0> for event 'build-finished' threw an exception (exception: 'pygment_light_style')

full error message from a test failure (from sphinx-gallery/sphinx-gallery#1243):

../../../micromamba/envs/test/lib/python3.11/site-packages/sphinx/events.py:97: in emit
    results.append(listener.handler(self.app, *args))
../../../micromamba/envs/test/lib/python3.11/site-packages/pydata_sphinx_theme/pygment.py:81: in overwrite_pygments_css
    style_name = app.builder.theme.get_options()[style_key]
E   KeyError: 'pygment_light_style'

The above exception was the direct cause of the following exception:
sphinx_gallery/tests/test_gen_gallery.py:493: in test_show_memory_callable
    sphinx_app = sphinx_app_wrapper.build_sphinx_app()
sphinx_gallery/tests/conftest.py:179: in build_sphinx_app
    app.build(*args, **kwargs)
../../../micromamba/envs/test/lib/python3.11/site-packages/sphinx/application.py:353: in build
    self.events.emit('build-finished', None)
../../../micromamba/envs/test/lib/python3.11/site-packages/sphinx/events.py:108: in emit
    raise ExtensionError(
E   sphinx.errors.ExtensionError: Handler <function overwrite_pygments_css at 0x11884d6c0> for event 'build-finished' threw an exception (exception: 'pygment_light_style')

Note pygment.overwrite_pygments_css in pydata-sphinx-theme is connected to 'build-finished' (ref)

Tested and fine with Sphinx 7.3.0 and 7.3.1. If I uninstall pydata-sphinx-theme its also fine.

Could it be related to: 982681b ?

How to Reproduce

  1. make a clean sphinx setup with sphinx-quickstart, include pydata-sphinx-theme in env
  2. run make html

Environment Information

Platform:              linux; (Linux-5.15.0-102-generic-x86_64-with-glibc2.35)
Python version:        3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0])
Python implementation: CPython
Sphinx version:        7.3.2
Docutils version:      0.20.1
Jinja2 version:        3.1.2
Pygments version:      2.17.2

Sphinx extensions

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions