使用 Sphinx 自动记录 Python
有没有一种方法可以递归地自动记录其中包含类和函数的模块或包?
我认为为每个函数添加 autofunction
或 automodule
指令是愚蠢的;必须有一种方法来自动化该过程,否则我根本看不到使用 Sphinx 的意义。
澄清: 而不是: ,这需要我手动剪切和粘贴所有方法名称并相应地更新文档。
.. 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.
This is a generalized version of a previous question regarding Sphinx.
Is there a way to recursively autodocument modules or packages which contain classes and functions within them?
I think it is silly to add the autofunction
or automodule
directive for each function; There must be a way to automate the process, otherwise I don't see the point of using Sphinx at all.
Clarification:
Instead of :
.. automodule:: segments.segments
.. autoclass:: segments.segments.Seg
.. automethod:: Seg.method_1
.. automethod:: Seg.method_2
.. automethod:: Seg.method_3
.......
.. automethod:: Seg.method_n
Which requires me to manually cut-and-paste all method names and update the documentation correspondingly, I want to have a command like:
.. automodule:: segments.segments
.. autoclass:: segments.segments.Seg
.. MAGIC COMMAND: Automatically print the docstrings and signatures
of all Seg() methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为了使事情变得更容易,您可以使用此脚本(查看页面底部的最新版本):
http://bitbucket.org/birkenfeld/ sphinx/issue/98/add-the-autogenerate-script-to-sphinx
该脚本将解析您的包/模块并生成从文档字符串构建文档所需的所有其余文件。
我是这个剧本的原作者。
更新
此脚本现在是 Sphinx 1.1 的一部分,作为 apidoc。
To make things easier you can use this script (look at the bottom of the page for the last version):
http://bitbucket.org/birkenfeld/sphinx/issue/98/add-the-autogenerate-script-to-sphinx
This script will parse your packages/modules and generate all the rest files necessary to build the doc from docstrings.
I'm the original author of this script.
UPDATE
This script is now part of Sphinx 1.1 as apidoc.
Etienne 在他的回答中提到的脚本现已作为 sphinx-apidoc 集成到 Sphinx 中。它正是 OP 想要的。它预计在 Sphinx 1.1 中发布,或者可以从 Hg 存储库中获取:
https://bitbucket.org/birkenfeld/ sphinx
它对我来说效果很好。文档如下:
Etienne's script, mentioned in his answer, has now been integrated into Sphinx as sphinx-apidoc. It does exactly what the OP wants. It is slated for release in Sphinx 1.1, or is available from the Hg repo:
https://bitbucket.org/birkenfeld/sphinx
It works beautifully for me. The docs read thus:
我建议使用 Epydoc,它专门用于从文档字符串生成文档。
I would suggest Epydoc, which is specialized at generating documentation from docstrings.
您希望它比仅仅指定 automodule 更简单吗?即使对于大型库,输入所有模块名称也需要 5 分钟的工作量。
这样做的原因是 Sphinx 很难猜测需要记录什么。
您还可以编写 autopackage,它将搜索模块并使用 automodule 指令(如果 automodule 尚未执行此操作)。
You want it more simpler than just specifing automodule? Even for a large library, it's 5min amount of work to type all the module names.
The reason of doing so is because Sphinx hardly guesses what needs to be documented.
You could also write autopackage, that would search for modules and use automodule directive (if automodule does not do that already).
我们使用
We use