Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Binder jupytext #12116

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

Closed
wants to merge 3 commits into from
Closed

Binder jupytext #12116

wants to merge 3 commits into from

Conversation

mwouts
Copy link

@mwouts mwouts commented Sep 14, 2018

The binder project and Jupytext can turn the matplotlib example library into a collection of interactive notebooks.

Try it now at https://mybinder.org/v2/gh/mwouts/matplotlib/master?filepath=examples

Further work is apparently required on the examples themselves - not all plots are shown correctly in Jupyter (Is that a Jupyter configuration issue? Your probably know better than me).

image

@ImportanceOfBeingErnest
Copy link
Member

There is rather long discussion about making examples available for interactive use in
Adding Binder links to the Matplotlib gallery #11415 and
DOC: Add links to pyodide to examples #11670.

In contrast, the approach here would be to let binder generate notebooks from the example .py files, is that correct?

Here is the link to an introduction of jupytext. And this is the jupytext github repo. Still, a little bit of explanation about how that plays together with binder would probably be welcome.

Attn. @choldgraf who initiated some of the earlier attempts for binder links via sphinx-gallery.

@ImportanceOfBeingErnest
Copy link
Member

not all plots are shown correctly in Jupyter

Comparing the notebooks generated via sphinx-gallery, which are downloadable below each example, and the ones generated via Jupytext is that Jupytext apperently triggers a new cell at each comment or double line break in the code, such that figures are not shown upon plt.show() in a later cell, while the sphinx-gallery-generated notebooks preserve the code in one cell.

image

@mwouts
Copy link
Author

mwouts commented Sep 14, 2018

Thanks! That's very helpful. I will also read the related discussions, they seem pretty interesting!

Jupytext is a plugin for Jupyter notebook that allows Jupyter to read/write notebooks directly from/to plain Python scripts. No ipynb file is generated in that process. Binder provides the Jupyter notebook, and the two seem to work well together.

Jupytext currently splits python files, when it reads them as a notebook, on blank lines (well, blank lines not inside functions, classes, etc). Clearly the current implementation does not seem to work well with the example above. Can you think of another approach (two blank lines??) that would work better (is there something like an implicit cell separator in the matplotlib examples)?

@jklymak
Copy link
Member

jklymak commented Sep 14, 2018

I think the same separators as rst are 95% of the time the appropriate ones (i..e a long line of #######). The comments directly below the separator are rendered as rst, and the code below as one cell.

@anntzer
Copy link
Contributor

anntzer commented Sep 14, 2018

The approach I took for sphinx-exhibit (#11936) is to use toplevel strings as text cells (with the option to use sphinx-gallery's choice). I actually think this works well with the single-cell case (just a docstring):

"""
this is a docstring
"""
some code
"""
more text
"""
more code

(ok it looks horrible without syntax highlighting and with a stupid example but I think you get the idea)

Here if you just want to separate two code blocks you could just put in a toplevel empty string ("" or """""") which is less a pain to type than 79x#...


Also, I guess(?) this will again choke on more complex rst constructs (cf the image tutorial example in the sphinx-exhibit thread) because I think they are basically unparseable without running them through sphinx. Now you may say oh well let's just switch everything to markdown but it's never going to be as expressive...

@mwouts
Copy link
Author

mwouts commented Sep 14, 2018

Thanks for the feedback! I'm new to RST, Sphynx, etc, but happy to learn. Let me come back in a few weeks with a proposal for another format in Jupytext that will better treat Sphynx oriented scripts (mwouts/jupytext#80)...

@tacaswell tacaswell added this to the v3.1 milestone Sep 15, 2018
@choldgraf
Copy link
Contributor

@mwouts check out sphinx-gallery for one way to do the python -> notebook conversion. I'd be (in theory) +1 on factoring out sphinx-gallery's conversion code into a standalone .py -> .ipynb module and then just depending on that within sphinx-gallery. It's always seemed like a useful enough thing to do on its own that it shouldn't be embedded in a gallery creation package.

@mwouts
Copy link
Author

mwouts commented Sep 18, 2018

@choldgraf , thanks for the reference. I have started exploring the sphinx-gallery module, and I am doubting how to exactly implement the sphinx-gallery format for Jupytext (mwouts/jupytext#80).

Do you want to advice on whether I should include the RST to markdown conversion? I am asking as Jupytext offers, for the other formats, a solid round trip conversion (that allows to safely edit scripts from within Jupyter). Converting RST to markdown would break that - is it worth the nicer rendering?

@mwouts
Copy link
Author

mwouts commented Sep 22, 2018

Hello everyone. I have just published a new RC for Jupytext, which now has support for Sphinx-gallery scripts. Would you like to have a look at the matplotlib binder ? Documentation for that rc is here. Thanks!

@choldgraf
Copy link
Contributor

very cool! thanks!

@jklymak
Copy link
Member

jklymak commented Feb 10, 2019

Closing for now. The binder links here give a TOC< but the actual examples don't seem to render, so I'll assume this is not working yet? But happy to re-open...

@jklymak jklymak closed this Feb 10, 2019
@jklymak
Copy link
Member

jklymak commented Feb 10, 2019

Ooops, my apologies - binder must have been having a hiccup. It seems to work now.

@jklymak jklymak reopened this Feb 10, 2019
@jklymak jklymak modified the milestones: v3.1.0, v3.2.0 Feb 11, 2019
@tacaswell tacaswell modified the milestones: v3.2.0, v3.3.0 Aug 25, 2019
@QuLogic QuLogic modified the milestones: v3.3.0, v3.4.0 May 2, 2020
@jklymak
Copy link
Member

jklymak commented Sep 10, 2020

I'll close this as not getting enough traction, but anyone should feel free to re-open (or request)

@jklymak jklymak closed this Sep 10, 2020
@QuLogic QuLogic removed this from the v3.4.0 milestone Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants