Description
Describe the bug
I am trying to modify the app config if the user has not already provided a value. I'm trying to do these two things:
- Add an extension to the extensions list if the
conf.py
hasn't initialized it already - Set a value in the config if it hasn't been specified in
conf.py
.
I'm trying to do this by registering a callback function attached to config-inited
. However, it seems that this callback function is never being called, and so I am not sure how I'm supposed to set the config before the builder
is initialized.
How to Reproduce
Here's a rough idea of code that I tried and that suggested to me the event wasn't being emitted. I added the THIS-SHOULD-BREAK at the end to try and get Sphinx to throw an error, but it never did.
def set_config_defaults(app, config):
theme = config.html_theme_options
# Navigation bar
if "navbar_align" not in theme:
theme["theme_navbar_align"] = "left"
if "foo" not in config.extensions:
extensions.append("foo")
THIS-SHOULD-BREAK
def setup(app):
app.connect("config-inited", set_config_defaults)
Expected behavior
set_config_defaults
should modify the config, and these changes should propagate to the app
build.
Your project
https://github.com/pydata/pydata-sphinx-theme
Screenshots
No response
OS
Linux
Python version
3.9
Sphinx version
5.0.1
Sphinx extensions
No response
Extra tools
No response
Additional context
For activating a new extension, I also tried app.setup_extension("extension-name")
, but this then seemed to activate the extension without setting any config values (they were all None
), which led to errors in the build. Activating the same extension manually in conf.py
worked fine.