blob: 05bcba97d047959db1556ffe5e2d4e63d44a2f7e [file] [log] [blame]
Zack Williams36451912022-03-04 20:31:37 -07001Sphinx
2======
3
4Docs are generated using :doc:`Sphinx <sphinx:usage/index>` using the
5:doc:`reStructuredText <sphinx:usage/restructuredtext/basics>` syntax.
6
7Sphinx was chosen because it's widely used (Python official docs, Linux Kernel,
8Read the Docs, etc.), open source, actively maintained, has code highlighting,
9and a good client-side search implementation.
10
11Writing Documentation
12---------------------
13
14reStructuredText 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
19rST creates headings by underlining the heading with a series of symbol
20characters. There is no specific required order for these, but for consistency
21most 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
30Linking within Documentation
31""""""""""""""""""""""""""""
32
33
34Referencing other Documentation
35"""""""""""""""""""""""""""""""
36
37Other Sphinx-built documentation, both ONF and non-ONF can be linked to using
38:doc:`InterSphinx <sphinx:usage/extensions/intersphinx>`, which allows you to
39create links that will work even if the other site moves or reorganizes
40content.
41
42New InterSphinx reference requires modifying the ``intersphinx_mapping``
43variables of the ``conf.py`` file.
44
45You 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
49More information about InterSphinx:
50
51* :doc:`Read the Docs InterSphinx Guide <rtd:guides/intersphinx>`
52
53Adding Images and Diagrams
54""""""""""""""""""""""""""
55
56There are multiple ways to add images and diagrams to the documentation.
57
58Generally, you should prefer using `SVG
59<https://en.wikipedia.org/wiki/Scalable_Vector_Graphics>`_ images, as these can
60be scaled to any size without quality loss.
61
62If you're creating diagrams, there are multiple tools available.
63:doc:`Graphviz <sphinx:usage/extensions/graphviz>` can render inline text-based
64graphs definitions and diagrams within the documentation, and is best choice for
65simple diagrams.
66
67More complex diagrams can be created in `Diagrams.net/Draw.io
68<https://www.diagrams.net/>`_ format, which is available as a standalone app,
69web app, or integrated with various other tools like Google Workspace. When
70saving these diagrams, use the SVG format, and check the **Include a copy of my
71diagram** box. This will let someone open the SVG later within Diagrams.net
72from file saved in the documentation and edit it without any loss in
73functionality or quality.
74
75The last resort is to use raster (bitmap) images. If they're drawings or screen
76captures, use the `PNG
77<https://en.wikipedia.org/wiki/Portable_Network_Graphics>`_ format. Consider
78optimizing the PNG files with a tool like `OptiPNG
79<http://optipng.sourceforge.net/>`_, or `pngquant <https://pngquant.org/>`_ to
80save space and data transfer required.
81
82If you need to include a photograph, use `JPEG
83<https://en.wikipedia.org/wiki/JPEG>`_.
84
85Building the Documentation
86--------------------------
87
88The documentation build process is stored in a ``Makefile``. Building docs
89requires Python to be installed, and most steps will create a virtualenv
90(usually ``venv-docs``) which contains the required tools. You may also need
91to install the ``enchant`` C library using your system's package manager for
92the spelling checker to function properly.
93
94Run ``make html`` to generate html documentation in ``_build/html``.
95
96There is also a test target, ``make test``, which will run all the following
97checks - 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
115Some 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
119Versioning Documentation
120""""""""""""""""""""""""
121
122To 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
124repo.
125
126Then when ``make multiversion`` target can be used which will build all
127versions tagged or branched on the remote to ``_build/multiversion``. This will
128use a fork of `sphinx-multiversion
129<https://github.com/Holzhaus/sphinx-multiversion>`_ to build multiple versions
130and a menu on the site.
131
132There are variables in ``conf.py`` to determine which tags/branches to build.