我相信这在某种程度上是用户错误,但我正在慢慢地疯狂,真的很需要帮助。
我已经成功使用了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.autosummary
和sphinx-apidoc
组合使用才能得到所需的结果..?)