使用Sphinx自动记录Python

2024-05-12 05:31:07 发布

您现在位置:Python中文网/ 问答频道 /正文

这是previous question regarding Sphinx的通用版本。

有没有办法递归地自动记录包含类和函数的模块或包?

我认为为每个函数添加autofunctionautomodule指令是愚蠢的;必须有一种方法使过程自动化,否则我根本看不到使用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.

Tags: 方法函数版本sphinxmethodquestion办法seg
4条回答

艾蒂安的剧本,在他的回答中提到,现在已经融入斯芬克斯作为斯芬克斯阿皮多克。它正是操作人员想要的。它将在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>.

我们用

.. automodule:: module
   :members:

为了简化操作,您可以使用此脚本(查看页面底部的最新版本): http://bitbucket.org/birkenfeld/sphinx/issue/98/add-the-autogenerate-script-to-sphinx

这个脚本将解析您的包/模块,并生成从docstrings构建doc所需的所有rest文件。

我是这个剧本的原作者。

更新

这个脚本现在是Sphinx 1.1的一部分,即apidoc

为了简化操作,您可以使用此脚本(查看页面底部的最新版本): http://bitbucket.org/birkenfeld/sphinx/issue/98/add-the-autogenerate-script-to-sphinx

这个脚本将解析您的包/模块,并生成从docstring构建doc所需的所有rest文件。

我是这个剧本的原作者。

更新

这个脚本现在是Sphinx 1.1的一部分,即apidoc

相关问题 更多 >