-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just cleanup!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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-inited
has already triggered by the time we register the listener - SBT is both a theme and extension, in which case the
app.config
insetup()
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 🤞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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-inited
to set this value before the theme is required.setup()
ensures that the theme search path (increate_template_bridge
is 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.