This looks like a really interesting project! One question I've been trying to figure out is "how is this different from nbconvert?" It seems like they have partially overlapping functionality, so I'm curious how you see these two projects differentiating one another.
Hello @choldgraf , thanks for asking!
As you state, jupytext and nbconvert can both export Jupyter notebooks to markdown and scripts. The added value of jupytext versus nbconvert is the support for the reverse conversion: with jupytext, you can convert a notebook to a script, edit the script, and then _update_ the original jupyter notebook.
There are two ways you can use jupytext:
--update flag to preserve output cells for unchanged input cells.A few more comments:
nbconvert, jupytext will preserve notebook and cell metadata in some of the text representations (R Markdown, light and percent scripts). @mwouts very cool - thanks for the explanation :-)
A couple quick questions:
.py files that are there. We're currently doing this with custom code because we want to avoid too many heavy dependencies (and nbconvert can be heavy).Thanks @choldgraf for the feedback! Let me try to answer your questions...
How lightweight is this compared with nbconvert?
I am not sure! Jupytext has very few dependencies. And its code is about 3k lines. Do you quantify that as light?
To that point, have you considered separating out the "converting text formats from one to the other" code from the "running a paired server" code?
Well, Jupytext only focuses on reading/writing notebooks. The contents manager (i.e. the plugin for Jupyter) is just one file (389 lines). There is no server within Jupytext.
I looked through the Sphinx Gallery code and the formatting isn't quite right (Sphinx Gallery python files need to begin with an rST-formatted docstring).
I see! You're right. The first markdown cell should be exported as a docstring. To achieve this, we would just need to add a cell metadata 'cell_marker' equal to """ for the first markdown cell of the notebook, in that function. But I am afraid the YAML header is not very Sphinx Gallery compliant... Do you see a way to have some content in the sphinx file that is ignored by Sphinx Gallery?
@choldgraf , on the branch 0.8.4 the first markdown cell is now exported as a docstring. Is this better? Please also let me know if you see how to mark the YAML header so that Sphinx will ignore it.
A few improvements, including the doctring for the first cell, are available in a pre-release version:
pip install jupytext==v0.8.4rc0
The YAML header will not be created if an option is set on Jupytext's content manager, cf. the documentation.
@choldgraf , I will close this issue as I think we've answered your questions here. Please let me know if you have other questions!
hey - just saw that I hadn't responded before, my bad! re: the YAML header, I don't think there's any way to get sphinx to ignore it unfortunately, so it'd have to be done with some kind of post-processing if it isn't possible to control with jupytext :-/ I'll take a stab at using this when I have a moment and maybe can make some PRs!
Sure, I will be glad to receive your pull request, they are welcome!
In the 0.8.4 release candidate Jupytext does have the option to not generate the YAML header (this is documented on the README). Still I am sure you will find room for more improvements... Let me know!
It seems like you're one step ahead of me here 馃槉
Most helpful comment
Hello @choldgraf , thanks for asking!
As you state,
jupytextandnbconvertcan both export Jupyter notebooks to markdown and scripts. The added value ofjupytextversusnbconvertis the support for the reverse conversion: withjupytext, you can convert a notebook to a script, edit the script, and then _update_ the original jupyter notebook.There are two ways you can use
jupytext:--updateflag to preserve output cells for unchanged input cells.A few more comments:
nbconvert,jupytextwill preserve notebook and cell metadata in some of the text representations (R Markdown, light and percent scripts).