python - 在 Sphinx 中自动为 autodoc 类创建目录树

标签 python python-sphinx autodoc toctree

我希望增加我的一个库中的文档。我一直在使用 sphinx 来帮助构建文档,最近开始探索 autodoc 扩展。

似乎在大多数专业文档中,每个类文档页面都有一个所有文档化方法的列表,顶部有链接。或者,换句话说,顶部的目录树带有指向每个更深入的方法文档的超链接。

有没有办法为使用 autodoc 记录的每个类自动创建此 toctree?

最佳答案

在你的 conf.py 文件中为 sphinx 添加

extensions = ['sphinx.ext.autosummary',]
# NOTE: Don't overwrite your old extension list! Just add to it!

autodoc_default_flags = ['members']
autosummary_generate = True

我把 toctree 放在我的 index.rst 中,它看起来像这样:

.. autosummary::
     :toctree: stubs

     Class1
     Class2
     Class3

参见 this example对于 conf.py 设置

this example以 toctree 为例。

希望对您有所帮助!

关于python - 在 Sphinx 中自动为 autodoc 类创建目录树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34557716/

相关文章:

python - 制作sphinx autodoc时如何忽略python项目中的 'src'目录

python - 多热标签编码

python - 如何使用 Python 在 Gtk3 中显示 png 图像?

python 模块导入难题(来自子模块的模块)

python - 狮身人面像快速启动失败

python - Sphinx meth 角色不创建链接

python - 用于打印日期的 django 时区

python - Autodoc 在本地工作,但不在 ReadTheDocs 上

python - Sphinx autodoc 找不到模块

python - 如何使用 autodoc 覆盖 Sphinx 中的构造函数参数?