-
Notifications
You must be signed in to change notification settings - Fork 21
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
Strip tagged cells from .ipynb
notebooks passed to the NotebookLite
and JupyterLite
directives
#180
Strip tagged cells from .ipynb
notebooks passed to the NotebookLite
and JupyterLite
directives
#180
Conversation
538735f
to
ff738bc
Compare
In commit 23d2cae, I added an example by setting This can be noticed on the pages in the documentation preview: https://jupyterlite-sphinx--180.org.readthedocs.build/en/180/directives/jupyterlite.html and https://jupyterlite-sphinx--180.org.readthedocs.build/en/180/directives/notebooklite.html. I shall revert the commit once this PR has been reviewed. |
@steppi, I figured out the problem with the repeated copying for the notebook files, and the good thing is that the repeated copying exists only when the notebook is embedded multiple times in the same document (I'm appalled it took me slightly longer than expected to figure it out, haha). This behaviour is apparently different from that of the @melissawm, I tested this with the seventeen or so notebooks from scipy/scipy#21042 like you suggested (I converted them via Jupytext to IPyNB first, using its CLI) and added them under separate JupyterLite directives. The time taken by P.S. Jupytext provides an API as well. Perhaps another worthwhile feature to add to It is to be noted that the JupyterLite interface does have support for Jupytext in the screenshot below, but I am not sure how to make the Markdown notebook runnable – (I think) it is not supported right now: jupyterlite/jupyterlite#731, so this conversion from |
Should this option be a booolean or a list of tag to strip?
? |
I have put some thought about the use cases of having JSON metadata for notebooks, e.g., to include interactive widgets like Thebe, or cells where it is helpful to show inputs but hide outputs, etc., so, yes – having a list of tags could be a reasonable option. I imagine this option will be better coupled with |
I don't have much preference. I tend to think that if it's two options it might be more difficult to configure, and if the list is empty it can play the role of not stripping ? I think I would be +0.1 for just having a single config option. But maybe others want to pitch in. |
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.
This looks good @agriyakhetarpal. I'm in favor of keeping only a boolean config option and not making this more complex than needed. I also have a suggestion about the name of the tag.
Reverted the changes I made to the notebook in b853462 since the functionality is working as expected. |
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.
This looks good to me now. Thanks @agriyakhetarpal!
Description
This PR updates the
_LiteDirective
class to be able to usenbformat
, which is already specified as a dependency inpyproject.toml
, to be able to read IPyNB files and remove cells which include "strip" set to "true" in their JSON metadata. This way, it is possible to provide cleaner notebooks for cases similar to scipy/scipy#20303 or with PyWavelets/pywt#741, where notebooks passed to the.. notebooklite::
or the.. jupyterlite::
directives can now be preprocessed to remove certain cells before they are copied to the built documentation.For example, a notebook cell with the Markdown syntax
can receive metadata like this
and this cell will be removed by
nbformat
ifstrip_tagged_cells
is set toTrue
inconf.py
, therefore disabling the admonition in the deployed documentation.Changes made
strip_tagged_cells
which is set toFalse
by default. If set toTrue
inconf.py
, this enables preprocessing behaviourjupyterlite_sphinx/jupyterlite_sphinx.py
, wherenbformat
is used to read the notebook file and operate on the cells of the notebook.docs/configuration.md
.Additional context
TryExamples
directive is not compatible with this feature. This is because we need an IPyNB-based notebook file to add metadata for a cell, whileTryExamples
dynamically generates notebooks at runtime from doctests.