I want to build our documentation using sphinx and get the same formatting on parameters as the NumPy docs ( https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt )
I have found two ways to document parameters in this rst style with sphinx, one which is
:param name: description
or
:keyword name: description
and the other (which is the NumPy style)
Parameters
----------
name: type
description
Here is an example of what that looks like:
http://docs.scipy.org/doc/numpy/reference/distutils.html#module-numpy.distutils
and the source
def get_subpackage(self,subpackage_name,
subpackage_path=None,
parent_name=None,
caller_level = 1):
"""Return list of subpackage configurations.
Parameters
----------
subpackage_name: str,None
Name of the subpackage to get the configuration. '*' in
subpackage_name is handled as a wildcard.
subpackage_path: str
If None, then the path is assumed to be the local path plus the
subpackage_name. If a setup.py file is not found in the
subpackage_path, then a default configuration is used.
parent_name: str
Parent name.
"""
However, when I build the docs with sphinx ( I am using sphinx-apidoc and sphinx-build ), I can generate the formatted lists when I use the first syntax ( :param name: description), but when I try to use the NumPy style I do not get the formatting. Looking at the rst syntax ( http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#sections ) it seems that something like
Parameters
----------
is just a section title. But using this formatting with sphinx the title Parameter does not appear in the output, and it gets none of the parameter section formatting.
Does anyone know how NumPy builds the documentation with sphinx to get this sort of formatting to work for parameters?
I have tried to look at the makefile and conf.py, and I'm just not sure how
The Sphinx docstring formatA pair of :param: and :type: directive options must be used for each parameter we wish to document. The :raises: option is used to describe any errors that are raised by the code, while the :return: and :rtype: options are used to describe any values returned by our code.
numpydoc style docstrings are written in restructured text. They are composed of a short description of the object followed by a few required and optional sections. For functions and methods, these sections are: Required. Parameters.
The docstring in NumPy style consists of several sections. At a minimum, start with a short (one-line) summary of what the function does. If useful, add a few extra lines of extended summary. Then add a section describing the parameters and their types, and another section for the return values.
autodoc imports the modules to be documented. If any modules have side effects on import, these will be executed by autodoc when sphinx-build is run. If you document scripts (as opposed to library modules), make sure their main routine is protected by a if __name__ == '__main__' condition.
NumPy uses a custom Sphinx extension: https://pypi.python.org/pypi/numpydoc.
You can install it with
pip install numpydoc
and then you add it to the sphinx conf.py file by adding to the extensions list
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'numpydoc']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With