1
0

documentation.rst 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. .. _salt-docs:
  2. ==========================
  3. Writing Salt Documentation
  4. ==========================
  5. Salt's documentation is built using the `Sphinx`_ documentation system. It can
  6. be built in a large variety of output formats including HTML, PDF, ePub, and
  7. manpage.
  8. All the documentation is contained in the main Salt repository. Speaking
  9. broadly, most of the narrative documentation is contained within the
  10. :blob:`doc` subdirectory and most of the reference and API documentation is
  11. written inline with Salt's Python code and extracted using a Sphinx extension.
  12. .. _`Sphinx`: https://www.sphinx-doc.org/en/master/
  13. .. _docs-style:
  14. Style
  15. =====
  16. The Salt project recommends the `IEEE style guide`_ as a general reference for
  17. writing guidelines. Those guidelines are not strictly enforced but rather serve
  18. as an excellent resource for technical writing questions. The `NCBI style
  19. guide`_ is another very approachable resource.
  20. .. _`IEEE style guide`: https://mentor.ieee.org/myproject/Public/mytools/draft/styleman.pdf
  21. .. _`NCBI style guide`: https://www.ncbi.nlm.nih.gov/books/NBK993/
  22. Point-of-view
  23. -------------
  24. Use third-person perspective and avoid "I", "we", "you" forms of address.
  25. Identify the addressee specifically e.g., "users should", "the compiler does",
  26. etc.
  27. Active voice
  28. ------------
  29. Use active voice and present-tense. Avoid filler words.
  30. Title capitalization
  31. --------------------
  32. Document titles and section titles within a page should follow normal sentence
  33. capitalization rules. Words that are capitalized as part of a regular sentence
  34. should be capitalized in a title and otherwise left as lowercase. Punctuation
  35. can be omitted unless it aids the intent of the title (e.g., exclamation points
  36. or question marks).
  37. For example:
  38. .. code-block:: restructuredtext
  39. This is a main heading
  40. ======================
  41. Paragraph.
  42. This is an exciting sub-heading!
  43. --------------------------------
  44. Paragraph.
  45. .. _docs-modules:
  46. Serial Commas
  47. -------------
  48. According to Wikipedia: In English punctuation, a serial comma or series comma
  49. (also called Oxford comma and Harvard comma) is a comma placed immediately
  50. before the coordinating conjunction (usually "and", "or", or "nor") in a series of
  51. three or more terms. For example, a list of three countries might be punctuated
  52. either as "France, Italy, and Spain" (with the serial comma), or as "France,
  53. Italy and Spain" (without the serial comma)."
  54. When writing a list that includes three or more items, the serial comma should
  55. always be used.
  56. Documenting modules
  57. ===================
  58. Documentation for Salt's various module types is inline in the code. During the
  59. documentation build process it is extracted and formatted into the final HTML,
  60. PDF, etc format.
  61. Inline documentation
  62. --------------------
  63. Python has special multi-line strings called docstrings as the first element in
  64. a function or class. These strings allow documentation to live alongside the
  65. code and can contain special formatting. For example:
  66. .. code-block:: python
  67. def my_function(value):
  68. """
  69. Upper-case the given value
  70. Usage:
  71. .. code-block:: python
  72. val = 'a string'
  73. new_val = myfunction(val)
  74. print(new_val) # 'A STRING'
  75. :param value: a string
  76. :return: a copy of ``value`` that has been upper-cased
  77. """
  78. return value.upper()
  79. Specify a release for additions or changes
  80. ------------------------------------------
  81. New functions or changes to existing functions should include a marker that
  82. denotes what Salt release will be affected. For example:
  83. .. code-block:: python
  84. def my_function(value):
  85. """
  86. Upper-case the given value
  87. .. versionadded:: 2014.7.0
  88. <...snip...>
  89. """
  90. return value.upper()
  91. For changes to a function:
  92. .. code-block:: python
  93. def my_function(value, strip=False):
  94. """
  95. Upper-case the given value
  96. .. versionchanged:: 2016.3.0
  97. Added a flag to also strip whitespace from the string.
  98. <...snip...>
  99. """
  100. if strip:
  101. return value.upper().strip()
  102. return value.upper()
  103. Adding module documentation to the index
  104. ----------------------------------------
  105. Each module type has an index listing all modules of that type. For example:
  106. :ref:`all-salt.modules`, :ref:`all-salt.states`, :ref:`all-salt.renderers`.
  107. New modules must be added to the index manually.
  108. 1. Edit the file for the module type:
  109. :blob:`execution modules <doc/ref/modules/all/index.rst>`,
  110. :blob:`state modules<doc/ref/states/all/index.rst>`,
  111. :blob:`renderer modules <doc/ref/renderers/all/index.rst>`, etc.
  112. 2. Add the new module to the alphebetized list.
  113. 3. :ref:`Build the documentation <docs-building>` which will generate an ``.rst``
  114. file for the new module in the same directory as the ``index.rst``.
  115. 4. Commit the changes to ``index.rst`` and the new ``.rst`` file and send a
  116. pull request.
  117. .. _docs-ref:
  118. Cross-references
  119. ================
  120. The Sphinx documentation system contains a wide variety of cross-referencing
  121. capabilities.
  122. .. _docs-ref-glossary:
  123. Glossary entries
  124. ----------------
  125. Link to :ref:`glossary entries <glossary>` using the `term role`_. A
  126. cross-reference should be added the first time a Salt-specific term is used in
  127. a document.
  128. .. _`term role`: https://www.sphinx-doc.org/en/master/glossary.html#term-role
  129. .. code-block:: restructuredtext
  130. A common way to encapsulate master-side functionality is by writing a
  131. custom :term:`Runner Function`. Custom Runner Functions are easy to write.
  132. .. _docs-ref-index:
  133. Index entries
  134. -------------
  135. Sphinx automatically generates many kinds of index entries, but it is
  136. occasionally useful to manually add items to the index.
  137. One method is to use the `index directive`_ above the document or section that
  138. should appear in the index.
  139. .. _`index directive`: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html?highlight=index%20directive#index-generating-markup
  140. .. code-block:: restructuredtext
  141. .. index:: ! Event, event bus, event system
  142. see: Reactor; Event
  143. Another method is to use the `index role`_ inline with the text that should
  144. appear in the index. The index entry is created and the target text is left
  145. otherwise intact.
  146. .. _`index role`: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#role-index
  147. .. code-block:: restructuredtext
  148. Information about the :index:`Salt Reactor`
  149. -------------------------------------------
  150. Paragraph.
  151. .. _docs-ref-docs:
  152. Documents and sections
  153. ----------------------
  154. Each document should contain a unique top-level label of the form:
  155. .. code-block:: restructuredtext
  156. .. _my-page:
  157. My page
  158. =======
  159. Paragraph.
  160. Unique labels can be linked using the `ref role`_. This allows cross-references
  161. to survive document renames or movement.
  162. .. code-block:: restructuredtext
  163. For more information see :ref:`my-page`.
  164. Note, the ``:doc:`` role should *not* be used to link documents together.
  165. .. _`ref role`: https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-ref
  166. .. _docs-ref-modules:
  167. Modules
  168. -------
  169. Cross-references to Salt modules can be added using Sphinx's Python domain
  170. roles. For example, to create a link to the :py:func:`test.ping
  171. <salt.modules.test.ping>` function:
  172. .. code-block:: restructuredtext
  173. A useful execution module to test active communication with a minion is the
  174. :py:func:`test.ping <salt.modules.test.ping>` function.
  175. Salt modules can be referenced as well:
  176. .. code-block:: restructuredtext
  177. The :py:mod:`test module <salt.modules.test>` contains many useful
  178. functions for inspecting an active Salt connection.
  179. The same syntax works for all modules types:
  180. .. code-block:: restructuredtext
  181. One of the workhorse state module functions in Salt is the
  182. :py:func:`file.managed <salt.states.file.managed>` function.
  183. .. _docs-ref-settings:
  184. Settings
  185. --------
  186. Individual settings in the Salt Master or Salt Minion configuration files are
  187. cross-referenced using two custom roles, ``conf_master``, and ``conf_minion``.
  188. .. code-block:: restructuredtext
  189. The :conf_minion:`minion ID <id>` setting is a unique identifier for a
  190. single minion.
  191. .. _docs-ref-fixes:
  192. Documentation Changes and Fixes
  193. ===============================
  194. Documentation changes and fixes should be made against the earliest supported
  195. release branch that the update applies to. The practice of updating a release
  196. branch instead of making all documentation changes against Salt's main, default
  197. branch, ``master``, is necessary in order for the docs to be as up-to-date as
  198. possible when the docs are built.
  199. The workflow mentioned above is also in line with the recommendations outlined
  200. in Salt's :ref:`contributing` page. You can read more about how to choose where
  201. to submit documentation fixes by reading the :ref:`which-salt-branch` section.
  202. For an explanation of how to submit changes against various branches, see the
  203. :ref:`github-pull-request` section. Specifically, see the section describing
  204. how to ``Create a new branch`` and the steps that follow.
  205. .. _docs-building:
  206. Building the documentation
  207. ==========================
  208. 1. Install Sphinx using a system package manager or pip. The package name is
  209. often of the form ``python-sphinx``. There are no other dependencies.
  210. 2. Build the documentation using the provided Makefile or ``.bat`` file on
  211. Windows.
  212. .. code-block:: bash
  213. cd /path/to/salt/doc
  214. make html
  215. 3. The generated documentation will be written to the ``doc/_build/<format>``
  216. directory.
  217. 4. A useful method of viewing the HTML documentation locally is to start
  218. Python's built-in HTTP server:
  219. Python 3:
  220. .. code-block:: bash
  221. cd /path/to/salt/doc/_build/html
  222. python3 -m http.server
  223. Python 2:
  224. .. code-block:: bash
  225. cd /path/to/salt/doc/_build/html
  226. python -m SimpleHTTPServer
  227. Then pull up the documentation in a web browser at http://localhost:8000/.