Skip to content

Commit 836e657

Browse files
jorgepilotoPipKat
andauthored
ENH: add documentation formatting tools section (#78)
* Add formatting tools section * Apply suggestions from code review Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com> Co-authored-by: Kathy Pippert <84872299+PipKat@users.noreply.github.com>
1 parent 4d753ba commit 836e657

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Formatting Tools
2+
================
3+
4+
There are plenty of tools for documentation style and coverage. This section
5+
presents some of the most popular ones in the Python ecosystem. A minimum
6+
configuration is provided for each one so you can easily include them in your
7+
PyAnsys project.
8+
9+
Most of the tools presented can be configured using :ref:`the
10+
\`\`pyproject.toml\`\` file`, avoiding dotfiles and thus leading to a much
11+
cleaner root project directory.
12+
13+
14+
Codespell
15+
---------
16+
17+
`Codespell`_ checks for common misspellings in text files. This implies that it
18+
is not limited to Python files but can check any human-readable file.
19+
20+
It is possible to ignore words that are flagged as misspelled. You can specify these words in a
21+
file that can hen be passed to `codespell` by running:
22+
23+
.. code:: bash
24+
25+
codespell --write-changes --ignore-words=<FILE>
26+
27+
28+
Docformatter
29+
------------
30+
31+
`Docformatter`_ allows you to automatically format Python docstrings according
32+
to `PEP 257`_. To make sure `docformatter`_ wraps your docstrings at a given
33+
number of characters, the following configuration should be used:
34+
35+
36+
.. code:: bash
37+
38+
docformatter -r -i --wrap-summaries <length> --wrap-descriptions <length> src
39+
40+
41+
Doctest
42+
-------
43+
44+
`Doctest`_ is a module from the Python standard library, which means it is
45+
included by default with your Python installation. It is used for checking the
46+
examples provided inside docstrings to make sure that they reflect the current usage
47+
of the source code. `Doctest`_ can be integrated with ``pytest`` in :ref:`The
48+
\`\`pyproject.toml\`\` File`:
49+
50+
.. code:: toml
51+
52+
[tool.pytest.ini_options]
53+
addopts = "--doctest-modules"
54+
55+
56+
Interrogate
57+
-----------
58+
59+
`Interrogate`_ is a tool for checking docstring coverage. Similar to source code
60+
coverage tools, this tool tests how many functions, classes, and modules in a Python
61+
library hold a docstring.
62+
63+
.. code:: toml
64+
65+
[tool.interrogate]
66+
exclude = ["setup.py", "doc", "tests"]
67+
color = true
68+
verbose = 2
69+
70+
Alternate tools to `interrogate`_ are `docstr-coverage`_ and
71+
`docstring-coverage`_. However, `interrogate`_ is modern and maintained, with
72+
output resembling that of `pytest-cov`_, which is the the equivalent tool
73+
for source code coverage.
74+
75+
76+
Pydocstyle
77+
----------
78+
79+
`Pydocstyle`_ is a tool for checking the compliance of Python docstrings with `PEP
80+
257`_. Its configuration can be defined in the :ref:`The \`\`pyproject.toml\`\`
81+
File`. By default, it will match all ``*.py`` files except those starting with
82+
``test_*.py``. Default `pydocstyle`_ configuration should be enough for a
83+
PyAnsys project. If additional configuration is needed, it must be included
84+
under the ``[tool.pydocstyle]`` entry:
85+
86+
.. code:: toml
87+
88+
[tool.pydocstyle]
89+
# Additional configuration
90+
91+
92+
.. _interrogate: https://interrogate.readthedocs.io/en/latest/
93+
.. _docstr-coverage: https://docstr-coverage.readthedocs.io/en/latest/index.html
94+
.. _docstring-coverage: https://bitbucket.org/DataGreed/docstring-coverage/wiki/Home
95+
.. _pytest-cov: https://pytest-cov.readthedocs.io/en/latest/
96+
.. _doctest: https://docs.python.org/3/library/doctest.html
97+
.. _PEP 257: http://www.python.org/dev/peps/pep-0257/
98+
.. _docformatter: https://github.com/PyCQA/docformatter
99+
.. _codespell: https://github.com/codespell-project/codespell
100+
.. _pytest-cov: https://pytest-cov.readthedocs.io/en/latest/

doc/source/documentation_style/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ see :ref:`documentation_deployment`.
4141
docstrings
4242
class_documentation
4343
deployment
44+
formatting-tools

0 commit comments

Comments
 (0)