| 1 |
:mod:`sphinx.ext.coverage` -- Collect doc coverage stats |
| 2 |
======================================================== |
| 3 |
|
| 4 |
.. module:: sphinx.ext.coverage |
| 5 |
:synopsis: Check Python modules and C API for coverage in the documentation. |
| 6 |
|
| 7 |
.. role:: code-py(code) |
| 8 |
:language: Python |
| 9 |
|
| 10 |
This extension features one additional builder, the :class:`CoverageBuilder`. |
| 11 |
|
| 12 |
.. todo:: Write this section. |
| 13 |
|
| 14 |
.. note:: |
| 15 |
|
| 16 |
The :doc:`sphinx-apidoc </man/sphinx-apidoc>` command can be used to |
| 17 |
automatically generate API documentation for all code in a project, |
| 18 |
avoiding the need to manually author these documents and keep them up-to-date. |
| 19 |
|
| 20 |
.. warning:: |
| 21 |
|
| 22 |
:mod:`~sphinx.ext.coverage` **imports** the modules to be documented. |
| 23 |
If any modules have side effects on import, |
| 24 |
these will be executed by the coverage builder when ``sphinx-build`` is run. |
| 25 |
|
| 26 |
If you document scripts (as opposed to library modules), |
| 27 |
make sure their main routine is protected by a |
| 28 |
``if __name__ == '__main__'`` condition. |
| 29 |
|
| 30 |
.. note:: |
| 31 |
|
| 32 |
For Sphinx (actually, the Python interpreter that executes Sphinx) |
| 33 |
to find your module, it must be importable. |
| 34 |
That means that the module or the package must be in |
| 35 |
one of the directories on :data:`sys.path` -- adapt your :data:`sys.path` |
| 36 |
in the configuration file accordingly. |
| 37 |
|
| 38 |
To use this builder, activate the coverage extension in your configuration file |
| 39 |
and run ``sphinx-build -M coverage`` on the command line. |
| 40 |
|
| 41 |
|
| 42 |
Builder |
| 43 |
------- |
| 44 |
|
| 45 |
.. py:class:: CoverageBuilder |
| 46 |
|
| 47 |
|
| 48 |
Configuration |
| 49 |
------------- |
| 50 |
|
| 51 |
Several configuration values can be used to specify |
| 52 |
what the builder should check: |
| 53 |
|
| 54 |
.. confval:: coverage_modules |
| 55 |
:type: :code-py:`Sequence[str]` |
| 56 |
:default: :code-py:`()` |
| 57 |
|
| 58 |
List of Python packages or modules to test coverage for. |
| 59 |
When this is provided, Sphinx will introspect each package |
| 60 |
or module provided in this list as well |
| 61 |
as all sub-packages and sub-modules found in each. |
| 62 |
When this is not provided, Sphinx will only provide coverage |
| 63 |
for Python packages and modules that it is aware of: |
| 64 |
that is, any modules documented using the :rst:dir:`py:module` directive |
| 65 |
provided in the :doc:`Python domain </usage/domains/python>` |
| 66 |
or the :rst:dir:`automodule` directive provided by the |
| 67 |
:mod:`~sphinx.ext.autodoc` extension. |
| 68 |
|
| 69 |
.. versionadded:: 7.4 |
| 70 |
|
| 71 |
.. confval:: coverage_ignore_modules |
| 72 |
coverage_ignore_functions |
| 73 |
coverage_ignore_classes |
| 74 |
coverage_ignore_pyobjects |
| 75 |
:type: :code-py:`Sequence[str]` |
| 76 |
:default: :code-py:`()` |
| 77 |
|
| 78 |
List of `Python regular expressions`_. |
| 79 |
|
| 80 |
If any of these regular expressions matches any part of the full import path |
| 81 |
of a Python object, that Python object is excluded from the documentation |
| 82 |
coverage report. |
| 83 |
|
| 84 |
.. _Python regular expressions: https://docs.python.org/library/re |
| 85 |
|
| 86 |
.. versionadded:: 2.1 |
| 87 |
|
| 88 |
.. confval:: coverage_c_path |
| 89 |
:type: :code-py:`Sequence[str]` |
| 90 |
:default: :code-py:`()` |
| 91 |
|
| 92 |
.. confval:: coverage_c_regexes |
| 93 |
:type: :code-py:`dict[str, str]` |
| 94 |
:default: :code-py:`{}` |
| 95 |
|
| 96 |
.. confval:: coverage_ignore_c_items |
| 97 |
:type: :code-py:`dict[str, Sequence[str]]` |
| 98 |
:default: :code-py:`{}` |
| 99 |
|
| 100 |
.. confval:: coverage_write_headline |
| 101 |
:type: :code-py:`bool` |
| 102 |
:default: :code-py:`True` |
| 103 |
|
| 104 |
Set to ``False`` to not write headlines. |
| 105 |
|
| 106 |
.. versionadded:: 1.1 |
| 107 |
|
| 108 |
.. confval:: coverage_skip_undoc_in_source |
| 109 |
:type: :code-py:`bool` |
| 110 |
:default: :code-py:`False` |
| 111 |
|
| 112 |
Skip objects that are not documented in the source with a docstring. |
| 113 |
|
| 114 |
.. versionadded:: 1.1 |
| 115 |
|
| 116 |
.. confval:: coverage_show_missing_items |
| 117 |
:type: :code-py:`bool` |
| 118 |
:default: :code-py:`False` |
| 119 |
|
| 120 |
Print objects that are missing to standard output also. |
| 121 |
|
| 122 |
.. versionadded:: 3.1 |
| 123 |
|
| 124 |
.. confval:: coverage_statistics_to_report |
| 125 |
:type: :code-py:`bool` |
| 126 |
:default: :code-py:`True` |
| 127 |
|
| 128 |
Print a tabular report of the coverage statistics to the coverage report. |
| 129 |
|
| 130 |
Example output: |
| 131 |
|
| 132 |
.. code-block:: text |
| 133 |
|
| 134 |
+-----------------------+----------+--------------+ |
| 135 |
| Module | Coverage | Undocumented | |
| 136 |
+=======================+==========+==============+ |
| 137 |
| package.foo_module | 100.00% | 0 | |
| 138 |
+-----------------------+----------+--------------+ |
| 139 |
| package.bar_module | 83.33% | 1 | |
| 140 |
+-----------------------+----------+--------------+ |
| 141 |
|
| 142 |
.. versionadded:: 7.2 |
| 143 |
|
| 144 |
.. confval:: coverage_statistics_to_stdout |
| 145 |
:type: :code-py:`bool` |
| 146 |
:default: :code-py:`False` |
| 147 |
|
| 148 |
Print a tabular report of the coverage statistics to standard output. |
| 149 |
|
| 150 |
Example output: |
| 151 |
|
| 152 |
.. code-block:: text |
| 153 |
|
| 154 |
+-----------------------+----------+--------------+ |
| 155 |
| Module | Coverage | Undocumented | |
| 156 |
+=======================+==========+==============+ |
| 157 |
| package.foo_module | 100.00% | 0 | |
| 158 |
+-----------------------+----------+--------------+ |
| 159 |
| package.bar_module | 83.33% | 1 | |
| 160 |
+-----------------------+----------+--------------+ |
| 161 |
|
| 162 |
.. versionadded:: 7.2 |