-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
DOC: Add interactive notebooks to pages in the "Usage Examples" section #741
base: main
Are you sure you want to change the base?
DOC: Add interactive notebooks to pages in the "Usage Examples" section #741
Conversation
Quite strange. The documentation is building without any problems locally... Edit: I can reproduce locally if I delete a few of the previously generated files – this is coming from Edit, again: they were failing because the |
4d1dcf0
to
970439b
Compare
doc/source/regression/dwt-idwt.md
Outdated
```{eval-rst} | ||
.. currentmodule:: pywt | ||
|
||
.. dropdown:: 🧑🔬 This notebook can be executed online. Click this section to try it out! ✨ |
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.
Is this how it's done in scikit-learn as well? I don't mind if it's needed, but it seems easy to forget this kind of snippet in larger projects.
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.
It should be possible to write another minimal Sphinx extension that can automate adding these admonitions and connect to the HTML builder at an event, similar to convert_md_to_ipynb
. We don't need it here, however.
As for scikit-learn, I think they switched to the PyData Sphinx Theme as well in their recent release, and I feel like I like their solution much more than using an admonition – the JupyterLite/Binder/download buttons are very conveniently placed in the secondary sidebar. I can try to explore that and see how they did it, and whether we can do it conditionally for just these six pages through the theme's API.
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.
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.
sphinx-gallery/sphinx-gallery#1312 is a non-minimal implementation, so we can't copy it that easily unless it were a Sphinx extension of its own.
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.
That looks really nice! I suggest then that we merge this as is, and explore the option of how to have support either in pydata-sphinx-theme or in a separate Sphinx extension for having a right sidebar like done in sphinx-gallery.
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.
Thanks! I'm still figuring out a solution for preprocessing the notebooks to add the directives on-demand (it's not that easy to do without a Markdown parser that allows me to change things programmatically through a document's AST).
Another option I have explored is an extension that runs at the time of the source-read
event, and I have it working partially. If this doesn't work, I can ping you to merge this – because the content looks complete and I guess we will have better things to spend more time on.
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.
Unresolving this to keep the discussion visible - this is an important topic I think. The sphinx-gallery
example renders a lot nicer visually; the sidebar links are much cleaner and it shouldn't require as much boilerplate in the .md
files to get those links. It looks like it'd be good for pydata-sphinx-theme
or a separate extension to have something similar.
Not a show-stopper for PyWavelets, because there's only a handful of .md
files. But I doubt that what we have here will work for a much larger project.
I added a basic extension to clean up the generated IPython notebooks in 6bc9c60 using |
18b4b2c
to
21e0158
Compare
Processing Markdown programmatically doesn't bear good fruit – it would have been easier if we used IPyNB, and we don't plan to. I would suggest that we should merge this for now, @rgommers. The issue with Markdown was that there isn't a clean way to add both the Jupytext frontmatter and the notebook directives and that requires some obtrusive, prone-to-failure file manipulation by processing the contents as a string (we can keep the notebook directives at the bottom and the frontmatter intact, but it's easier to provide the download buttons at the top of the page rather than at the bottom). |
Weird, the local docs build and RTD both produce cleaner downloadable notebooks, but the NotebookLite directive on RTD doesn't have the cleaner notebooks (they still have the Sphinx directives). This does not happen locally. I think RTD has some caching troubles, because I removed the redundant module headings from the notebooks (such as Edit: some notebooks are as expected, and some don't. Edit 2: this is most likely the case of a cached build or some updates that don't trickle down the RTD, the logs say that all the notebooks are converted. I can't reproduce locally, and I feel that the issue will go away automatically on a fresh build. |
I had a revelation just now and I think 07a0926 should fix the synchronisation issue for good – the RTD build is just buggy for some reason or the other and the local documentation builds where the issue doesn't arise can be trusted upon. Ready for review and further proceedings. |
Tagging @melissawm and @steppi for a review as discussed during the 14/06/2024 interactive docs meeting – thanks, both! |
This seems to work really well- I love the buttons and dropdowns. How flexible can we make this to share with other projects? Ideally, we could have an extension (or as a part of jupyterlite-sphinx) that adds the preprocess notebooks event, common settings and looks without having to turn them on manually for each project? |
I had a discussion with @agriyakhetarpal offline where we discussed how this preprocessing could be added to jupyterlite-sphinx. I think he's working on it. |
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.
Thanks @agriyakhetarpal. Don't forget to set jupyterlite_silence = True
again now that we're done debugging. After that I think this is good to merge.
cc @rgommers
Looks like that last action was done, and everything is green. Are you happy with this PR as is @agriyakhetarpal? |
In the last few comments, I bumped to the latest https://github.com/jupyterlite/pyodide-kernel/releases/tag/v0.5.1, which brings https://github.com/pyodide/pyodide/releases/tag/0.27.1. |
Now that all tests are passing, this PR should be ready – thanks to @gabalafou's help with the styling 🙈 cc: @melissawm and @Carreau; tagging you here as I can't request a review from GitHub directly. |
Description
Tip
Those interested can try it at https://pywavelets--741.org.readthedocs.build/en/741/regression/index.html
The Usage Examples section, following #728 and as requested in #737 (comment), is rendered interactive through the changes in this PR through the use of
jupyterlite-sphinx
and Markdown-based notebooks that are executed by MyST-NB. Please read below for a granular overview of all of these details:Which issue does this PR solve/reference?
Addresses a part of #706
Key changes made
.rst
based files underdoc/source/regression
converted to Markdown and reformatted as notebooksconf.py
jupyterlite-sphinx
to run the notebooks under WASM in the same tab (and something like Add the option to open JupyterLite window in new tab jupyterlite/jupyterlite-sphinx#165 can be added for this directive as well).ipynb
-based notebooks that get generated during the process in order to keep the documentation build warning-free. Generating them at build time is for theNotebookLite
directive to be able to access them and load them, since the NotebookLite directive currently does not load.md
files or notebook files in other formats.i. I imagine this will be helpful for DOC: stats: Convert sampling tutorial to MyST-md scipy/scipy#20303 as well where it is required to load the notebooks in an interactive manner under a specific folder. The notebooks are not executed by Jupytext at the time of conversion, and therefore, based on past experiments, it takes ~10 seconds to convert 30 or so notebooks.
Additional context
This is just a pilot run of how notebook-based examples can be configured for Sphinx-based documentation websites, so there are a few corner cases that I have noticed so far:
conf.py
just like how theTryExamples
directive can be configured.A brief to-do list
Besides the points mentioned above, smaller tasks can be looked into:
.md
and.ipynb
)