-
Notifications
You must be signed in to change notification settings - Fork 0
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
WIP: add support for ipywidgets #2
Conversation
changed "no kernel is connect" to "no kernel is connected"
README typo
TODO
|
jupyter_sphinx/execute.py
Outdated
nb, resources = super(ExecutePreprocessor, ep).preprocess(nb, resources) | ||
info_msg = ep._wait_for_reply(ep.kc.kernel_info()) | ||
nb.metadata['language_info'] = info_msg['content']['language_info'] | ||
return extract_widget_state(ep) |
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.
extract_widget_state
will only work properly if:
- The kernel is IPython (or anything running Python more generally, e.g. xonsh).
- ipywidgets are importable
Therefore calling extract_widget_state
should only be done when it's safe.
In absence of multi-language implementation of the Kernel side of jupyter widgets, I believe a relatively safe heuristic for doing this is to check that the outputs contain at least one widget view.
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.
What about just wrapping the code to execute in a try/catch block>
jupyter_sphinx/execute.py
Outdated
nb, resources = super(ExecutePreprocessor, ep).preprocess(nb, resources) | ||
info_msg = ep._wait_for_reply(ep.kc.kernel_info()) | ||
nb.metadata['language_info'] = info_msg['content']['language_info'] | ||
return extract_widget_state(ep) |
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.
We need to be more careful here. Widgets are only a thing for Python kernels
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 suppose the widget protocol could be used from kernels of other languages, but I've never seen this.
We can support only extracting widget state from IPython kernels for the moment, and implement others later if there is demand.
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.
minimally we would need to only extract if the kernel is a python one.
jupyter_sphinx/execute.py
Outdated
nb, resources = super(ExecutePreprocessor, ep).preprocess(nb, resources) | ||
info_msg = ep._wait_for_reply(ep.kc.kernel_info()) | ||
nb.metadata['language_info'] = info_msg['content']['language_info'] | ||
return extract_widget_state(ep) |
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.
What about just wrapping the code to execute in a try/catch block>
jupyter_sphinx/execute.py
Outdated
nb, resources = super(ExecutePreprocessor, ep).preprocess(nb, resources) | ||
info_msg = ep._wait_for_reply(ep.kc.kernel_info()) | ||
nb.metadata['language_info'] = info_msg['content']['language_info'] | ||
return extract_widget_state(ep) |
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.
Soon this will be moot: jupyter/nbconvert#900
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.
And this is targeted for nbconvert 5.5
The url of the external json is not correctly parsed I think: <script type="application/vnd.jupyter.widget-state+json" src="/home/docs/checkouts/readthedocs.org/user_builds/adaptive/checkouts/latest/docs/source/_build/jupyter_execute/tutorial/tutorial.Learner1D_widget-state.json"></script> from https://adaptive.readthedocs.io/en/latest/tutorial/tutorial.Learner1D.html |
@akhmerov unfortunately we can't put the widget state in a separate file because of this: https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/html-manager/src/libembed.ts#L36 because they just take the "innerHTML" from the script tag we can't specify it as a separate file |
5d005d8
to
fb90706
Compare
fb90706
to
5af07f0
Compare
5af07f0
to
9e9cf80
Compare
add an extension for executing code in a jupyter kernel
I merged the main PR to jupyter-sphinx. Would you like to reopen this to master? |
Co-authored-by: Bas Nijholt <[email protected]>
Closing to reopen against the upstream repo |
No description provided.