|
| 1 | +# Generating API documentation |
| 2 | + |
| 3 | +This folder contains the required files to automatically generate the Adafruit Beaglebone I/O Python API documentation, partly from the code docstrings and partly from a reStructuredText-formatted `index.rst` file. |
| 4 | + |
| 5 | +``` |
| 6 | +├── conf.py <- Sphinx configuration file |
| 7 | +├── index.rst <- Documentation will be generated based on this |
| 8 | +└── Makefile <- Auxiliary Makefile to build documentation |
| 9 | +``` |
| 10 | + |
| 11 | +The tools used are [http://www.sphinx-doc.org](Sphinx) to extract the documentation and publish it in HTML format for online viewing, in combination with [Readthedocs](http://readthedocs.io), which automatically executes Sphinx via webhooks triggered by Github commits, and publishes the resulting docs for all tracked branches. Generally Readthedocs will be set up to track stable release branches and master. |
| 12 | + |
| 13 | +## Building the documentation |
| 14 | + |
| 15 | +The documentation can also be built on a local checkout of the project: |
| 16 | + |
| 17 | +First ensure you've got sphinx installed: |
| 18 | + |
| 19 | +``` |
| 20 | +sudo pip install sphinx |
| 21 | +``` |
| 22 | + |
| 23 | +Then you can build the HTML docs: |
| 24 | + |
| 25 | +``` |
| 26 | +cd docs |
| 27 | +make html |
| 28 | +``` |
| 29 | + |
| 30 | +Once Sphinx has built the documentation, you can open the main index file with your browser: `_build/html/index.html` |
| 31 | + |
| 32 | +Notes: |
| 33 | + |
| 34 | +- The build process will create three additional temporary directories: `_build`, `_static` and `_templates` that will not be version-controlled. You can use `make clean` to remove their contents if you wish to do so. |
| 35 | +- The html theme from files built locally is different from the online readthedocs theme. See the `docs/config.py` `html_theme` variable. The main reason is not to introduce another dependency to install the readthedocs theme, but as a side effect, it also helps visually distinguishing the locally-built documentation from the online version. |
| 36 | + |
| 37 | +## Readthedocs maintenance |
| 38 | + |
| 39 | +At every release that includes documenation (most probably 1.0.10 will be the first one), the release's branch needs to be selected in the web UI and marked as active. |
| 40 | + |
| 41 | +After this, documentation will automatically be generated and published for that release. It will be available at the same URL as the main documentation, and a link with the version number will be shown, where it can be accessed from. |
| 42 | + |
| 43 | +Optionally, the 'stable' URL slug can be pointed to that release branch. Otherwise, the 'stable' slug can also be deactivated for less maintenance overhead. |
| 44 | + |
| 45 | +The 'latest' URL slug will always be pointing at the repo's master branch. |
| 46 | + |
| 47 | +## Notes |
| 48 | + |
| 49 | +Ideally, all API documentation would be written in the source files as Python docstrings, and sphinx would simply extract it. This is actually the case with the `Encoder` module, which is pure Python. |
| 50 | + |
| 51 | +However, most of the code is written as C extensions. While they do provide docstrings once they are built, Sphinx does not natively support extracting them. There is [a workaround](https://stackoverflow.com/a/30110104/9022675) to do this, but it involves first building the extensions, installing them and hardcoding a path. While it might work for locally-built documentation, it's unlikely that readthedocs support this option. |
| 52 | + |
| 53 | +For the sake of keeping things simple and with less maintenance, the approach of documenting the C-generated API in the `index.rst` file has been taken. |
| 54 | + |
| 55 | +This has the advantage of having a definition of the API in one place, but it also poses the disadvantage of some duplication, as the C modules do define some docstrings for their objects. Then again, the API itself has hardly changed in the last few years, and the Beaglebone is a mature platform, so it's unlikely that this will pose a significant maintenance overhead. |
| 56 | + |
| 57 | +- The documentation in Python modules follows the Google readable docstring markup, which is fully supported by Sphinx. |
| 58 | +- The documentation in the `index.rst` file is written in [reStructuredText](http://docutils.sourceforge.net/rst.html), with Sphinx markup for defining the objects. |
| 59 | + |
| 60 | +## Further reference |
| 61 | + |
| 62 | +- [Google readable docstring markup](https://google.github.io/styleguide/pyguide.html?showone=Comments#Comments) |
| 63 | +- [Google docstring examples](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html) |
| 64 | +- [More Google docstring examples](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)) |
| 65 | +- [Sphinx docstring markup](http://www.sphinx-doc.org/en/stable/domains.html#the-python-domain) |
| 66 | + |
| 67 | + |
0 commit comments