Zack Williams | 3645191 | 2022-03-04 20:31:37 -0700 | [diff] [blame] | 1 | Sphinx |
| 2 | ====== |
| 3 | |
| 4 | Docs are generated using :doc:`Sphinx <sphinx:usage/index>` using the |
| 5 | :doc:`reStructuredText <sphinx:usage/restructuredtext/basics>` syntax. |
| 6 | |
| 7 | Sphinx was chosen because it's widely used (Python official docs, Linux Kernel, |
| 8 | Read the Docs, etc.), open source, actively maintained, has code highlighting, |
| 9 | and a good client-side search implementation. |
| 10 | |
| 11 | Writing Documentation |
| 12 | --------------------- |
| 13 | |
| 14 | reStructuredText syntax references can be found here: |
| 15 | |
| 16 | * :doc:`Sphinx reStructuredText Primer <sphinx:usage/restructuredtext/basics>` |
| 17 | * `rst cheat sheet <https://github.com/ralsina/rst-cheatsheet/blob/master/rst-cheatsheet.rst>`_ |
| 18 | |
| 19 | rST creates headings by underlining the heading with a series of symbol |
| 20 | characters. There is no specific required order for these, but for consistency |
| 21 | most ONF docs use the following symbols/order to represent heading levels:: |
| 22 | |
| 23 | H1: = |
| 24 | H2: - |
| 25 | H3: " |
| 26 | H4: ' |
| 27 | H5: ^ |
| 28 | H6: + |
| 29 | |
| 30 | Linking within Documentation |
| 31 | """""""""""""""""""""""""""" |
| 32 | |
| 33 | |
| 34 | Referencing other Documentation |
| 35 | """"""""""""""""""""""""""""""" |
| 36 | |
| 37 | Other Sphinx-built documentation, both ONF and non-ONF can be linked to using |
| 38 | :doc:`InterSphinx <sphinx:usage/extensions/intersphinx>`, which allows you to |
| 39 | create links that will work even if the other site moves or reorganizes |
| 40 | content. |
| 41 | |
| 42 | New InterSphinx reference requires modifying the ``intersphinx_mapping`` |
| 43 | variables of the ``conf.py`` file. |
| 44 | |
| 45 | You can see all link targets available on a remote Sphinx's docs by running:: |
| 46 | |
| 47 | python -msphinx.ext.intersphinx http://otherdocs/objects.inv |
| 48 | |
| 49 | More information about InterSphinx: |
| 50 | |
| 51 | * :doc:`Read the Docs InterSphinx Guide <rtd:guides/intersphinx>` |
| 52 | |
| 53 | Adding Images and Diagrams |
| 54 | """""""""""""""""""""""""" |
| 55 | |
| 56 | There are multiple ways to add images and diagrams to the documentation. |
| 57 | |
| 58 | Generally, you should prefer using `SVG |
| 59 | <https://en.wikipedia.org/wiki/Scalable_Vector_Graphics>`_ images, as these can |
| 60 | be scaled to any size without quality loss. |
| 61 | |
| 62 | If you're creating diagrams, there are multiple tools available. |
| 63 | :doc:`Graphviz <sphinx:usage/extensions/graphviz>` can render inline text-based |
| 64 | graphs definitions and diagrams within the documentation, and is best choice for |
| 65 | simple diagrams. |
| 66 | |
| 67 | More complex diagrams can be created in `Diagrams.net/Draw.io |
| 68 | <https://www.diagrams.net/>`_ format, which is available as a standalone app, |
| 69 | web app, or integrated with various other tools like Google Workspace. When |
| 70 | saving these diagrams, use the SVG format, and check the **Include a copy of my |
| 71 | diagram** box. This will let someone open the SVG later within Diagrams.net |
| 72 | from file saved in the documentation and edit it without any loss in |
| 73 | functionality or quality. |
| 74 | |
| 75 | The last resort is to use raster (bitmap) images. If they're drawings or screen |
| 76 | captures, use the `PNG |
| 77 | <https://en.wikipedia.org/wiki/Portable_Network_Graphics>`_ format. Consider |
| 78 | optimizing the PNG files with a tool like `OptiPNG |
| 79 | <http://optipng.sourceforge.net/>`_, or `pngquant <https://pngquant.org/>`_ to |
| 80 | save space and data transfer required. |
| 81 | |
| 82 | If you need to include a photograph, use `JPEG |
| 83 | <https://en.wikipedia.org/wiki/JPEG>`_. |
| 84 | |
| 85 | Building the Documentation |
| 86 | -------------------------- |
| 87 | |
| 88 | The documentation build process is stored in a ``Makefile``. Building docs |
| 89 | requires Python to be installed, and most steps will create a virtualenv |
| 90 | (usually ``venv-docs``) which contains the required tools. You may also need |
| 91 | to install the ``enchant`` C library using your system's package manager for |
| 92 | the spelling checker to function properly. |
| 93 | |
| 94 | Run ``make html`` to generate html documentation in ``_build/html``. |
| 95 | |
| 96 | There is also a test target, ``make test``, which will run all the following |
| 97 | checks - this is what Jenkins does on patchset validation, so: |
| 98 | |
| 99 | * ``make lint``: Check the formatting of documentation using `doc8 |
| 100 | <https://github.com/PyCQA/doc8>`_. |
| 101 | |
| 102 | * ``make license``: Verifies licensing is correct using :ref:`REUSE |
| 103 | <policies/licensing:REUSE License Tool>` |
| 104 | |
| 105 | * ``make spelling``: Checks spelling on all documentation. If there are |
| 106 | additional words that are correctly spelled but not in the dictionary |
| 107 | (acronyms, nouns, etc.) please add them to the ``dict.txt`` file, which |
| 108 | should be alphabetized using ``sort`` |
| 109 | |
| 110 | * ``make linkcheck``: Verifies that links in the document are working and |
| 111 | accessible, using Sphinx's built in linkcheck tool. If there are links that |
| 112 | don't work with this, please see the ``linkcheck_ignore`` section of |
| 113 | ``conf.py``. |
| 114 | |
| 115 | Some sites may have the ability to build a PDF file of the documentation using |
| 116 | ``make latexpdf``. This requires that you have a recent LaTeX installation and |
| 117 | ``latexmk`` installed. |
| 118 | |
| 119 | Versioning Documentation |
| 120 | """""""""""""""""""""""" |
| 121 | |
| 122 | To change the version shown on the built site, change the contents of the |
| 123 | ``VERSION`` file to be released SemVer version. This will create a tag on the |
| 124 | repo. |
| 125 | |
| 126 | Then when ``make multiversion`` target can be used which will build all |
| 127 | versions tagged or branched on the remote to ``_build/multiversion``. This will |
| 128 | use a fork of `sphinx-multiversion |
| 129 | <https://github.com/Holzhaus/sphinx-multiversion>`_ to build multiple versions |
| 130 | and a menu on the site. |
| 131 | |
| 132 | There are variables in ``conf.py`` to determine which tags/branches to build. |