Skip to main content
 首页 » 编程设计

python之使用 numpy 样式格式的 Sphinx 忽略的部分

2025年05月04日10pander-it

我正在尝试从我的模块中提取文档字符串并构建一个不错的文档。所以我在这里使用 Sphinx,但我不知道出了什么问题。

我的类文档字符串,在 _meta 文件中:

class MasterBlock(object): 
    """ 
    Main class for block architecture. All blocks should inherit this class.     
 
    Methods 
    ------- 
    main() 
        Override it to define the main function of this block. 
    add_input(Link object) 
        Add a Link object as input. 
    add_output(Link object) 
        Add a Link as output. 
    start() 
        Start the main() method as a Process. 
    stop() 
        Stops the process. 
    """ 

我的 .rst :

Meta 
========================== 
 
.. automodule:: crappy.blocks._meta 
    :members: 
    :undoc-members: 
    :show-inheritance: 

我的 Sphinx 配置文件(我更改的部分):

autoclass_content = 'both' 
extensions = ['sphinx.ext.autodoc','sphinx.ext.napoleon'] 
napoleon_numpy_docstring = True 

当我尝试 make html 时,它可以工作(此模块没有错误),但它不显示“方法”部分。如果我在文档字符串中删除它,它与 html 的唯一区别是下面列出的方法不再是链接。

我错过了什么?

请您参考如下方法:

您应该尝试使用 numpydoc Sphinx extension .一旦你安装了它,你只需将它包含在你的 Sphinx 扩展列表中:

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon', 'numpydoc'] 

在 conf.py 中,您可以访问以下选项:

  • numpydoc_show_class_members: bool

    Whether to show all members of a class in the Methods and Attributes sections automatically. True by default.

  • numpydoc_show_inherited_class_members: bool

    Whether to show all inherited members of a class in the Methods and Attributes sections automatically. If it's false, inherited members won't shown. True by default.

  • numpydoc_class_members_toctree: bool

    Whether to create a Sphinx table of contents for the lists of class methods and attributes. If a table of contents is made, Sphinx expects each entry to have a separate page. True by default.