|
| 1 | +# Guide to Contributing |
| 2 | + |
| 3 | +First, clone this repository. |
| 4 | + |
| 5 | +With HTTPS: |
| 6 | + |
| 7 | +```sh |
| 8 | +git clone https://github.com/scientific-python/executable-tutorials |
| 9 | +``` |
| 10 | + |
| 11 | +With SSH: |
| 12 | +```sh |
| 13 | +git clone [email protected]:scientific-python/executable-tutorials |
| 14 | +``` |
| 15 | + |
| 16 | +## Overview |
| 17 | + |
| 18 | +Each "recipe" is a directory under `docs/recipes/`. It may contain one or more |
| 19 | +Markdown (`.md`) files with a mixture of narrative text and code. Each recipe |
| 20 | +directory may also contain supporting data files, scripts, illustrations, |
| 21 | +solutions to exercises, etc. |
| 22 | + |
| 23 | +```none |
| 24 | +$ tree docs/ |
| 25 | +docs/ |
| 26 | +├── conf.py |
| 27 | +├── contributing.md |
| 28 | +├── index.md |
| 29 | +├── recipes |
| 30 | +│ ├── executable |
| 31 | +│ │ ├── basics.md |
| 32 | +│ ├── matplotlib |
| 33 | +│ │ ├── interactive_mpl.md |
| 34 | +│ │ └── static_mpl.md |
| 35 | +│ └── static |
| 36 | +│ └── static.md |
| 37 | +... |
| 38 | +``` |
| 39 | + |
| 40 | +Some of these Markdown files include a header that describes how to convert |
| 41 | +them into Jupyter notebooks and execute the code in them. This is described in |
| 42 | +more detail below. |
| 43 | + |
| 44 | +## Setup |
| 45 | + |
| 46 | +We use the [pixi](https://pixi.sh/latest/#installation) package manager to |
| 47 | +create an environment with dependencies from conda-forge and PyPI. We recommend |
| 48 | +installing pixi. Then just: |
| 49 | + |
| 50 | +```sh |
| 51 | +pixi install |
| 52 | +``` |
| 53 | + |
| 54 | +But if you have a strong preference for a different package manager, peek |
| 55 | +inside `pixi.toml` to find the list of dependencies and install them however |
| 56 | +you wish. |
| 57 | + |
| 58 | +## Build |
| 59 | + |
| 60 | +```sh |
| 61 | +pixi run build |
| 62 | +``` |
| 63 | + |
| 64 | +```{note} |
| 65 | +Later, if the build results get into a broken state, use `pixi run clean` |
| 66 | +to start fresh. |
| 67 | +``` |
| 68 | + |
| 69 | +This creates: |
| 70 | +- Executed notebooks, generated from eligible Markdown files, under `build/juptyer_execute/` |
| 71 | +- HTML under `build/html/` |
| 72 | + |
| 73 | +Open `build/html/index.html` in a web browser. |
| 74 | + |
| 75 | +## Develop |
| 76 | + |
| 77 | +``` |
| 78 | +pixi run jupyter lab |
| 79 | +``` |
| 80 | + |
| 81 | +In the file browser, locate one of the examples under `docs/recipes/`. Double |
| 82 | +click to open. |
| 83 | + |
| 84 | +Files like `docs/recipes/static/static.md` are plain Markdown files. Files like |
| 85 | +`docs/recipes/executable/basics.md` have a YAML header which enables the |
| 86 | +documentation build system to convert them to Jupyter notebooks and execute |
| 87 | +them: |
| 88 | + |
| 89 | +```yaml |
| 90 | +--- |
| 91 | +jupytext: |
| 92 | + text_representation: |
| 93 | + extension: .md |
| 94 | + format_name: myst |
| 95 | + format_version: 0.13 |
| 96 | + jupytext_version: 1.16.4 |
| 97 | +kernelspec: |
| 98 | + display_name: Python 3 (ipykernel) |
| 99 | + language: python |
| 100 | + name: python3 |
| 101 | +--- |
| 102 | +``` |
| 103 | + |
| 104 | +One option is to simply edit these files in any text editor. |
| 105 | + |
| 106 | +Another is to use Jupyter Lab, which can open these files _as notebooks_ |
| 107 | +enabling you the interactively edit and execute them, saving the changes to |
| 108 | +Markdown. |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +Note that the cell _outputs_ are not saved to disk. This is a feature, not a |
| 113 | +bug: the outputs are build products, and they do not belong in version control. |
| 114 | +During the build process, the Markdown document is converted to a Jupyter |
| 115 | +notebook format and executed. |
| 116 | + |
| 117 | +## Test |
| 118 | + |
| 119 | +The script `test.sh` runs files with executable code from top to bottom and |
| 120 | +prints any unexpected tracebacks. |
| 121 | + |
| 122 | +``` |
| 123 | +pixi run ./test.sh docs/recipes/executable/basics.md |
| 124 | +``` |
| 125 | + |
| 126 | +`````{note} |
| 127 | +
|
| 128 | +Sometimes examples are _expected_ to raise an exception. These can be marked up |
| 129 | +with a "tag" like so. With that tag, the build and test procedures will pass |
| 130 | +over the exception. |
| 131 | +
|
| 132 | +````markdown |
| 133 | +```{code-cell} ipython3 |
| 134 | +:tags: [raises-exception] |
| 135 | +
|
| 136 | +1 / 0 |
| 137 | +``` |
| 138 | +```` |
| 139 | +````` |
| 140 | + |
| 141 | +To test _all_ examples, run: |
| 142 | + |
| 143 | +``` |
| 144 | +pixi run ./test.sh --all |
| 145 | +``` |
| 146 | + |
| 147 | +(Above, the script automatically discovers all Markdown files which have that |
| 148 | +YAML header marking them as executable.) |
| 149 | + |
| 150 | +## Deploy |
| 151 | + |
| 152 | +Once changes are merged to the `main` branch, the GitHub Actions [Publish workflow][] will: |
| 153 | +- Publish HTML to this site. |
| 154 | +- Uploaded the executed ipynb notebooks as a GitHub Artifact (useful for debugging) |
| 155 | + as an Artifact associated with the workflow run. |
| 156 | +- Push to [the `notebooks` branch of this repository][notebooks-branch] a version |
| 157 | + where all Markdown Jupytext files have been converted to `.ipynb` format, using |
| 158 | + `pixi run ./convert-all ipynb`. This is suitable for use in environments |
| 159 | + where users need to be handed Jupyter Notebook files directly, such as Google |
| 160 | + Colab. |
| 161 | + |
| 162 | +[notebooks-branch]: https://github.com/scientific-python/executable-tutorials/tree/notebooks/docs/recipes |
| 163 | +[Publish workflow]: https://github.com/scientific-python/executable-tutorials/actions/workflows/cd.yml |
0 commit comments