FIX: use config-inited event to register config#814
Conversation
| class Margin(Sidebar): | ||
| """Goes in the margin to the right of the page.""" | ||
|
|
||
| optional_arguments = 1 | ||
| required_arguments = 0 | ||
|
|
||
| def run(self): | ||
| """Run the directive.""" | ||
| if not self.arguments: | ||
| self.arguments = [""] | ||
| nodes = super().run() | ||
| nodes[0].attributes["classes"].append("margin") | ||
|
|
||
| # Remove the "title" node if it is empty | ||
| if not self.arguments: | ||
| nodes[0].children.pop(0) | ||
| return nodes | ||
|
|
||
|
|
for more information, see https://pre-commit.ci
…-config' into agoose77/fix-update-config
for more information, see https://pre-commit.ci
…-config' into agoose77/fix-update-config
for more information, see https://pre-commit.ci
…-config' into agoose77/fix-update-config
|
@ghisvail, @adam-grant-hendry, @choldgraf I'm pinging you three as the most recent investigators of the issue with SBT's use in extensions. This PR makes the changes suggested by @adam-grant-hendry in a closed PR, which is to convert the If you don't have any bandwidth for this, please let me know! I'll just make a release and we'll deal with the fall-out through normal channels (if there is any!). |
|
I am not familiar with the specifics of Sphinx et al. All I can offer is to test whether things work appropriately with the new release. |
| # Meanwhile, extensions are initialised _first_, and any config | ||
| # values set during setup() will be overwritten. We must therefore | ||
| # register the `config-inited` event to set these config options | ||
| app.connect("config-inited", update_general_config) |
There was a problem hiding this comment.
I thought that for some folks if the config initialization was called twice, it would raise an error. If that's not the case then I think it's fine to just do this twice as long as nobody reports regressions
There was a problem hiding this comment.
@choldgraf to be clear, I don't think this should ever set the config twice. AFAICT either:
- SBT is only used as a theme, which means
config-initedhas already triggered by the time we register the listener - SBT is both a theme and extension, in which case the
app.configinsetup()is nearly immediately clobbered.
I'm hoping that isn't a cause of bugs, and I've not seen any evidence as yet to suggest it might be 🤞
choldgraf
left a comment
There was a problem hiding this comment.
I don't have much time to do a thorough review but as long as there aren't regressions and folks report expected behavior I'm +1
config-inited event to register configconfig-inited event to register config
config-inited event to register configconfig-inited event to register config
|
Dear all, sorry to reopen this thread, but I'm quite sure this MR breaks the Jupyter-Book compilation. The error message is the following one: Steps to reproduce:
No issues found when reverting to 1.1.0 version. Thanks in advance and apologies if the culprit is not here! |
|
@frgigr that's a new bug! Thanks for reporting it, will issue a fix. |
Fixes #768, obviates need for jupyter-book/jupyter-book#2111
I'll restate the rationale here:
The registration order is as follows:
[[extensions]] sphinx::Application.setup_extension()sphinx::Config.init_values()<config-inited>sphinx::Builder.init()[[theme]] sphinx::Registry.load_extension()sphinx::Builder.create_template_bridge()<builder-inited>Crucially:
setup()are subsequently clobbered bysphinx::Config.init_values.setup()is called exclusively once for a theme/extension, so these variables are never set again.config-initedto set this value before the theme is required.setup()ensures that the theme search path (increate_template_bridgeis correct.sphinx::Registry.load_extension) before the path is required (insphinx::Builder.create_template_bridge) i.e. before any further events are dispatched.What's happening in JB and other users is that they're using SBT as both a theme and an extension, so we start at the top of the registration order. Thus, we need to support both use cases, i.e. set config twice. This is acceptable because due to the registration system we either see
<config-inited>, but not fromsetup()setup(), after<config-inited>is dispatchedFinally, it should be noted that SBT needs to be in extensions whilst it adds features (the margin directive) that are non-HTML focused.