| 1 |
|
| 2 |
Sphinx Integration |
| 3 |
================== |
| 4 |
|
| 5 |
Sphinx object inventories can be used to create links in both ways between |
| 6 |
documentation generated by pydoctor and by Sphinx. |
| 7 |
|
| 8 |
|
| 9 |
Linking from pydoctor to external API docs |
| 10 |
------------------------------------------ |
| 11 |
|
| 12 |
It can link to external API documentation using a Sphinx objects inventory |
| 13 |
with the following cumulative configuration option:: |
| 14 |
|
| 15 |
--intersphinx=https://docs.python.org/3/objects.inv |
| 16 |
|
| 17 |
.. note:: The URL must point to the the ``objects.inv``. |
| 18 |
|
| 19 |
Then, your interpreted text, with backticks (`````) using `restructuredtext` and |
| 20 |
with ``L{}`` tag using `epytext`, will be linked to the Python element. Example:: |
| 21 |
|
| 22 |
`datetime.datetime` |
| 23 |
L{datetime.datetime} |
| 24 |
|
| 25 |
Simple as that! |
| 26 |
|
| 27 |
Linking from Sphinx to your pydoctor API docs |
| 28 |
--------------------------------------------- |
| 29 |
|
| 30 |
pydoctor's HTML generator will also generate a Sphinx objects inventory that can be |
| 31 |
used with the following mapping: |
| 32 |
|
| 33 |
* packages, modules -> ``:py:mod:`` |
| 34 |
* classes -> ``:py:class:`` |
| 35 |
* functions -> ``:py:func:`` |
| 36 |
* methods -> ``:py:meth:`` |
| 37 |
* attributes -> ``:py:attr:`` |
| 38 |
|
| 39 |
You can use this mapping in Sphinx via the `Intersphinx extension`__. |
| 40 |
|
| 41 |
__ https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html |
| 42 |
|
| 43 |
For an up to date lists of API links, |
| 44 |
run pydoctor before building the Sphinx documentation. |
| 45 |
|
| 46 |
You can use the ``--make-intersphinx`` option to only generate the object inventory file. |
| 47 |
|
| 48 |
You will then reference this file inside the Sphinx `intersphinx_mapping`. |
| 49 |
|
| 50 |
Note that relative paths are relative to the Sphinx source directory. |
| 51 |
You might need to exit the source and reference the build directory:: |
| 52 |
|
| 53 |
intersphinx_mapping = { |
| 54 |
'twisted': ('https://twistedmatrix.com/documents/current/api/', '../../build/apidocs/objects.inv'), |
| 55 |
} |
| 56 |
|
| 57 |
Link to elements :py:func:`with custom text <twisted:twisted.web.client.urlunparse>` with:: |
| 58 |
|
| 59 |
:py:func:`with custom text <twisted:twisted.web.client.urlunparse>` |
| 60 |
|
| 61 |
Link to elements with default label :py:class:`twisted:twisted.web.client.HTTPDownloader` with:: |
| 62 |
|
| 63 |
:py:class:`twisted:twisted.web.client.HTTPDownloader` |
| 64 |
|
| 65 |
|
| 66 |
Building pydoctor together with Sphinx HTML build |
| 67 |
------------------------------------------------- |
| 68 |
|
| 69 |
When running pydoctor with HTML generation it will generate a set of static |
| 70 |
HTML files that can be used any HTTP server. |
| 71 |
|
| 72 |
Under some circumstances (ex Read The Docs) you might want to trigger the |
| 73 |
pydoctor API docs build together with the Sphinx build. |
| 74 |
|
| 75 |
This can be done by using the :py:mod:`pydoctor.sphinx_ext.build_apidocs` extension. |
| 76 |
|
| 77 |
Inside your Sphinx ``conf.py`` file enable and configure the extension in this |
| 78 |
way:: |
| 79 |
|
| 80 |
extensions.append("pydoctor.sphinx_ext.build_apidocs") |
| 81 |
|
| 82 |
pydoctor_args = [ |
| 83 |
'--project-name=YOUR-PROJECT-NAME', |
| 84 |
'--project-version=YOUR-PUBLIC-VERSION', |
| 85 |
'--project-url=YOUR-PROJECT-HOME-URL', |
| 86 |
'--docformat=epytext', |
| 87 |
'--intersphinx=https://docs.python.org/3/objects.inv', |
| 88 |
'--html-viewsource-base=https://github.com/ORG/REPO/tree/default', |
| 89 |
'--html-output={outdir}/api', |
| 90 |
'--project-base-dir=path/to/source/code', |
| 91 |
'path/to/source/code/package1' |
| 92 |
] |
| 93 |
|
| 94 |
pydoctor_url_path = '/en/{rtd_version}/api/' |
| 95 |
|
| 96 |
You can pass almost any argument to ``pydoctor_args`` |
| 97 |
in the same way you call ``pydoctor`` from the command line. |
| 98 |
|
| 99 |
You don't need to pass the ``--make-html``, ``--make-intersphinx`` or ``--quiet`` |
| 100 |
arguments. |
| 101 |
The extension will add them automatically. |
| 102 |
|
| 103 |
The ``pydoctor_url_path`` is an URL path, |
| 104 |
relative to your public API documentation site. |
| 105 |
``{rtd_version}`` will be replaced with the Read The Docs version (``stable`` , ``latest``, tag name). |
| 106 |
You only need to define this argument if you need to have Intersphinx links |
| 107 |
from your Sphinx narrative documentation to your pydoctor API documentation. |
| 108 |
|
| 109 |
As a hack to integrate the pydoctor API docs ``index.html`` with the Sphinx TOC |
| 110 |
and document reference, you can create an ``index.rst`` at the location where |
| 111 |
the pydoctor ``index.html`` is hosted. |
| 112 |
The Sphinx ``index.html`` will be generated during the Sphinx build process and |
| 113 |
later overwritten by the pydoctor build process. |
| 114 |
|
| 115 |
It is possible to call pydoctor multiple times (with different arguments) as |
| 116 |
part of the same build process. |
| 117 |
For this you need to define ``pydoctor_args`` as a dict. |
| 118 |
The key is the human readable build name and the value for each dict member |
| 119 |
is the list of arguments. |
| 120 |
See pydoctor's own `conf.py <https://github.com/twisted/pydoctor/blob/master/docs/source/conf.py>`_ |
| 121 |
for usage example. |