News for hackers. Stuff that matters.
Re:The new Jupyter Book by heisenzombie on Wednesday August 12, 2020 @07:13PM (#24138180)
I love the Jupyter ecosystem but it's frustratingly messy sometimes. There's already "nbconvert" built in to Jupyter (lab), built on Pandoc. It's extremely under-documented but it's possible to extend it with templates to generate arbitrary outputs. I've done this to directly generate branded PDF reports via latex. Jupyter Book has a lot of overlap with this feature, but rather than building on nbconvert/pandoc, it starts from scratch with Sphinx.

Oh well! Keeps things interesting, I suppose!

Re:The new Jupyter Book by jjoonathan on Wednesday August 12, 2020 @11:48PM (#24139773)
The JupyterLab extension system is the biggest offender imo.

"Oh, I need to install the python package and the jupyter extension separately? And there are no breadcrumbs if I install one but not the other? And I have to figure out which versions are mutually compatible with each other and jupyterlab because 'everything latest' sure isn't? And I have to install extensions to get features that used to be built-in? And then I have to explain the install procedure to the person I'm trying to share with, twice, because he didn't believe me the first time? UGGGGGGGHHHHHHHH"

Re:The new Jupyter Book by ycan on Thursday August 13, 2020 @08:47AM (#24142764)
Imagine you manage all this but they change something fundamental and you have to (get everyone else to) reinstall all of it.
Re:The new Jupyter Book by dividedbyzero on Thursday August 13, 2020 @05:27PM (#24149519)
We maintain a custom internal Docker image that everyone uses for their JupyterLab needs to make this manageable; that way, we only have to get everything to work once, and everyone else can just docker pull :latest and be good. It's become a rather large image, since it needs to have everything anyone uses, but for a small-ish team, this has worked well for about two years or so now.

Another upside: There is a GCP gcloud one-liner to start a VM for a given Docker image, and the image is designed to work both locally and in a GCP VM, with notebooks in a git repository that gets checked out automatically on container creation, so switching from laptop to 16-core VM to churn through a large dataset from a bucket is pretty seamless.

Re:The new Jupyter Book by chrisjsewell on Wednesday August 12, 2020 @07:45PM (#24138445)
nbconvert/pandoc is very limited in how it can be extended because it only relies on jinja templating rather than a proper AST. You couldn't achieve a lot of the things that sphinx/jupyter book can now do with that. Trust me I know because, before starting work on https://github.com/executablebooks/MyST-Parser I used the nbconvert/pandoc approach to create https://github.com/chrisjsewell/ipypublish ;-)
Re:The new Jupyter Book by heisenzombie on Wednesday August 12, 2020 @10:57PM (#24139532)
This is interesting, so do you think the JupyterBook solution could/should replace nbconvert?

I was always a bit frustrated by the way nbconvert pulled in pandoc as a dependency, but then didn't make use of any of its power (pandoc surely has a powerful AST). Instead they re-implemented filters and templates themselves. It struck me that it would have been much cleaner to write a proper 'ipynb > AST' Pandoc reader, and then expose pandoc AST filters and templates.

I was a bit suspicious of moving away from pandoc to sphinx, because sphinx seems markedly less powerful and general than pandoc. However, you seem to think it's the opposite! Does Sphinx have an AST? I can't see any reference?

Re:The new Jupyter Book by chrisjsewell on Wednesday August 12, 2020 @11:14PM (#24139613)
pandocs AST is actually a little limited, in terms of extensability, because it has to resove to JSON. The scorreia.com/software/panflute/code.html is a good python API for it.

By contrast sphinx uses docutils AST: https://github.com/live-clones/docutils/blob/master/docutils..., the documentation is not great (working on that) but it is pretty powerful.

Re:The new Jupyter Book by fiddlosopher on Thursday August 13, 2020 @12:04AM (#24139844)
In fact, pandoc now does have an ipynb reader and writer. You can convert between ipynb and any of the formats pandoc supports, and you can manipulate the AST using filters.
Re:The new Jupyter Book by chrisjsewell on Thursday August 13, 2020 @01:00AM (#24140087)
Now use that to replicate the example pages here: https://myst-nb.readthedocs.io/en/latest/examples/basic.html... and here https://jupyterbook.org/interactive/launchbuttons.html, and let me know how you get on ;-)
Re:The new Jupyter Book by tikej on Thursday August 13, 2020 @06:30AM (#24141824)
Oh, this is huge for me!

My main concern with jupyter is that I prefer orgmode (and by a lot), but I know that it's niche and most people don't even heard about it ipnbs are preferred form of notebook exchange.

I will check how good translation to/from orgmode is then.

Re:The new Jupyter Book by heisenzombie on Thursday August 13, 2020 @04:17AM (#24141090)
Oh! Thanks! I'll definitely take a look at that!
Re:The new Jupyter Book by zdw on Wednesday August 12, 2020 @10:04PM (#24139249)
This looks great, as extended commonmark support knocks down the last major pain point to switching to Sphinx for docs in the projects I've worked on.

The only remaining tooling gap is a markdown linter implemented in python.

Re:The new Jupyter Book by dmix on Wednesday August 12, 2020 @10:57PM (#24139533)
Why a python linter? Text editors are usually language agnostic and separate from other tooling.
Re:The new Jupyter Book by zdw on Thursday August 13, 2020 @09:55AM (#24143349)
If the rest of the documentation workflow is in python, it would remove the need to install another entirely separate scripting language runtime to do those checks on every developer laptop, CI system, etc.
Re:The new Jupyter Book by abhishekjha on Wednesday August 12, 2020 @08:35PM (#24138781)
>I've done this to directly generate branded PDF reports via latex.

Can you elaborate on this a little? Do you mean via Jupyter notebooks?

Re:The new Jupyter Book by setgree on Thursday August 13, 2020 @06:53AM (#24141949)
Here's an example where nbconverts a notebook and a template into a formatted tex file, and then a journal-ready PDF:

https://codeocean.com/capsule/9155944/tree/v1

The nbconvert syntax is

  jupyter nbconvert --exec --to latex --template ieee.tplx --output ../results/editorial.tex editorial.ipynb
and then `pdflatex` converts the tex file to a PDF
Re:The new Jupyter Book by heisenzombie on Wednesday August 12, 2020 @10:34PM (#24139398)
Yes, via Jupyter notebooks -- using the same machinery that gives the 'File > Export Notebook As...' functionality.

My method is roughly this:

1. Create a Python package that subclasses nbconvert.exporters.LatexExporter -- in the setup.py you register the class to 'nbconvert.exporters' in the 'entry_points' dict.

2. You can do general filtering/compiling by registering 'Exporter.filters'. The compile process can be modified by implementing a custom 'from_notebook_node()'

3. You can include a folder containing jinja template(s) in the package to implement whatever styling you want

4. I have some standard metadata that I pull from the notebook/cell metadata (using the standard Jupyter/lab frontend metadata sidebar) to define things like document titles, authors, etc.

5. Do the conversion like: jupyter nbconvert --to=myfancyexportformat notebook.ipynb

Re:The new Jupyter Book by carreau on Thursday August 13, 2020 @01:01AM (#24140092)
Wow someone use the features I wrote years ago ! <3 You might want to submit a blog post to Jupyter.org to show that this is possible and make it more known.
Re:The new Jupyter Book by heisenzombie on Thursday August 13, 2020 @04:20AM (#24141106)
That work you did those years ago made me a hero at work :) Thanks!
Re:The new Jupyter Book by carreau on Friday August 14, 2020 @12:10PM (#24159764)
Never had the opportunity to really document it, so thinks for finding it; I would have hoped for a much wider variety of exporter to be published. I'm still happy about the "pip install package" --to=qualname. I thin you can hardly make it simpler.