| 1 |
========== |
| 2 |
Extensions |
| 3 |
========== |
| 4 |
|
| 5 |
Since many projects will need special features in their documentation, Sphinx |
| 6 |
allows adding "extensions" to the build process, each of which can modify |
| 7 |
almost any aspect of document processing. |
| 8 |
|
| 9 |
This chapter describes the extensions bundled with Sphinx. For the API |
| 10 |
documentation on writing your own extension, refer to :ref:`dev-extensions`. |
| 11 |
|
| 12 |
|
| 13 |
.. _builtin-extensions: |
| 14 |
|
| 15 |
Built-in extensions |
| 16 |
------------------- |
| 17 |
|
| 18 |
These extensions are built in and can be activated by respective entries in the |
| 19 |
:confval:`extensions` configuration value: |
| 20 |
|
| 21 |
.. toctree:: |
| 22 |
:maxdepth: 1 |
| 23 |
|
| 24 |
apidoc |
| 25 |
autodoc |
| 26 |
autosectionlabel |
| 27 |
autosummary |
| 28 |
coverage |
| 29 |
doctest |
| 30 |
duration |
| 31 |
extlinks |
| 32 |
githubpages |
| 33 |
graphviz |
| 34 |
ifconfig |
| 35 |
imgconverter |
| 36 |
inheritance |
| 37 |
intersphinx |
| 38 |
linkcode |
| 39 |
math |
| 40 |
napoleon |
| 41 |
todo |
| 42 |
viewcode |
| 43 |
|
| 44 |
|
| 45 |
.. _third-party-extensions: |
| 46 |
|
| 47 |
Third-party extensions |
| 48 |
---------------------- |
| 49 |
|
| 50 |
You can find several extensions contributed by users in the `sphinx-contrib`__ |
| 51 |
organization. If you wish to include your extension in this organization, |
| 52 |
simply follow the instructions provided in the `github-administration`__ |
| 53 |
project. This is optional and there are several extensions hosted elsewhere. |
| 54 |
The `awesome-sphinxdoc`__ and `sphinx-extensions`__ projects are both curated |
| 55 |
lists of Sphinx packages, and many packages use the |
| 56 |
`Framework :: Sphinx :: Extension`__ and |
| 57 |
`Framework :: Sphinx :: Theme`__ trove classifiers for Sphinx extensions and |
| 58 |
themes, respectively. |
| 59 |
|
| 60 |
.. __: https://github.com/sphinx-contrib/ |
| 61 |
.. __: https://github.com/sphinx-contrib/github-administration |
| 62 |
.. __: https://github.com/yoloseem/awesome-sphinxdoc |
| 63 |
.. __: https://sphinx-extensions.readthedocs.io/en/latest/ |
| 64 |
.. __: https://pypi.org/search/?c=Framework+%3A%3A+Sphinx+%3A%3A+Extension |
| 65 |
.. __: https://pypi.org/search/?c=Framework+%3A%3A+Sphinx+%3A%3A+Theme |
| 66 |
|
| 67 |
Where to put your own extensions? |
| 68 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 69 |
|
| 70 |
Extensions local to a project should be put within the project's directory |
| 71 |
structure. Set Python's module search path, ``sys.path``, accordingly so that |
| 72 |
Sphinx can find them. For example, if your extension ``foo.py`` lies in the |
| 73 |
``exts`` subdirectory of the project root, put into :file:`conf.py`: |
| 74 |
|
| 75 |
.. code-block:: python |
| 76 |
|
| 77 |
import sys |
| 78 |
from pathlib import Path |
| 79 |
|
| 80 |
sys.path.append(str(Path('exts').resolve())) |
| 81 |
|
| 82 |
extensions = ['foo'] |
| 83 |
|
| 84 |
You can also install extensions anywhere else on ``sys.path``, e.g. in the |
| 85 |
``site-packages`` directory. |