2009-03-15 19:30:09 -05:00
|
|
|
.. highlight:: rest
|
|
|
|
|
|
|
|
:mod:`sphinx.ext.autosummary` -- Generate autodoc summaries
|
|
|
|
===========================================================
|
|
|
|
|
|
|
|
.. module:: sphinx.ext.autosummary
|
|
|
|
:synopsis: Generate autodoc summaries
|
|
|
|
|
2009-09-09 12:18:02 -05:00
|
|
|
.. versionadded:: 0.6
|
|
|
|
|
|
|
|
This extension generates function/method/attribute summary lists, similar to
|
|
|
|
those output e.g. by Epydoc and other API doc generation tools. This is
|
|
|
|
especially useful when your docstrings are long and detailed, and putting each
|
|
|
|
one of them on a separate page makes them easier to read.
|
|
|
|
|
|
|
|
The :mod:`sphinx.ext.autosummary` extension does this in two parts:
|
|
|
|
|
2014-06-18 10:53:25 -05:00
|
|
|
1. There is an :rst:dir:`autosummary` directive for generating summary listings
|
|
|
|
that contain links to the documented items, and short summary blurbs
|
|
|
|
extracted from their docstrings.
|
2009-09-09 12:18:02 -05:00
|
|
|
|
2011-06-29 14:27:43 -05:00
|
|
|
2. Optionally, the convenience script :program:`sphinx-autogen` or the new
|
2009-09-09 12:18:02 -05:00
|
|
|
:confval:`autosummary_generate` config value can be used to generate short
|
2010-04-17 03:39:51 -05:00
|
|
|
"stub" files for the entries listed in the :rst:dir:`autosummary` directives.
|
2014-06-18 10:53:25 -05:00
|
|
|
These files by default contain only the corresponding
|
|
|
|
:mod:`sphinx.ext.autodoc` directive, but can be customized with templates.
|
2009-09-09 12:18:02 -05:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
.. rst:directive:: autosummary
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
Insert a table that contains links to documented items, and a short summary
|
2011-10-09 16:09:57 -05:00
|
|
|
blurb (the first sentence of the docstring) for each of them.
|
2011-06-29 14:27:43 -05:00
|
|
|
|
|
|
|
The :rst:dir:`autosummary` directive can also optionally serve as a
|
|
|
|
:rst:dir:`toctree` entry for the included items. Optionally, stub
|
|
|
|
``.rst`` files for these items can also be automatically generated.
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
For example, ::
|
|
|
|
|
|
|
|
.. currentmodule:: sphinx
|
|
|
|
|
|
|
|
.. autosummary::
|
|
|
|
|
|
|
|
environment.BuildEnvironment
|
|
|
|
util.relative_uri
|
|
|
|
|
|
|
|
produces a table like this:
|
|
|
|
|
|
|
|
.. currentmodule:: sphinx
|
|
|
|
|
|
|
|
.. autosummary::
|
|
|
|
|
|
|
|
environment.BuildEnvironment
|
|
|
|
util.relative_uri
|
|
|
|
|
|
|
|
.. currentmodule:: sphinx.ext.autosummary
|
|
|
|
|
|
|
|
Autosummary preprocesses the docstrings and signatures with the same
|
|
|
|
:event:`autodoc-process-docstring` and :event:`autodoc-process-signature`
|
|
|
|
hooks as :mod:`~sphinx.ext.autodoc`.
|
|
|
|
|
|
|
|
**Options**
|
|
|
|
|
2014-06-18 10:53:25 -05:00
|
|
|
* If you want the :rst:dir:`autosummary` table to also serve as a
|
|
|
|
:rst:dir:`toctree` entry, use the ``toctree`` option, for example::
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
.. autosummary::
|
|
|
|
:toctree: DIRNAME
|
|
|
|
|
|
|
|
sphinx.environment.BuildEnvironment
|
|
|
|
sphinx.util.relative_uri
|
|
|
|
|
|
|
|
The ``toctree`` option also signals to the :program:`sphinx-autogen` script
|
|
|
|
that stub pages should be generated for the entries listed in this
|
|
|
|
directive. The option accepts a directory name as an argument;
|
|
|
|
:program:`sphinx-autogen` will by default place its output in this
|
|
|
|
directory. If no argument is given, output is placed in the same directory
|
|
|
|
as the file that contains the directive.
|
|
|
|
|
2014-06-18 10:53:25 -05:00
|
|
|
* If you don't want the :rst:dir:`autosummary` to show function signatures in
|
|
|
|
the listing, include the ``nosignatures`` option::
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
.. autosummary::
|
|
|
|
:nosignatures:
|
|
|
|
|
|
|
|
sphinx.environment.BuildEnvironment
|
|
|
|
sphinx.util.relative_uri
|
|
|
|
|
|
|
|
* You can specify a custom template with the ``template`` option.
|
|
|
|
For example, ::
|
|
|
|
|
|
|
|
.. autosummary::
|
|
|
|
:template: mytemplate.rst
|
|
|
|
|
|
|
|
sphinx.environment.BuildEnvironment
|
|
|
|
|
|
|
|
would use the template :file:`mytemplate.rst` in your
|
|
|
|
:confval:`templates_path` to generate the pages for all entries
|
|
|
|
listed. See `Customizing templates`_ below.
|
|
|
|
|
2010-02-21 14:57:58 -06:00
|
|
|
.. versionadded:: 1.0
|
|
|
|
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
:program:`sphinx-autogen` -- generate autodoc stub pages
|
|
|
|
--------------------------------------------------------
|
|
|
|
|
|
|
|
The :program:`sphinx-autogen` script can be used to conveniently generate stub
|
2010-04-17 03:39:51 -05:00
|
|
|
documentation pages for items included in :rst:dir:`autosummary` listings.
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
For example, the command ::
|
|
|
|
|
|
|
|
$ sphinx-autogen -o generated *.rst
|
|
|
|
|
2014-06-18 10:53:25 -05:00
|
|
|
will read all :rst:dir:`autosummary` tables in the :file:`*.rst` files that have
|
|
|
|
the ``:toctree:`` option set, and output corresponding stub pages in directory
|
2009-09-09 12:18:02 -05:00
|
|
|
``generated`` for all documented items. The generated pages by default contain
|
|
|
|
text of the form::
|
|
|
|
|
|
|
|
sphinx.util.relative_uri
|
|
|
|
========================
|
|
|
|
|
|
|
|
.. autofunction:: sphinx.util.relative_uri
|
|
|
|
|
|
|
|
If the ``-o`` option is not given, the script will place the output files in the
|
|
|
|
directories specified in the ``:toctree:`` options.
|
|
|
|
|
2017-07-11 09:58:20 -05:00
|
|
|
For more information, refer to the :doc:`sphinx-autogen documentation
|
|
|
|
</man/sphinx-autogen>`
|
|
|
|
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
Generating stub pages automatically
|
|
|
|
-----------------------------------
|
|
|
|
|
|
|
|
If you do not want to create stub pages with :program:`sphinx-autogen`, you can
|
|
|
|
also use this new config value:
|
|
|
|
|
|
|
|
.. confval:: autosummary_generate
|
|
|
|
|
|
|
|
Boolean indicating whether to scan all found documents for autosummary
|
|
|
|
directives, and to generate stub pages for each.
|
|
|
|
|
|
|
|
Can also be a list of documents for which stub pages should be generated.
|
|
|
|
|
|
|
|
The new files will be placed in the directories specified in the
|
|
|
|
``:toctree:`` options of the directives.
|
|
|
|
|
|
|
|
|
|
|
|
Customizing templates
|
|
|
|
---------------------
|
|
|
|
|
2010-02-21 14:57:58 -06:00
|
|
|
.. versionadded:: 1.0
|
|
|
|
|
2009-09-09 12:18:02 -05:00
|
|
|
You can customize the stub page templates, in a similar way as the HTML Jinja
|
|
|
|
templates, see :ref:`templating`. (:class:`~sphinx.application.TemplateBridge`
|
|
|
|
is not supported.)
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
If you find yourself spending much time tailoring the stub templates, this
|
|
|
|
may indicate that it's a better idea to write custom narrative documentation
|
|
|
|
instead.
|
|
|
|
|
2017-03-25 16:16:28 -05:00
|
|
|
Autosummary uses the following Jinja template files:
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
- :file:`autosummary/base.rst` -- fallback template
|
|
|
|
- :file:`autosummary/module.rst` -- template for modules
|
|
|
|
- :file:`autosummary/class.rst` -- template for classes
|
|
|
|
- :file:`autosummary/function.rst` -- template for functions
|
|
|
|
- :file:`autosummary/attribute.rst` -- template for class attributes
|
|
|
|
- :file:`autosummary/method.rst` -- template for class methods
|
|
|
|
|
|
|
|
The following variables available in the templates:
|
|
|
|
|
2010-01-07 06:59:06 -06:00
|
|
|
.. currentmodule:: None
|
|
|
|
|
2009-09-09 12:18:02 -05:00
|
|
|
.. data:: name
|
|
|
|
|
|
|
|
Name of the documented object, excluding the module and class parts.
|
|
|
|
|
|
|
|
.. data:: objname
|
|
|
|
|
|
|
|
Name of the documented object, excluding the module parts.
|
|
|
|
|
|
|
|
.. data:: fullname
|
|
|
|
|
|
|
|
Full name of the documented object, including module and class parts.
|
|
|
|
|
|
|
|
.. data:: module
|
|
|
|
|
|
|
|
Name of the module the documented object belongs to.
|
|
|
|
|
|
|
|
.. data:: class
|
|
|
|
|
|
|
|
Name of the class the documented object belongs to. Only available for
|
|
|
|
methods and attributes.
|
|
|
|
|
|
|
|
.. data:: underline
|
|
|
|
|
2017-03-25 16:16:28 -05:00
|
|
|
A string containing ``len(full_name) * '='``. Use the ``underline`` filter
|
|
|
|
instead.
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
.. data:: members
|
|
|
|
|
|
|
|
List containing names of all members of the module or class. Only available
|
|
|
|
for modules and classes.
|
|
|
|
|
2018-05-31 23:29:00 -05:00
|
|
|
.. data:: inherited_members
|
|
|
|
|
|
|
|
List containing names of all inherited members of class. Only available for
|
|
|
|
classes.
|
|
|
|
|
2018-09-02 20:46:38 -05:00
|
|
|
.. versionadded:: 1.8.0
|
|
|
|
|
2009-09-09 12:18:02 -05:00
|
|
|
.. data:: functions
|
|
|
|
|
|
|
|
List containing names of "public" functions in the module. Here, "public"
|
|
|
|
here means that the name does not start with an underscore. Only available
|
|
|
|
for modules.
|
|
|
|
|
|
|
|
.. data:: classes
|
|
|
|
|
|
|
|
List containing names of "public" classes in the module. Only available for
|
|
|
|
modules.
|
|
|
|
|
|
|
|
.. data:: exceptions
|
|
|
|
|
|
|
|
List containing names of "public" exceptions in the module. Only available
|
|
|
|
for modules.
|
|
|
|
|
|
|
|
.. data:: methods
|
|
|
|
|
|
|
|
List containing names of "public" methods in the class. Only available for
|
|
|
|
classes.
|
|
|
|
|
2009-12-24 06:29:11 -06:00
|
|
|
.. data:: attributes
|
2009-09-09 12:18:02 -05:00
|
|
|
|
|
|
|
List containing names of "public" attributes in the class. Only available
|
|
|
|
for classes.
|
|
|
|
|
2017-03-25 16:16:28 -05:00
|
|
|
|
|
|
|
Additionally, the following filters are available
|
|
|
|
|
|
|
|
.. function:: escape(s)
|
|
|
|
|
|
|
|
Escape any special characters in the text to be used in formatting RST
|
2017-08-05 06:50:26 -05:00
|
|
|
contexts. For instance, this prevents asterisks making things bold. This
|
2017-03-25 16:16:28 -05:00
|
|
|
replaces the builtin Jinja `escape filter`_ that does html-escaping.
|
|
|
|
|
|
|
|
.. function:: underline(s, line='=')
|
|
|
|
|
|
|
|
Add a title underline to a piece of text.
|
|
|
|
|
|
|
|
For instance, ``{{ fullname | escape | underline }}`` should be used to produce
|
|
|
|
the title of a page.
|
|
|
|
|
2009-09-09 12:18:02 -05:00
|
|
|
.. note::
|
2009-10-26 03:45:50 -05:00
|
|
|
|
2010-04-17 03:39:51 -05:00
|
|
|
You can use the :rst:dir:`autosummary` directive in the stub pages.
|
2009-09-09 12:18:02 -05:00
|
|
|
Stub pages are generated also based on these directives.
|
2017-03-25 16:16:28 -05:00
|
|
|
|
|
|
|
.. _`escape filter`: http://jinja.pocoo.org/docs/2.9/templates/#escape
|