-
Notifications
You must be signed in to change notification settings - Fork 131
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
Prevent adding a source suffix twice #637
Conversation
I can really see documentation taking advantages of both extensions. |
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.
Thanks for this PR!
src/nbsphinx.py
Outdated
app.add_source_suffix('.ipynb', 'jupyter_notebook') | ||
for suffix in config.nbsphinx_custom_formats: | ||
app.add_source_suffix(suffix, 'jupyter_notebook') | ||
suffixes = [".ipynb", *config.nbsphinx_custom_formats] |
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 think that the nbsphinx_custom_formats
have to be checked further. They are provided by the user, so it's the user's responsibility not to provide conflicting suffixes.
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 see. Does this nbsphinx_custom_formats
config do anything else that sphinx's source_suffix
don't do? https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-source_suffix
so it's the user's responsibility not to provide conflicting suffixes
Actually my understanding is that sphinx's source_suffix
is a way for users to overwrite anything that extensions have setup, so it's not really the same thing? Or am I completely misunderstanding all this? (sphinx beginner here)
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.
Does this
nbsphinx_custom_formats
config do anything else that sphinx'ssource_suffix
don't do?
Yes. In addition to registering the source suffix, it also provides a function that transforms a string containing certain custom format into a Jupyter notebook object. See https://nbsphinx.readthedocs.io/custom-formats.html.
But I assume that if a user provides a custom format, they don't want their chosen suffix to be overwritten by some other Sphinx extension.
And if another extension is loaded after nbsphinx
, I prefer an error over silently ignoring the source suffix.
And if a user provides nbsphinx_custom_formats
and a conflicting source_suffix
, it's their own fault.
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.
@martinRenou Do you want to update this PR or should I do it?
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.
Please do it if you can :) Thanks a lot!
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 have rebased your branch and I've added fc79fd1 that unconditionally adds nbsphinx_custom_formats
.
Can you please test if that works for you?
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.
Thanks a lot! I'll give it a try
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've merged this PR already, but please let me know if it doesn't work as expected, so we can fix that.
ecbbc4c
to
fc79fd1
Compare
PR coupled with jupyterlite/jupyterlite-sphinx#28
This prevents collisions between nbsphinx and jupyterlite-sphinx which both add the
".ipynb"
source prefix: ifapp.registry.source_suffix
already contains "ipynb", then do nothing.The behavior will then be the following:
conf.py