Skip to content
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

Merged
merged 2 commits into from
Sep 2, 2022

Conversation

martinRenou
Copy link
Contributor

PR coupled with jupyterlite/jupyterlite-sphinx#28

This prevents collisions between nbsphinx and jupyterlite-sphinx which both add the ".ipynb" source prefix: if app.registry.source_suffix already contains "ipynb", then do nothing.

The behavior will then be the following:

conf.py

# nbsphinx will handle .ipynb files and jupyterlite-sphinx won't
extensions = [
    'nbsphinx',
    'jupyterlite_sphinx',
]

# jupyterlite-sphinx will handle .ipynb files and nbsphinx won't
extensions = [
    'jupyterlite_sphinx',
    'nbsphinx',
]

@martinRenou
Copy link
Contributor Author

I can really see documentation taking advantages of both extensions.

Copy link
Member

@mgeier mgeier left a 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 Show resolved Hide resolved
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]
Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Member

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's source_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.

Copy link
Member

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?

Copy link
Contributor Author

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!

Copy link
Member

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?

Copy link
Contributor Author

@martinRenou martinRenou Aug 31, 2022

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

Copy link
Member

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.

@mgeier mgeier force-pushed the check_source_suffix branch from ecbbc4c to fc79fd1 Compare August 28, 2022 08:48
@mgeier mgeier merged commit fc79fd1 into spatialaudio:master Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants