python-tutorial icon indicating copy to clipboard operation
python-tutorial copied to clipboard

Notebooks-as-code with Jupytext

Open edoardob90 opened this issue 8 months ago • 1 comments

Jupytext is a package and Jupyter extension that provides a very useful way of "pairing" a notebook with a text file in many formats: a Python script, a Markdown, a RestructuredText.

Pairing a notebook from Jupyter creates the chosen text file alongside the notebook file. Any changes made to the text file are reflected in the notebook upon reloading.

I think this is an incredibly useful addition to simplify reviews on GitHub because you can change or suggest changes directly on a text file, instead of an IPython notebook (which is an unreadable JSON).

The notebook and the text file are synced only on save: if you don't reload and save the notebook from Jupyter, the changes are not synced. An even more useful addition is to integrate Jupytext syncing as a pre-commit hook:

repos:
-   repo: https://github.com/mwouts/jupytext
    rev: v1.14.7  # CURRENT_TAG/COMMIT_HASH
    hooks:
    - id: jupytext
      args: [--sync]

Todo

  • [ ] Add jupytext as a dependency
  • [ ] Enable the JupyterLab extension (Dockerfile)
  • [ ] Setup a pre-commit hook

edoardob90 avatar May 08 '25 09:05 edoardob90

An added benefit is that we can rewrite the toc.py script (#240 and #131) to edit the text files. This is way easier than parsing and editing a Jupyter notebook file directly.

edoardob90 avatar May 08 '25 09:05 edoardob90