numpy - NumPy 如何将文档字符串处理为参数的 sphinx 文档?

标签 numpy python-sphinx docstring

我想使用 sphinx 构建我们的文档并获得与 NumPy 文档( https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt )相同的参数格式

我找到了两种使用 sphinx 以这种第一种样式记录参数的方法,一种是

:param name: description

或者
:keyword name: description

和另一个(这是 NumPy 风格)
Parameters
----------
name: type
    description

下面是一个示例:

http://docs.scipy.org/doc/numpy/reference/distutils.html#module-numpy.distutils

和来源
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.
    """

但是,当我使用 sphinx 构建文档时(我使用 sphinx-apidoc 和 sphinx-build),当我使用第一种语法(:param name: description)时,我可以生成格式化列表,但是当我尝试使用 NumPy style 我没有得到格式。查看第一个语法( http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#sections ),似乎类似于
Parameters
----------

只是一个章节标题。但是将这种格式与 sphinx 一起使用时,标题参数不会出现在输出中,并且不会获得任何参数部分格式。

有谁知道 NumPy 如何使用 sphinx 构建文档以使这种格式适用于参数?

我试图查看 makefile 和 conf.py,但我不确定如何

最佳答案

NumPy 使用自定义 Sphinx 扩展:https://pypi.python.org/pypi/numpydoc .

你可以安装它

pip install numpydoc

然后通过添加到扩展列表将其添加到 sphinx conf.py 文件中
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'numpydoc']

关于numpy - NumPy 如何将文档字符串处理为参数的 sphinx 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17397483/

相关文章:

python - 将作为矩阵的 numpy 数组字段值拆分为列向量

python - 无法在 Sphinx 中获取 TOCTREE 以显示链接

python-sphinx - 用 reStructuredText (Sphinx) 替换文件名?

python "See help(type(self)) for accurate signature."

python - 结构化 python 文档字符串,IDE 友好

python - Python中一定距离内去重

Python 更新全局变量

python-sphinx - Sphinx Pygments 词法分析器过滤器扩展?

python - 将 javadoc 用于 Python 文档

python - 如何根据其他列值动态填充列值?