|
| 1 | +Developing examples |
| 2 | +------------------- |
| 3 | + |
| 4 | +All our examples are available as: |
| 5 | + |
| 6 | +* As a rendered HTML gallery online |
| 7 | +* As downloadable Python scripts or Jupyter notebooks |
| 8 | +* As the original Python scripts in the ``./examples`` directory, which can be |
| 9 | + browsed directly on the online repository. |
| 10 | + |
| 11 | +We use `Sphinx-Gallery`_ to render the Python files as HTML. We could also use |
| 12 | +Jupyter notebooks as they are nicely rendered and executable by a user. |
| 13 | +However, Sphinx-Gallery has a number of advantages over Jupyter notebooks: |
| 14 | + |
| 15 | +* To render Jupyter notebooks online, cell output has to be stored in the |
| 16 | + notebooks. This is fine for text output, but images are stored as (inline) |
| 17 | + binary blobs. These result in large commits bloating the Git repository. |
| 18 | + Tools such as `nbstripout`_ will remove the cell outputs, but this comes at |
| 19 | + the obvious cost of not having the rendered notebooks available online. |
| 20 | +* `Not everybody likes Jupyter notebooks`_ and Jupyter notebooks require |
| 21 | + special software to run. Python scripts can be run with just a Python |
| 22 | + interpreter. Furthermore, Sphinx-Gallery also provides Jupyter notebooks: |
| 23 | + from the Python scripts it will automatically generate them. |
| 24 | +* Sphinx-Gallery uses `reStructured Text (rST)`_ rather than Markdown. rST |
| 25 | + syntax is somewhat less straightforward than `Markdown`_, but it also |
| 26 | + provides additional features such as easily linking to the API (including |
| 27 | + other projects, via `intersphinx`_). |
| 28 | + |
| 29 | +For Sphinx-Gallery, rST is `embedded`_ as module docstrings at the start of a |
| 30 | +scripts and as comments in between the executable Python code. We use ``# %%`` |
| 31 | +as the block splitter rather than 79 ``#``'s, as the former is recognized by |
| 32 | +editors such as Spyder and VSCode, while the latter is not. The former also |
| 33 | +introduces less visual noise into the examples when reading it as an unrendered |
| 34 | +Python script. |
| 35 | + |
| 36 | +Note that documentation that includes a large portion of executable code such |
| 37 | +as the User Guide has been written as Python scripts with embedded rST as well, |
| 38 | +rather than via the use of `IPython Sphinx Directives`_. |
| 39 | + |
| 40 | +.. _Sphinx-Gallery: https://sphinx-gallery.github.io/stable/index.html |
| 41 | +.. _nbstripout: https://github.com/kynan/nbstripout |
| 42 | +.. _Not everybody likes Jupyter notebooks: https://www.youtube.com/watch?v=7jiPeIFXb6U |
| 43 | +.. _reStructured Text (rST): https://en.wikipedia.org/wiki/ReStructuredText |
| 44 | +.. _Markdown: https://en.wikipedia.org/wiki/Markdown |
| 45 | +.. _intersphinx: https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html |
| 46 | +.. _embedded: https://sphinx-gallery.github.io/stable/syntax.html#embedding-rst |
| 47 | +.. _IPython Sphinx Directives: https://ipython.readthedocs.io/en/stable/sphinxext.html |
0 commit comments