我正在尝试使用 Sphinx 1.4 和扩展为我的 python 类生成sphinx-apidoc
文档sphinx.ext.autodoc
。
我有很多模块,我希望每个模块只显示类名,而不是类中方法的完整列表(在我的代码中都有文档字符串)。
这是我的conf.py
文件的片段:
sys.path.insert(0, '/blah/sphinx/src')
extensions = ['sphinx.ext.autodoc']
autodoc_member_order = 'bysource'
autodoc_default_flags = ['no-members']
这是一个玩具模块 ( my_module.py
),我用它来了解 Sphinx 的工作原理:
"""
==============
Test my module
==============
"""
def module_function():
"""Here is a module function, let's see if it's in"""
print 'module level'
class TestClass:
"""
Test this class
Here is some more class documentation.
"""
def __init__(self):
"""Here is init"""
self.test = True
def getName(self, inputName):
"""Summary for getName
more documentation for getName
"""
print "hello"
return inputName
我只显示这个类的代码,以防我需要在我丢失的文档字符串中做一些事情。
我运行 sphinx-apidoc 来生成 rst 文件:
sphinx-apidoc -f -M -e -o docs/ /blah/sphinx/src/
然后构建:
制作html
我可能不清楚autodoc_default_flags
应该做什么。我认为当您在设置了这些标志的情况下运行 sphinx-apidoc 时,这些标志将应用于 .rst 文件中的指令。但是,在我运行 sphinx-apidoc 之后,我得到了这个 .rst 文件:
my_module module
=====================
.. automodule:: my_module
:members:
:undoc-members:
:show-inheritance:
由于设置了这些标志,我没想到:members:
会被应用,但它确实存在!并且 html 页面具有完整的方法及其文档字符串。
FWIW,autodoc_member_order
正在工作;我可以设置它来切换方法出现的顺序。
所以我的问题:
- 应该做我
autodoc_default_flags
所描述的还是我误解了它? - 如果它可以用来自动隐藏构建中的成员,我是否正确使用它?如果是这样,关于为什么我仍然被
:members:
添加到 .rst 文件中的任何想法? - 如果我误解了它,那么它到底有什么作用?以及如何自动从我的构建中隐藏方法文档字符串?
理想情况下,我想要像 SciPy 这样的东西,例如这里:
http://docs.scipy.org/doc/scipy/reference/cluster.hierarchy.html
为此,我正在玩拿破仑和 sphinx.ext.autosummary 扩展,但似乎只有 apidoc 应该能够隐藏类方法文档。