-
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
Support the usage of Markdown-based notebooks with "Lite" directives #221
Support the usage of Markdown-based notebooks with "Lite" directives #221
Conversation
I am facing some unrelated troubles when testing it locally with the SciPy documentation from SciPy's |
Update: I've tested it multiple times by now and this is working perfectly well with the SciPy docs 🎉 though the use of a UUID to append to the filename would break the caching (obviously) of the notebook builds and also adds additional notebooks to the built docs. So, I've chosen to adapt the caching-related check from scipy/scipy#21433 in e3b6882, and I can confirm that there are no regressions as those that were noticed in scipy/scipy#21394. This does mean that I've had to revert the commit via d1c7f7d where I added a sample When this PR becomes part of a release, we can remove the .. jupyterlite:: ../../_contents/hypothesis_chi2_contingency.ipynb
:new_tab: True we can just write: .. jupyterlite:: hypothesis_chi2_contingency.md
:new_tab: True which would be much cleaner – and I can submit a follow-up PR to SciPy for this, or step back if you wish to do so, @melissawm. :) This PR should now be ready for review now! |
Note; we can also allow both The docs build is failing because of this, but I would like to receive further direction before I proceed with this approach. |
Go ahead - that would be great! |
Thanks – will do when this is reviewed and released! |
Thanks @agriyakhetarpal, nice to see support for markdown-based notebooks being added here! Looks like the docs failure may be relevant though: https://readthedocs.org/projects/jupyterlite-sphinx/builds/26477597/
|
Yes, this is related to #221 (comment) and #221 (comment). Let me push a few more changes to handle that; however, I'll fix it for now by reverting the previous commit! |
ccd22f6
to
0401426
Compare
Hi @gabalafou, I've ensured that these Markdown/MyST notebooks can also be stripped via 6a6d7a2, and added docs on how to use the stripping functionality with Markdown notebooks in 5867428 – on the lines of what we discussed yesterday. I have tested the changes that I have also upstreamed to a SciPy PR here: scipy/scipy#22042. From a self-review, this looks alright to me to go ahead with. |
The case where
We would have a conflict again because all of the notebooks are going to be copied under the However, it is safe to say that this case existed prior to this PR as well (my example concerns two |
5867428
to
6d2336b
Compare
This was discussed with @steppi today, and we agreed upon making a naming conflict a hard error, regardless of file extension. He suggested that I check if any projects have notebooks with duplicate names, so that we could correct them downstream as a safety measure before we release. I didn't find any for NumPy, SciPy, or scikit-learn; and neither has anyone reported an issue about this before – ever since |
I've gone one step ahead in the check and also allowed having notebooks of the same filename stem—such as Also, we perform this lookup with a set, so that operation happens in linear time anyway – I did think about caching it using a frozenset with paths serialised to strings and a simple LRU approach, but I didn't feel it was worth keeping because we are never going to expect notebooks in the order of thousands. This is ready for review, now! |
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 is looking good Agriya. A couple small suggestions. Only real blocker I think is that the error message for when duplicate notebooks are found could use a little work. Let's discuss it offline when you have time.
Co-Authored-By: Albert Steppi <[email protected]>
Albert and I discussed the error message offline and in consideration, reduced its size because of its verbosity; plus, it would be weird to see it as such from a user's perspective. It made more sense to make it more impersonal, highlighting the problem of conflicting notebook names at hand. Implemented in 81c0c09. |
Co-authored-by: Albert Steppi <[email protected]>
Co-Authored-By: Albert Steppi <[email protected]>
Co-Authored-By: Albert Steppi <[email protected]>
With 29bb810, we don't keep going until we find all conflicts at once, and stop at the first one itself. |
Closing and reopening to investigate XPython kernel not being found in the readthedocs preview in #228 (comment) |
🤔 I cannot reproduce it here either |
|
||
# We only consider conflicts if notebooks are actually referenced in | ||
# a directive, to prevent false posiitves from being raised. | ||
if hasattr(self.env, "jupyterlite_notebooks"): |
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 think it should be fine for now, but the
Thanks @agriyakhetarpal. The issue with the docs was transient. I'm still not sure what the problem was |
Description
Please refer to the proposal in #191 for additional context and the rationale behind this change. This PR adds preprocessing functionalities to the base "Lite" directive (in the
_LiteIframe
class), which will allow a user to pass in a plain Markdown/MyST-Markdown notebook file to a directive, which will then get converted on the fly when JupyterLite is triggered. The conversion is performed viajupytext
, which has been included as a dependency.There is also the option of leaving this as an experimental feature behind an experimental flag and/or an optional dependency on
jupytext
, as suggested in #191 (comment). However, I haven't implemented that change and would like to wait for further direction on this before I do so.Changes made
run()
method of the_LiteIframe
class to convert.md
files to.ipynb
files and pass them on to JupyterLite_LiteIframe.run()
ValueError
for any conflicts, recommending that the user rename their notebooks to have unique names.jupytext
added as a dependency for facilitating the conversionAdditional context
This is supposed to make interacting with Markdown-based notebook workflows easier – a few notable examples are scipy/scipy#20303 and PyWavelets/pywt#741, which have their own ways of dealing with this intermediate step that might make sense to include in
jupyterlite-sphinx
itself through this PR, such as https://github.com/scipy/scipy/blob/82ee02556872b9f91576b835a8f40f1d9eb1fd8d/doc/convert_notebooks.py and https://github.com/agriyakhetarpal/pywt/blob/fd3e01c3003a18cca770fc6f33752f8c07084e21/doc/source/conf.py#L33-L49 respectively.cc: @melissawm @steppi @gabalafou