Python Sphinx accessing the html_context from within conf.py

Viewed 302

I have a sphinx project with an extension that provides a set of values that can be accessed in the template files from the html_context.

I would like to make a slight modification depending on one of these extension provided variables inside of my conf.py file. The sphinx documentation only states how to provide more html_context values to the templates but not how to read out extension generated html_context values from within conf.py. Is there a good method to achieving this or are these values generated after conf.py has been read and executed?

1 Answers

The html_context is filled in the main entrypoint, and it's passed to the Sphinx object as part of the confoverrides:

https://github.com/sphinx-doc/sphinx/blob/3d8fbd992cedf1784b106cf43ecbc452953ebe17/sphinx/cmd/build.py#L267-L277

which are then combined with the actual settings from conf.py to create the Config object:

https://github.com/sphinx-doc/sphinx/blob/3d8fbd992cedf1784b106cf43ecbc452953ebe17/sphinx/application.py#L216

Therefore, from my understanding, conf.py never sees this html_context and what you are asking can't be done.

Related