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

Error when used with Jupyter Book: source_suffix '.ipynb' is already registered #27

Closed
psychemedia opened this issue Mar 9, 2022 · 5 comments · Fixed by #28
Closed
Labels
bug Something isn't working

Comments

@psychemedia
Copy link

Running this extension with Jupyter Book (a custom sphinx build), which already has ipynb registered as a file type, generates an error when building a book:

Extension error:
source_suffix '.ipynb' is already registered

Also described here: jupyter-book/jupyter-book#1344 (comment)

Offending line is presumably:

app.add_source_suffix(".ipynb", "jupyterlite_notebook")

@psychemedia psychemedia added the bug Something isn't working label Mar 9, 2022
@psychemedia psychemedia changed the title Error: source_suffix '.ipynb' is already registered Error when used with Jupyter Book: source_suffix '.ipynb' is already registered Mar 9, 2022
@martinRenou
Copy link
Member

martinRenou commented Mar 9, 2022

Thanks for reporting. I wonder what should be done for fixing this.

We could either use the override option (see https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_source_suffix) to force using jupyterlite-sphinx suffix handlers, or we could back off if it's already registered.

I guess the second option is best. The end user can override that in their configuration anyway (see https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-source_suffix).

So maybe something like

try:
    app.add_source_suffix(".ipynb", "jupyterlite_notebook")
except ExtensionError:
    # Show a warning explaining how to force "jupyterlite_notebook"?
    pass

@psychemedia
Copy link
Author

Yeah, I was wondering if there was a way of looking up already registered source suffixes, other than raising an exception if you try to re-add one, but I can't spot anything from a quick look at the docs.

The override option is new to me (I wonder if there are any side effects from re-registering a suffix?).

@martinRenou
Copy link
Member

martinRenou commented Mar 9, 2022

, I was wondering if there was a way of looking up already registered source suffixes

Looking at the Sphinx code, we could probably do:

if '.ipynb' not in self.app.registry.source_suffix:
    app.add_source_suffix(".ipynb", "jupyterlite_notebook")
else:
    # Show a warning explaining how to force "jupyterlite_notebook"?
    pass

The override option is new to me (I wonder if there are any side effects from re-registering a suffix?).

I guess the side-effect there would be that if you're already using jupyter-sphinx or nbpshinx then those extensions would not work as expected anymore.

@martinRenou
Copy link
Member

@martinRenou
Copy link
Member

Actually what nbsphinx does does not work and collide with jupyterlite-sphinx, so I guess my proposition above is safer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants