diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 96b92e77bfa..3154eedb723 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -178,10 +178,8 @@ right before you open a pull request. And with that step, it's time to start hacking on Salt! -.. _imagemagick-setup: - -Set up ``imagemagick`` ----------------------- +Set up imagemagick +------------------ One last prerequisite is to have ``imagemagick`` installed, as it is required by Sphinx for generating the HTML documentation. @@ -267,7 +265,7 @@ Before approving code contributions, Salt requires: Documentation fixes just require correct documentation. What if I don't write tests or docs? -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +------------------------------------ If you aren't into writing documentation or tests, we still welcome your contributions! But your PR will be labeled ``Needs Testcase`` and @@ -282,14 +280,65 @@ and Thursday morning, Central Time. If you'd like specific help with tests, bring them to the clinic. If no community members need help, you can also just watch tests written in real time. -.. _docs-building: Documentation ------------- Salt uses both docstrings, as well as normal reStructuredText files in the ``salt/doc`` folder for documentation. Sphinx is used to generate the -documentation, and does require :ref:`setting up imagemagick on your OS.` +documentation, and does require ``imagemagick``. See `Set up imagemagick`_ for +more information. + +Before submitting a documentation PR, it helps to first build the Salt docs +locally on your machine and preview them. Local previews helps you: + +- Debug potential documentation output errors before submitting a PR. +- Saves you time by not needing to use the Salt CI/CD test suite to debug, which takes + more than 30 minutes to run on a PR. +- Ensures the final output looks the way you intended it to look. + +To set up your local environment to preview the core Salt and module +documentation: + +#. Install the documentation dependencies. For example, on Ubuntu: + + :: + + sudo apt-get update + + sudo apt-get install -y enchant-2 git gcc imagemagick make zlib1g-dev libc-dev libffi-dev g++ libxml2 libxml2-dev libxslt-dev libcurl4-openssl-dev libssl-dev libgnutls28-dev xz-utils inkscape + +#. Navigate to the folder where you store your Salt repository and remove any + `.nox` directories that might be in that folder: + + :: + + rm -rf .nox + +#. Install `pyenv` for the version of Python needed to run the docs. As of the + time of writing, the Salt docs theme is not compatible with Python 3.10, so + you'll need to run 3.9 or earlier. For example: + + :: + + pyenv install 3.7.15 + pyenv virtualenv 3.7.15 salt-docs + echo 'salt-docs' > .python-version + +#. Activate `pyenv` if it's not auto-activated: + + :: + + pyenv exec pip install -U pip setuptools wheel + +#. Install `nox` into your pyenv environment, which is the utility that will + build the Salt documentation: + + :: + + pyenv exec pip install nox + + Since we use ``nox``, you can build your docs and view them in your browser with this one-liner: @@ -297,9 +346,9 @@ with this one-liner: python -m nox -e 'docs-html(compress=False, clean=False)'; cd doc/_build/html; python -m webbrowser http://localhost:8000/contents.html; python -m http.server -The first time this will take a while because there are a *lot* of -modules. Maybe you should go grab some dessert if you already finished -that sandwich. But once Sphinx is done building the docs, python should +The first time you build the docs, it will take a while because there are a +*lot* of modules. Maybe you should go grab some dessert if you already finished +that sandwich. But once nox and Sphinx are done building the docs, python should launch your default browser with the URL http://localhost:8000/contents.html. Now you can navigate to your docs and ensure your changes exist. If you make changes, you can simply run @@ -312,9 +361,18 @@ this: And then refresh your browser to get your updated docs. This one should be quite a bit faster since Sphinx won't need to rebuild everything. +Alternatively, you could build the docs on your local machine and then preview +the build output. To build the docs locally: + +:: + + pyenv exec nox -e 'docs-html(compress=False, clean=True)' + +The output from this command will put the preview files in: ``doc > _build > html``. + If your change is a docs-only change, you can go ahead and commit/push your code and open a PR. You can indicate that it's a docs-only change by -adding ``[Documentation]`` to the title of your PR. Otherwise you'll +adding ``[Documentation]`` to the title of your PR. Otherwise, you'll want to write some tests and code. diff --git a/doc/_incl/requisite_incl.rst b/doc/_incl/requisite_incl.rst index fd5e75d54a4..a8c78dc4904 100644 --- a/doc/_incl/requisite_incl.rst +++ b/doc/_incl/requisite_incl.rst @@ -1,9 +1,10 @@ **Before continuing** make sure you have a working Salt installation by -following the :ref:`installation` and the -:ref:`configuration ` instructions. +following the instructions in the +`Salt install guide `_. .. admonition:: Stuck? - There are many ways to :ref:`salt-community` including our - `mailing list `_ - and our `IRC channel `_ #salt. + The Salt Project community can help offer advice and help troubleshoot + technical issues as you're learning about Salt. One of the best places to + talk to the community is on the + `Salt Project Slack workspace `_. diff --git a/doc/contents.rst b/doc/contents.rst index 341cfa881f2..ff1ad97267c 100644 --- a/doc/contents.rst +++ b/doc/contents.rst @@ -10,7 +10,7 @@ Salt Table of Contents topics/about_salt_project topics/index topics/salt_system_architecture - topics/contributing + topics/contributing-guide topics/installation/index topics/configuration/index topics/using_salt diff --git a/doc/topics/contributing.rst b/doc/topics/contributing-guide.rst similarity index 59% rename from doc/topics/contributing.rst rename to doc/topics/contributing-guide.rst index b259e93d4ef..6436c882c1e 100644 --- a/doc/topics/contributing.rst +++ b/doc/topics/contributing-guide.rst @@ -1,3 +1,3 @@ -.. _contributing: +.. _contributing-import: .. include:: ../../CONTRIBUTING.rst \ No newline at end of file diff --git a/doc/topics/development/conventions/documentation.rst b/doc/topics/development/conventions/documentation.rst index dc04f0cd787..4337331a1bc 100644 --- a/doc/topics/development/conventions/documentation.rst +++ b/doc/topics/development/conventions/documentation.rst @@ -1,298 +1,11 @@ .. _salt-docs: ========================== -Writing Salt Documentation +Writing Salt documentation ========================== -Salt's documentation is built using the `Sphinx`_ documentation system. It can -be built in a large variety of output formats including HTML, PDF, ePub, and -manpage. +For the latest information about writing Salt documentation, see: -All the documentation is contained in the main Salt repository. Speaking -broadly, most of the narrative documentation is contained within the -:blob:`doc` subdirectory and most of the reference and API documentation is -written inline with Salt's Python code and extracted using a Sphinx extension. - -.. _`Sphinx`: https://www.sphinx-doc.org/en/master/ - - -.. _docs-style: - -Style -===== - -The Salt project recommends the `IEEE style guide`_ as a general reference for -writing guidelines. Those guidelines are not strictly enforced but rather serve -as an excellent resource for technical writing questions. The `NCBI style -guide`_ is another very approachable resource. - -.. _`IEEE style guide`: https://mentor.ieee.org/myproject/Public/mytools/draft/styleman.pdf -.. _`NCBI style guide`: https://www.ncbi.nlm.nih.gov/books/NBK993/ - -Point-of-view -------------- - -Use third-person perspective and avoid "I", "we", "you" forms of address. -Identify the addressee specifically e.g., "users should", "the compiler does", -etc. - -Active voice ------------- - -Use active voice and present-tense. Avoid filler words. - -Title capitalization --------------------- - -Document titles and section titles within a page should follow normal sentence -capitalization rules. Words that are capitalized as part of a regular sentence -should be capitalized in a title and otherwise left as lowercase. Punctuation -can be omitted unless it aids the intent of the title (e.g., exclamation points -or question marks). - -For example: - -.. code-block:: restructuredtext - - This is a main heading - ====================== - - Paragraph. - - This is an exciting sub-heading! - -------------------------------- - - Paragraph. - - -.. _docs-modules: - -Serial Commas -------------- - -According to Wikipedia: In English punctuation, a serial comma or series comma -(also called Oxford comma and Harvard comma) is a comma placed immediately -before the coordinating conjunction (usually "and", "or", or "nor") in a series of -three or more terms. For example, a list of three countries might be punctuated -either as "France, Italy, and Spain" (with the serial comma), or as "France, -Italy and Spain" (without the serial comma)." - -When writing a list that includes three or more items, the serial comma should -always be used. - -Documenting modules -=================== - -Documentation for Salt's various module types is inline in the code. During the -documentation build process it is extracted and formatted into the final HTML, -PDF, etc format. - -Inline documentation --------------------- - -Python has special multi-line strings called docstrings as the first element in -a function or class. These strings allow documentation to live alongside the -code and can contain special formatting. For example: - -.. code-block:: python - - def my_function(value): - """ - Upper-case the given value - - Usage: - - .. code-block:: python - - val = 'a string' - new_val = myfunction(val) - print(new_val) # 'A STRING' - - :param value: a string - :return: a copy of ``value`` that has been upper-cased - """ - return value.upper() - -Specify a release for additions or changes ------------------------------------------- - -New functions or changes to existing functions should include a marker that -denotes what Salt release will be affected. For example: - -.. code-block:: python - - def my_function(value): - """ - Upper-case the given value - - .. versionadded:: 2014.7.0 - - <...snip...> - """ - return value.upper() - -For changes to a function: - -.. code-block:: python - - def my_function(value, strip=False): - """ - Upper-case the given value - - .. versionchanged:: 2016.3.0 - Added a flag to also strip whitespace from the string. - - <...snip...> - """ - if strip: - return value.upper().strip() - return value.upper() - -Adding module documentation to the index ----------------------------------------- - -Each module type has an index listing all modules of that type. For example: -:ref:`all-salt.modules`, :ref:`all-salt.states`, :ref:`all-salt.renderers`. -New modules must be added to the index manually. - -1. Edit the file for the module type: - :blob:`execution modules `, - :blob:`state modules`, - :blob:`renderer modules `, etc. - -2. Add the new module to the alphabetized list. - -3. :ref:`Build the documentation ` which will generate an ``.rst`` - file for the new module in the same directory as the ``index.rst``. - -4. Commit the changes to ``index.rst`` and the new ``.rst`` file and send a - pull request. - - -.. _docs-ref: - -Cross-references -================ - -The Sphinx documentation system contains a wide variety of cross-referencing -capabilities. - - -.. _docs-ref-glossary: - -Glossary entries ----------------- - -Link to :ref:`glossary entries ` using the `term role`_. A -cross-reference should be added the first time a Salt-specific term is used in -a document. - -.. _`term role`: https://www.sphinx-doc.org/en/master/glossary.html#term-role - -.. code-block:: restructuredtext - - A common way to encapsulate master-side functionality is by writing a - custom :term:`Runner Function`. Custom Runner Functions are easy to write. - - -.. _docs-ref-index: - -Index entries -------------- - -Sphinx automatically generates many kinds of index entries, but it is -occasionally useful to manually add items to the index. - -One method is to use the `index directive`_ above the document or section that -should appear in the index. - -.. _`index directive`: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html?highlight=index%20directive#index-generating-markup - -.. code-block:: restructuredtext - - .. index:: ! Event, event bus, event system - see: Reactor; Event - -Another method is to use the `index role`_ inline with the text that should -appear in the index. The index entry is created and the target text is left -otherwise intact. - -.. _`index role`: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#role-index - -.. code-block:: restructuredtext - - Information about the :index:`Salt Reactor` - ------------------------------------------- - - Paragraph. - - -.. _docs-ref-docs: - -Documents and sections ----------------------- - -Each document should contain a unique top-level label of the form: - -.. code-block:: restructuredtext - - .. _my-page: - - My page - ======= - - Paragraph. - -Unique labels can be linked using the `ref role`_. This allows cross-references -to survive document renames or movement. - -.. code-block:: restructuredtext - - For more information see :ref:`my-page`. - -Note, the ``:doc:`` role should *not* be used to link documents together. - -.. _`ref role`: https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-ref - - -.. _docs-ref-modules: - -Modules -------- - -Cross-references to Salt modules can be added using Sphinx's Python domain -roles. For example, to create a link to the :py:func:`test.ping -` function: - -.. code-block:: restructuredtext - - A useful execution module to test active communication with a minion is the - :py:func:`test.ping ` function. - -Salt modules can be referenced as well: - -.. code-block:: restructuredtext - - The :py:mod:`test module ` contains many useful - functions for inspecting an active Salt connection. - -The same syntax works for all modules types: - -.. code-block:: restructuredtext - - One of the workhorse state module functions in Salt is the - :py:func:`file.managed ` function. - - -.. _docs-ref-settings: - -Settings --------- - -Individual settings in the Salt Master or Salt Minion configuration files are -cross-referenced using two custom roles, ``conf_master``, and ``conf_minion``. - -.. code-block:: restructuredtext - - The :conf_minion:`minion ID ` setting is a unique identifier for a - single minion. +* `Salt docs contributing guide `_ +* `Salt rST guide `_ +* `Salt style guide `_ diff --git a/doc/topics/tutorials/states_pt4.rst b/doc/topics/tutorials/states_pt4.rst index f2fe67348c9..5ca637c67e2 100644 --- a/doc/topics/tutorials/states_pt4.rst +++ b/doc/topics/tutorials/states_pt4.rst @@ -209,8 +209,9 @@ can be found on GitHub in the `saltstack-formulas`_ collection of repositories. .. _`saltstack-formulas`: https://github.com/saltstack-formulas If you have any questions, suggestions, or just want to chat with other people -who are using Salt, we have a very :ref:`active community ` -and we'd love to hear from you. +who are using Salt, we have a very active community and we'd love to hear from +you. One of the best places to talk to the community is on the +`Salt Project Slack workspace `_. In addition, by continuing to the :ref:`Orchestrate Runner ` docs, you can learn about the powerful orchestration of which Salt is capable.