|
| 1 | +# Quickstart: Contributing to a lesson |
| 2 | + |
| 3 | +If you are at this page, you might want to quickly contribute to some |
| 4 | +existing material using the `sphinx-lesson` format. Luckily, this |
| 5 | +is fairly easy: |
| 6 | + |
| 7 | +- Get the source |
| 8 | +- Edit the material in the `content/` directory |
| 9 | +- (optional) Set up the Python environment and preview |
| 10 | +- Send your contribution |
| 11 | + |
| 12 | +In summary, each lesson is a Python project, with content in the |
| 13 | +`content/` directory. It uses the Sphinx documentation system, |
| 14 | +which is a popular, extendable tool. We have only minor extensions to |
| 15 | +make it suitable to lessons. |
| 16 | + |
| 17 | +Instead of going through this process, you can also open an issue |
| 18 | +instead with your proposed change, and let someone else add it. |
| 19 | + |
| 20 | +```{highlight} console |
| 21 | +``` |
| 22 | + |
| 23 | +## Get the lesson material |
| 24 | + |
| 25 | +You need to consult with the lesson you would like to edit. If this |
| 26 | +is using the `git` version control system on Github, you could clone |
| 27 | +it like this: |
| 28 | + |
| 29 | +``` |
| 30 | +$ git clone git://github.com/ORGANIZATION/LESSON.git |
| 31 | +``` |
| 32 | + |
| 33 | +[CodeRefinery's git-intro lesson](https://coderefinery.github.io/git-intro/) explains more. |
| 34 | + |
| 35 | +## Edit the material |
| 36 | + |
| 37 | +The material is in the `content/` directory. Depending on the |
| 38 | +lesson, in may be in ReStructured Text, MyST Markdown, or Jupyter |
| 39 | +notebooks. |
| 40 | + |
| 41 | +### ReStructured Text and MyST Markdown |
| 42 | + |
| 43 | +You will probably copy existing examples, but you can also see |
| 44 | +{doc}`our quick guide <md-and-rst>`. The main thing to note is that |
| 45 | +this is not unstructured Markdown, but there are particular |
| 46 | +(non-display) **directives** and **roles** to tag blocks and inline |
| 47 | +text. (In fact, "markdown" is a broad concept and everyone uses some |
| 48 | +different extensions of it). |
| 49 | + |
| 50 | +- {doc}`md-and-rst` |
| 51 | +- {ref}`ReStructured Text reference <sphinx:rst-primer>` |
| 52 | +- [MyST reference](https://myst-parser.readthedocs.io/en/latest/using/syntax.html) |
| 53 | +- {doc}`sphinx-lesson directives for markup <directives>` |
| 54 | + |
| 55 | +*Do not worry about getting syntax right*. Send your improvement, and |
| 56 | +editing is easy and you will learn something. |
| 57 | + |
| 58 | +### Jupyter notebooks |
| 59 | + |
| 60 | +Jupyter notebooks are a common format for computational narratives, |
| 61 | +and can be natively used with Sphinx via [myst-nb](https://myst-nb.readthedocs.io/). Note that you should use MyST |
| 62 | +Markdown directives and roles (see previous section) in the notebook |
| 63 | +to give structure to the material. |
| 64 | + |
| 65 | +Again, *do not worry about getting the syntax right*. This is the |
| 66 | +least important part of things. |
| 67 | + |
| 68 | +## Build and test locally |
| 69 | + |
| 70 | +Generic: The `requirements.txt` file includes all Python dependencies |
| 71 | +to build the lesson. The lesson can be built with `sphinx-build -M |
| 72 | +html content/ _build`, or `make html` if you have Make installed. |
| 73 | + |
| 74 | +Or in more detail: |
| 75 | + |
| 76 | +Create a virtual environment to install the requirements (a conda |
| 77 | +environment would work just as well): |
| 78 | + |
| 79 | +``` |
| 80 | +$ python3 -m venv venv/ |
| 81 | +$ source venv/bin/activate |
| 82 | +``` |
| 83 | + |
| 84 | +:::{note} |
| 85 | +if `python3 -m venv venv/` does not work, try with `python -m venv venv/` |
| 86 | +::: |
| 87 | + |
| 88 | +Then upgrade pip inside the virtual environment and install dependencies (it is recommended that conda base environment is deactivated): |
| 89 | + |
| 90 | +``` |
| 91 | +$ pip install --upgrade pip |
| 92 | +$ pip install -r requirements.txt |
| 93 | +``` |
| 94 | + |
| 95 | +You can build it using either of these commands: |
| 96 | + |
| 97 | +``` |
| 98 | +$ sphinx-build -M html content/ _build |
| 99 | +$ make html # if you have make installed |
| 100 | +``` |
| 101 | + |
| 102 | +And then view it with your web browser. Remove the `_build` |
| 103 | +directory to force a clean rebuild (or `make clean`). |
| 104 | + |
| 105 | +Or you can use the **Sphinx autobuilder**, which will start a process |
| 106 | +that rebuilds it on every change, and starts a web server to view it. |
| 107 | +It will tell you how to access the server: |
| 108 | + |
| 109 | +``` |
| 110 | +$ sphinx-autobuild content/ _build/ |
| 111 | +... |
| 112 | +[I ...] Serving on http://127.0.0.1:8000 |
| 113 | +``` |
| 114 | + |
| 115 | +## Sending your changes back |
| 116 | + |
| 117 | +This depends on the project, but can be done using Github pull |
| 118 | +requests. [CodeRefinery's git-collaborative lesson](https://coderefinery.github.io/git-collaborative/) goes into |
| 119 | +details about pull requests. |
| 120 | + |
| 121 | +## Other things to keep in mind |
| 122 | + |
| 123 | +- Make sure that you have rights to submit your change. In general, |
| 124 | + if you reuse anything else that already exists, explain this in your |
| 125 | + pull request. |
| 126 | +- *Content and ideas are more important than markup*. Don't worry |
| 127 | + about doing something wrong, that is why we have review! |
| 128 | +- Many different people use the lessons. Ask before doing things that |
| 129 | + make the lesson too specific to your use case. |
0 commit comments