2020-08-16 03:28:02 +02:00
=============
2020-07-21 00:18:26 +02:00
Documentation
=============
2020-08-16 03:28:02 +02:00
The Apache NuttX Documentation is built using the
`Sphinx documentation system <https://www.sphinx-doc.org/en/master/> `_ . Documentation
is written in `ReStructured Text <https://docutils.sourceforge.io/rst.html> `_ (RST),
with Sphinx-specific directives. RST is the format used for
`Python documentation <https://docs.python.org/3/> `_ and is also used in many other projects.
Using Sphinx, the RST files are rendered into HTML files that can be read in your browser.
Building
========
2020-10-18 18:48:44 +02:00
To render the Documentation locally, you should clone the NuttX main repository, and
2020-08-16 03:28:02 +02:00
go into `` Documentation `` directory. Then,
2020-09-02 20:47:36 +02:00
1. Install Sphinx and other dependencies using pipenv.
You may also find it helpful on platforms such as Windows and MacOS to use *pyenv*
to manage your python installation. You can read about installing that on the
project `site <https://github.com/pyenv/pyenv#installation> `_ .
2020-10-18 18:48:44 +02:00
2020-09-02 20:47:36 +02:00
.. code-block :: console
2020-10-18 18:48:44 +02:00
2020-09-02 20:47:36 +02:00
$ pip3 install pipenv
$ pipenv install
2021-04-28 21:14:44 +02:00
$ # activate the virtual environment
2020-09-02 20:47:36 +02:00
$ pipenv shell
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
2. Build documentation:
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
.. code-block :: console
2020-10-18 18:48:44 +02:00
2024-08-30 16:40:15 +02:00
$ cd Documentation/
2020-08-16 03:28:02 +02:00
$ make html
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
The resulting HTMLs will end up under `` _build/html `` . You can open your browser at the root with:
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
.. code-block :: console
2020-10-18 18:48:44 +02:00
$ xdg-open _build/html/index.html
2020-08-16 03:28:02 +02:00
2021-03-26 18:48:22 +01:00
Live Rebuild
------------
For more comfortable editing and previewing of changes (as `` make html `` will perform a slower full rebuild),
you can install `` sphinx-autobuild `` which will monitor file changes and rebuild only affected files. To
install it (within the virtual environment):
.. code-block :: console
$ pip3 install sphinx-autobuild
To run:
.. code-block :: console
$ make autobuild
Which will perform an initial clean build and monitor changes from then on.
2020-08-16 03:28:02 +02:00
Contributing
============
Contributions to documentation are appreciated. These can be as simple as fixing a typo or formatting issues to more involved
changes such as documenting parts of NuttX which are not yet covered or even writing guides for other users.
The contribution workflow is the same as for the code, so check the :doc: `/contributing/workflow` to understand
how your changes should be upstreamed.
Writing ReStructure Text with Sphinx
====================================
The following links can be used to learn about RST syntax and about Sphinx specific directives. Note that
sometimes Sphinx's approach is used over standard RST since it is more powerful (e.g. standard linking vs Sphinx
`` :ref: `` which can be used across files, `` code-block `` directive vs `` :: `` which allows specifying highlight language, etc.):
* `Sphinx documentation system <https://www.sphinx-doc.org/en/master/> `__
* `ReStructured Text documentation <https://docutils.sourceforge.io/rst.html> `__
* `Sphinx Guide to ReStructured Text <http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html> `__
* `Restructured Text cheat sheet <https://thomas-cokelaer.info/tutorials/sphinx/rest_syntax.html> `__
Documentation Conventions
=========================
2021-04-28 21:14:44 +02:00
While RST/Sphinx provide many ways to do things, it is best to follow a given convention to maintain consistency and avoid
2020-08-16 03:28:02 +02:00
pitfalls. For this reason, documentation changes should follow the following set of conventions.
Indentation
-----------
Child blocks should be indented two-spaces. This includes itemizations/enumerations.
Headings
--------
Three levels of headings should be used in general. The style used to mark sections is based around `` = `` and `` - `` .
Sections should look like this:
.. code-block :: RST
=================
Top Level Heading
=================
Subsection
==========
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
Subsubsection
-------------
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
Code
----
2020-10-18 18:48:44 +02:00
Code should be documented using the `C domain <https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#the-c-domain> `_ .
2020-08-16 03:28:02 +02:00
This means for example that a function should be documented as:
.. code-block :: RST
.. c:function :: bool myfunction(int arg1, int arg2)
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
Here the function should be described
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
:param arg1: Description of arg1
:param arg2: Description of arg2
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
:return: Description of return value
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
To document a piece of code, use a `` code-block `` `directive <https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-code-block> `_ , specifying the highlight language. If the block is not of code but some verbatim piece of text,
it is acceptable to use RST standard `::` . This is specially useful and compact when used in the following mode:
.. code-block :: RST
The text file should have the following content::
2020-10-18 18:48:44 +02:00
Line1
2020-08-16 03:28:02 +02:00
Line2
Line3
Linking
-------
To generate internal links, Sphinx's `roles <https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#ref-role> `_ should
be used. So, use `` :ref: `` instead of standard RST syntax like `` ` link <target> ` _ `` for internal links.
If the target is in a different file, you can refer it with: `` :ref: ` link text </pathtorst:Section Name> ` `` .
2020-07-21 00:18:26 +02:00
2021-03-26 18:48:22 +01:00
Linking to a specific document can be done with `` :doc: ` /path/to/document ` `` (without `` .rst `` extension).
2020-08-16 03:28:02 +02:00
Notes and TODOS
---------------
2020-07-21 00:18:26 +02:00
2020-08-16 03:28:02 +02:00
Use RST `admonitions <https://docutils.sourceforge.io/docs/ref/rst/directives.html#admonitions> `_ to highlight things from the text,
such as a note that should be prominently displayed.
2020-07-21 00:18:26 +02:00
2020-08-16 03:28:02 +02:00
In case you need to leave a TODO note in the documentation to point that something needs to be improved, use a `` todo `` admonition,
which is available via the `` sphinx.ext.todo `` extension. This will let the reader of the documentation also know that the documentation
is not yet finished somewhere and may further motivate a contribution.
2020-07-21 00:18:26 +02:00
2020-09-11 23:55:50 +02:00
User Indications
----------------
To indicate a keypress, menu action or GUI button selection, use the following:
.. code-block :: RST
Go into menu :menuselection: `File --> Save As` , click :guilabel: `&OK` or press :kbd: `Enter` .
which would render as:
Go into menu :menuselection: `File --> Save As` , click :guilabel: `&OK` or press :kbd: `Enter` .
Tabbed examples
---------------
To indicate different instructions/examples for different scenarios (for example, different Operating
Systems) use the `tabs <https://github.com/executablebooks/sphinx-tabs> `_ extension (see link for examples).
2020-08-16 03:28:02 +02:00
Tips
====
2020-07-21 00:18:26 +02:00
2020-08-16 03:28:02 +02:00
Spacing
-------
2020-07-21 00:18:26 +02:00
2021-04-28 21:14:44 +02:00
If you are getting formatting errors, be sure to provide the appropriate spacing between a directive and its content.
2020-08-16 03:28:02 +02:00
Generally, you should follow this format:
2020-07-21 00:18:26 +02:00
2020-08-16 03:28:02 +02:00
.. code-block :: RST
2020-07-21 00:18:26 +02:00
2020-08-16 03:28:02 +02:00
.. directive ::
2020-10-18 18:48:44 +02:00
2020-08-16 03:28:02 +02:00
child content
2020-10-18 18:48:44 +02:00
non-child content which appears after previous directive
Note the line between directive and content and the indentation.
2020-07-21 00:18:26 +02:00