这是previous question regarding Sphinx的通用版本。
有没有一种方法可以递归地自动创建包含类和函数的模块或包?
我认为为每个函数添加autofunction
或automodule
指令是愚蠢的;必须有一种方法来自动化这个过程,否则我根本看不到使用Sphinx的意义。
Clarification:而不是:
.. automodule:: segments.segments
.. autoclass:: segments.segments.Seg
.. automethod:: Seg.method_1
.. automethod:: Seg.method_2
.. automethod:: Seg.method_3
.......
.. automethod:: Seg.method_n
这需要我手动剪切和粘贴所有方法名称,并相应地更新文档,我希望有一个命令,如下所示:
.. automodule:: segments.segments
.. autoclass:: segments.segments.Seg
.. MAGIC COMMAND: Automatically print the docstrings and signatures
of all Seg() methods.
发布于 2009-08-25 13:26:39
我们使用
.. automodule:: module
:members:
发布于 2009-08-25 14:37:37
为了简单起见,您可以使用这个脚本(查看页面底部的最新版本):http://bitbucket.org/birkenfeld/sphinx/issue/98/add-the-autogenerate-script-to-sphinx
此脚本将解析您的包/模块,并生成从文档字符串构建文档所需的所有rest文件。
我是这个脚本的原始作者。
更新
此脚本现在作为成为Sphinx1.1的一部分。
发布于 2011-02-28 19:22:50
Etienne的脚本,在他的回答中提到,现在已经作为sphinx-apidoc集成到了Sphinx中。它做的正是操作员想要的。它计划在Sphinx 1.1中发布,或者可以从Hg repo获得:
https://bitbucket.org/birkenfeld/sphinx
它对我来说效果很好。文档是这样写的:
> sphinx-apidoc --help
Usage: sphinx-apidoc-script.py [options] -o <output_path> <module_path>
[exclude_paths, ...]
Look recursively in <module_path> for Python modules and packages and create
a reST file with automodule directives per package in the <output_path>.
https://stackoverflow.com/questions/1328041
复制相似问题