如何让Sphinx autosummary为类生成完整的API文档以及一个该类的“摘要表”?

12

我相信这在某种程度上是用户错误,但我正在慢慢地疯狂,真的很需要帮助。

我已经成功使用了sphinx-apidoc和优秀的第三方sphinx-autoapi,但无法像sphinx.ext.autosummary一样重复这个技巧。这让我发疯了......而且这些选项都没有提供真正整洁的包/模块成员摘要表,这(大概)是sphinx.ext.autosummary的主要卖点。

我有一个非常简单的项目:

|_ TEST
   |_ docs
      |_ conf.py
      |_ index.rst
   |_ myproject
      |_ __init__.py
      |_ mymodule.py

conf.py 文件如下所示:

import os
import sys
sys.path.insert(0, os.path.abspath('../../myproject'))

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

autosummary_generate = True

index.rst看起来像这样:

.. autosummary::
   :toctree: _autosummary

   myproject.mymodule

mymodule.py看起来像这样:

"""
Module containing a class and a function.
"""

class TestClass:
    """
    A class representing a test.

    I wish I could get this to stuff to show up but I can't and I don't know why.

    Why isn't this documentation visible?!? :-(
    """
    def __init__(self):
        """
        Instantiate.
        """
        pass

    def Func_in_test_class(self):
        """
        Cool function that does stuff.

        :return: Some new stuff.
        """
        pass

def GlobalFunc():
    """
    Utility function.

    Does some good stuff.
    """
    pass

docs目录中运行make html命令,可以生成漂亮的Readthedocs风格的HTML文档:

(见图片)

我想要做的是,在摘要表格中点击TestClass函数,然后跳转到一个新页面,显示该类的完整API文档。我该如何实现?
(或者我是否误解了重点,需要将sphinx.ext.autosummarysphinx-apidoc组合使用才能得到所需的结果..?)

1
如果你的项目真的那么简单,我想手动创建所需的RST标记可能比使用sphinx-apidoc更容易。也许这就是你想要的:https://dev59.com/V23Xa4cB1Zd3GeqPjdt0#14621772 - mzjn
1个回答

4

似乎Python 2.7只支持到Sphinx 1.8.6,这意味着它不支持递归。 - Tjaart

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接