使用Sphinx为每个函数自动生成单独的文档

Joe*_*oel 7 python python-sphinx read-the-docs

我一直在构建一个具有许多不同功能的Python模块.

我正在使用Sphinx和readthedocs来提供文档.我已经取得了不错的进展,但目前我有一个庞大的页面,提供了我所有功能的文档(按字母顺序排列).

我查看了其他项目,每个项目都有一个单独的页面.通过查看源代码,我发现为每个文件创建了一个单独的.rst文件.我假设这是自动完成的,这个关于生成autodoc摘要的页面似乎正在描述其中的一些,但我无法理解它.

sphinx-apidoc 有一个选项(-e)为每个模块创建一个页面,但我想为每个函数创建一个页面.

如何使用Sphinx为每个函数自动生成单独的页面?


附加信息

要为下面的其中一个答案添加信息,我将以下内容放入我的EoN.rst文件中,该文件位于子目录中docs.

EON documentation
=================

.. automodule:: ../EoN
   :members:

.. currentmodule:: ../EoN

.. autosummary::
   :toctree: functions

   fast_SIR
   fast_SIS
Run Code Online (Sandbox Code Playgroud)

我收到错误消息

$ sphinx-autogen -o docs/generated docs/*.rst
Run Code Online (Sandbox Code Playgroud)

[autosummary]生成autosummary:docs/index.rst,docs/methods.rst,docs/quickstart.rst

[autosummary]写入docs/generated

警告:[autosummary]无法导入u'fast_SIR':没有名为fast_SIR的模块

警告:[autosummary]无法导入u'fast_SIS':没有名为fast_SIS的模块

fast_SISfast_SIR坐在里面../EoN.py

ast*_*rog 6

我认为sphinx-automodapi Sphinx扩展可能会满足您的需求。实质上,要记录模块,您只需执行以下操作:

.. automodapi:: mypackage.mymodule
Run Code Online (Sandbox Code Playgroud)

它将为每个函数生成表格和单个页面。

免责声明:我是sphinx-automodapi的作者


mzj*_*zjn 5

使用带有“autodoc”的 sphinx 按类排序显示的答案中它解释了如何使用每班一个页面生成类的文档,使用自动摘要autosummary_generate=True

这种机制也适用于函数。使用这样的东西:

EoN API documentation
=====================

.. currentmodule:: EoN

.. autosummary::
   :toctree: functions

   my_function1
   my_function2
   my_function3
   ...
Run Code Online (Sandbox Code Playgroud)

您必须枚举autosummary指令中的每个函数,但会自动生成相应的 *.rst 文件(在functions子目录中)。