zwang123 / sphinx-autodoc-defaultargs

Automatic generation of default arguments for the Sphinx autodoc extension.
MIT License
4 stars 0 forks source link

sphinx-autodoc-defaultargs

PyPi Version Build Status Coverage Status License Python Versions

Overview

This extension automatically generates default arguments for the Sphinx autodoc extension.

Example

With this package, the default values of all documented arguments, and undocumented arguments if enabled, are automatically detected and added to the docstring.

It also detects existing documentation of default arguments with the text unchanged.

def func(x=None, y=None):
    """
    Example docstring.

    :param x: The default value ``None`` will be added here.
    :param y: The text of default value is unchanged.
              (Default: ``'Default Value'``)
    """

    if y is None:
        y = 'Default Value'

    ...

Installation

pip

If you use pip, you can install the package with:

python -m pip install sphinx_autodoc_defaultargs

setup.py

In the root directory, run the following command in the terminal.

python setup.py install

Usage

Add the extension as well as the global substitution to the conf.py file:

extensions = [
    'sphinx.ext.autodoc',
    'sphinx_autodoc_defaultargs'
]

rst_prolog = """
.. |default| raw:: html

    <div class="default-value-section">""" + \
    ' <span class="default-value-label">Default:</span>'

Note that it should be loaded after sphinx.ext.napoleon.

Config Options