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

[HTMLExporter] Initialize resources before widget filtering #2118

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

yuvipanda
Copy link
Contributor

WidgetsDataTypeFilter is responsible for outputting appropriate widgets code where needed. If resources is passed to it, it looks inside for path and name parameters to figure out where to find metadata. The default name is "Notebook", set in Exporter._init_resources. However, in HTMLExporter, resources is passed to WidgetsDataTypeFilter here, before Exporter.init_resources is called (indirectly here).

This works ok as long as the default behavior for setting name is not needed - so all commandline conversions work. But when used programmatically (like here, for notebooksharing.space), this causes widgets to not be rendered, as the text/plain mime type is chosen each time.

This PR explicicly calls _init_resources before instantiating WidgetsDataTypeFilter, so the defaulting behavior of _init_resources is exercised.

yuvipanda and others added 2 commits February 29, 2024 22:09
`WidgetsDataTypeFilter` is responsible for outputting appropriate
widgets code where needed. If `resources` is passed to it, it looks inside
for `path` and `name` parameters to figure out where to find metadata. The
default `name` is `"Notebook"`, set in [`Exporter._init_resources`](https://github.com/jupyter/nbconvert/blob/fec19fa4d538495c3c02b85708878287463412ae/nbconvert/exporters/exporter.py#L314).
However, in `HTMLExporter`, `resources` is passed to `WidgetsDataTypeFilter`
[here](https://github.com/jupyter/nbconvert/blob/fec19fa4d538495c3c02b85708878287463412ae/nbconvert/exporters/html.py#L260),
*before* `Exporter.init_resources` is called (indirectly [here](https://github.com/jupyter/nbconvert/blob/fec19fa4d538495c3c02b85708878287463412ae/nbconvert/exporters/html.py#L266)).

This works ok as long as the default behavior for setting `name` is not
needed - so all commandline conversions work. But when used programmatically
(like [here](https://github.com/yuvipanda/notebooksharing.space/blob/f37fda886b8e565a82b1bf3f4851ad89e2b00e47/nbss/app.py#L250),
for notebooksharing.space), this causes widgets to not be rendered, as the `text/plain` mime type is
chosen each time.

This PR explicicly calls `_init_resources` before instantiating
`WidgetsDataTypeFilter`, so the defaulting behavior of `_init_resources`
is exercised.
yuvipanda added a commit to yuvipanda/notebooksharing.space that referenced this pull request Mar 1, 2024
Temporary workaround until jupyter/nbconvert#2118
gets merged.

This was a fun one to track down.
@blink1073 blink1073 added the bug label Mar 1, 2024
Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'll cut a release with this on Monday.

@blink1073 blink1073 merged commit 8dac97a into jupyter:main Mar 1, 2024
23 of 24 checks passed
@yuvipanda
Copy link
Contributor Author

Thanks for the quick review and merge, @blink1073

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants