-
Notifications
You must be signed in to change notification settings - Fork 386
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
How to build a documentation site with Jupytext? #247
Comments
@psychemedia , you shared some experience with Jupyter Book + Jupytext at #230 and #231 already, maybe we could write a post on that, and a short wrap up at |
In theory, Jupytext can also be used to edit Sphinx-galleries directly in Jupyter, cf. #80. And turning these galleries into a binder should just require adding |
@emmanuelle, I see that you've created https://github.com/plotly/plotly-sphinx-gallery, would you like to give a try to Jupyter + Jupytext as an editor of sphinx-gallery scripts? Also, I think that converting the Jupyter notebooks to Markdown files in https://github.com/plotly/documentation could make the repo much lighter. Would you be interested in giving a try to that? It should be as simple as:
and then, insert the opposite conversion in the process that builds the HTML files. You can use the Also, can you tell us how the Plotly web documentation is build from the notebooks? |
@choldgraf , you may be interested in this discussion. I also have a question for you... do you think we could treat the Markdown documents in a Jupyter Book repository as Jupyter notebook using Jupytext? That could require an additional operation when the book is build: convert the text notebooks (or only those that have a jupyter metadata?) to |
@mwouts -- this is how nbsphinx handles non-ipynb files: https://nbsphinx.readthedocs.io/en/0.4.1/custom-formats.html |
Note on scaled images: we hit a rough spot with the jupyter -> rst conversion that pandoc uses. Specifically, jupyter notebooks don't render the markdown image tag for scaled images:
As of last February, the only thing that works for both notebooks and sphinx rst files was IPython.display.Image details at: spatialaudio/nbsphinx#284 hopefully at some point jupyter notebook's markdown parser will support scaled images, which would solve this issue. |
I haven't had a chance to try this yet, but if Jupytext is set up to save |
@psychemedia , well I do have some experience with that! Take for example that README.md: it was 100% created in Jupyter, using Jupytext. And you can open it on binder as a notebook. I believe the same would work with However, the
|
How to replace every |
Working on a practical case (like in #263) is possibly the best way to address this issue. Would anybody want to suggest a repo in which a documentation site is made with Jupyter notebooks, that he/she'd like to transform to, say, Jupytext Markdown notebooks ? I'd like to test at least
Thanks! |
I'd be +1 on building in jupytext conversion to the Jupyter Book project somehow, just need to figure out the right pattern to do it. The problem w/ storing things as markdown files is that then you lose all the outputs, which are quite handy to have within the github repositories if you want people to be able to quickly glance at what is inside. Happy to brainstorm on this though. |
One thing I've started exploring here is authoring in md and having dualled notebooks in a hidden I'm not sure if that moves things forwards any, but it can make things a bit tidier? |
@psychemedia please write up a post or something about this! I have been thinking of doing the same :-) I like the idea of keeping both a rendered ipynb format and a markdown format and using one or the other on GitHub depending on whether I wanna diff or wanna see the results in a notebook |
Blog has died recently... too many half played with things not quite worked out for a post, and some actual work (late/missed deadline) in the way! But hopefully over w/e, or perhaps next week! |
Doesn't have to be a blog post :-) e.g. I've really enjoyed watching the "nbgitpuller + binder" discourse thread evolve over the months |
I completely agree, we should document one way to do that. But I would also like to document how to rebuild locally the full collection of
Certainly. In such a setting, it can be useful to configure |
A workflow I've started wondering is:
There is a complication perhaps if the structure of (On the other hand, if I just set |
Via the Jupyter discourse site ( https://discourse.jupyter.org/t/binder-template-repositories/1522 ) I learn of the new Github template repositories, which support the definition of repos intended to act as template for other repos. I wonder if this could be useful as a way of sharing Binderised repos that are pre-configured to support different jupytext mediated workflows? Eg I've started on a simple demo here: https://github.com/ouseful-template-repos/jupytext-md |
We've not discussed that yet: Jupytext can render Sphinx-Galleries on Binder! I think this is an interesting feature for the projects that offer examples in that form (notebook-like Python scripts). Recently I've seen Jupytext being used at PlasmaPy to render their gallery. I am glad to see that our documentation was a good entry point - see the corresponding commit. Thank you @StanczakDominik! |
🙇♂️ the pleasure is mine :) I'll have a blog post with instructions on how to do this up soon-ish (by tomorrow) - I'll link it back here. |
Oh that sounds great! We're looking forward to reading your post! Thanks |
Good timing, as here it is: https://stanczakdominik.github.io/posts/simple-binder-usage-with-sphinx-gallery-through-jupytext/ Most of this is simply using jupytext and its documentation, but there's an extension that lets you link those jupytext binder notebooks from sphinx gallery that may come in handy to anyone interested. |
This is really interesting... can jupytext sphinx also be invoked from something like Circle CI to build docs automatically? (CI is yet another of those things I keep not making time to learn about:-( |
Well done @StanczakDominik ! Sure, the most difficult thing here is probably to have all these independent project interacting well together...
Well I would say that this is already the case. Have a look at the PlasmaPy gallery: the plots are there, but I don't think that they are stored on GitHub, so they must have been produced when the documentation was built. |
Sure it can! You don't need jupytext to do that, either, unless you were storing your documentation in notebooks directly. That still has issues with keeping blobs of binary and JSON in git, which isn't at all handy. |
Another interesting example is the book Elegant Scipy, written by Juan Nunez-Iglesias (@jni), Harriet Dashnow (@hdashnow), and Stéfan van der Walt (@stefanv). The book is stored in the form of Markdown files in the I will have a look at how this would work with Jupytext. To start with, we'll have to implement the support for the |
As a follow-up on the previous comment, adding Jupytext>=1.2.0rc3 to the requirements of the Elegant Scipy book works was enough to render the book chapters as notebooks on binder. In the process for building the book, we could also substitute
with
( |
I'm just toying with the thought of using jupytext to integrate the examples (python script with the percent format) into my sphinx documentation. Maybe this "fresh" view is helpful, maybe not :) I wish there was a simple directive (maybe via a sphinx extension?) that would allow me to add documents: .. renderjupytext:: examples/my_example.py The documents would automatically run during the build process. |
Hi @sotte , well I am not really a Sphinx expert, but I think you have a least three options:
From what I have seen I think that option 1 is the most popular among Jupytext users. Still if you decide to give a try to second or third, please let us know the outcome. |
@mwouts thanks! I ended up with a Just using If somebody is interested, here is the relevant part of the Makefile SRC_DIR := ../examples
DST_DIR := _examples
SRC_FILES := $(wildcard $(SRC_DIR)/*.py)
DST_FILES := $(patsubst $(SRC_DIR)/%.py,$(DST_DIR)/%.ipynb,$(SRC_FILES))
$(DST_DIR)/%.ipynb: $(SRC_DIR)/%.py
jupytext --execute --to notebook -o $@ $<
@echo
html: $(DST_FILES)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
Note that you can turn off the default nbsphinx execution: https://nbsphinx.readthedocs.io/en/0.2.15/never-execute.html |
@phaustin thanks! You're right, I can turn it off, but I still need to transform the python script into the ipynb format. My |
@StanczakDominik, @lesteve , the subject of how to best setup Binder to work with Sphinx-Gallery has reached the Jupyter Discourse site (here). I think you will know better than me what is the issue with the default configuration of Sphinx-Gallery, so maybe you'd like to comment there? Also, @lesteve, would you like to share your experience with the Scikit-learn gallery? |
Thanks @mwouts I commented on the Jupyter Discourse thread. Also a small thing I noticed, not sure whether something can be done to configure JupyterLab to have the "Open With" -> Notebook as the default. If you point to a specific It will use the Editor which is likely not what you want: I am reasonably confident this is a JupyterLab-specific: it seems like the default content manager for you have to right-click on a file (on the right-hand-side panel) and select "Open With" and then Notebook. Double-clicking on a file will open the editor. |
Thanks @lesteve for your comment at the Jupyter Discourse, that's an interesting input. And thanks for reporting the above. That is correct, we don't know yet how to emulate the right-click on open as notebook in JupyterLab (#271). The difference between JupyterLab and Jupyter Notebook is that the former looks not only at the document type reported by the contents manager ("notebook" for these documents), but also at the file extension. It's a bit harder to contribute a fix for this, as that has to be done in a JupyterLab extension, to be developped in TypeScript, which am I less familiar with. But sure, we will have to fix that at some point! |
@sotte wrote above (#247 (comment)):
You should have told me, I wasn't aware of this problem until a few days ago! I've tried to come up with a solution in spatialaudio/nbsphinx#408, please check it out! |
I'm actually pretty happy with my |
I am going to close this old issue. In the meanwhile we have seen Jupyter Book emerging, I think that is a great candidate for building documentation sites. Regarding Jupytext we have recently solved two related issues:
|
The purpose of this issue is to document a few ways to build a documentation site. Our requirements are:
We should explore at least
The text was updated successfully, but these errors were encountered: