2013-12-11 22 views
2

我在使用autodoc指令生成项目文档的Sphinx中引入了我的Python包类和方法中有大量的文档字符串。如何在Sphinx中为条件包含标记文档字符串?

某些外部(不以下划线开头)方法是API方法,应该出现在用户文档中。其他人是外部的,因为他们需要从另一个模块调用,但组成了一个内部 API。这些不应该出现在用户文档中。

到目前为止,我已经使用:members:参数手动区分内部API方法中的用户API方法。事实证明,当我添加新方法时容易出错,我想在文档字符串中指出方法是否应出现在用户API文档中。

有没有一种方法可以“标记”文档字符串或类似的东西直接出现在源代码中,以表明它应该出现在用户API文档中?

回答

2

看起来像要从autodoc中排除成员?

.. automodule:: yourmodule 
    :inherited-members:  # include inherited functions 
    :special-members:   # include __functions__ 
    :private-members:   # include _functions and __functions 
    :members:     # include all other documented functions 
    :undoc-members:   # include even undocumented functions 
    :exclude-members: f_1, f_2 # exclude certain members 

为了更编程摸出condional文档,你会编辑conf.py文件并覆盖插槽车博士跳过成员一样解释here

def skip(app, what, name, obj, skip, options): 
    return name in ["exclude1", "exclude2", "exclude3"] 

def setup(app): 
    app.connect("autodoc-skip-member", skip) 
相关问题