Skip to content

Configuration options added by themes are not properly loaded #10061

@pradyunsg

Description

@pradyunsg

Describe the bug

If you have a Sphinx theme that registers a configuration variable, that configuration variable is not loaded properly from the conf.py file -- i.e. is not accessible as app.config.{name}.

How to Reproduce

$ git clone https://github.com/pradyun/sphinx-configuration-bug.git
$ cd sphinx-configuration-bug
$ pip install .
$ sphinx-build docs/ docs/_build/
Running Sphinx v4.3.2
loading pickled environment... done
====================================================================================================
sorted(vars(config))=['_raw_config', 'epub_css_files', 'extensions', 'html_css_files', 'html_js_files', 'html_theme', 'numfig_format', 'overrides', 'setup', 'source_suffix', 'values']
config.sample_theme_configuration_value='default'
config._raw_config['sample_theme_configuration_value']='from conf.py'
====================================================================================================
sorted(vars(config))=['_raw_config', 'epub_css_files', 'extensions', 'html_css_files', 'html_js_files', 'html_theme', 'numfig_format', 'overrides', 'sample_theme_configuration_value', 'setup', 'source_suffix', 'values']
config.sample_theme_configuration_value='from conf.py'
config._raw_config['sample_theme_configuration_value']='from conf.py'
====================================================================================================
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
no targets are out of date.
build succeeded.

The HTML pages are in docs/_build.

The second section is what things look like, after running config.init_values() again.

Expected behavior

Configuration variables from the theme are loaded properly, without needing to re-initialize the configuration object.

Your project

https://github.com/pradyun/sphinx-configuration-bug/

Screenshots

No response

OS

MacOS (should happen on all OSes)

Python version

3.9, although unlikely to be implicated

Sphinx version

4.3.2

Sphinx extensions

None

Extra tools

No response

Additional context

I had first encountered this in Furo and couldn't figure out what's up. Some more investigation as a part of writing a follow up theme (python/docs-community#1) led to me hitting this again; which... lead to this bug report. :)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions