简体   繁体   English

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

[英]Automatically create a toctree for autodoc classes in Sphinx

I'm looking to increase the documentation in one of my libraries.我希望增加我的一个库中的文档。 I've been using sphinx to help build the documentation and recently started exploring the autodoc extension.我一直在使用 sphinx 来帮助构建文档,最近开始探索 autodoc 扩展。

It seems like in most professional documentation, each class documentation page has a list of all the documented methods with links at the top.似乎在大多数专业文档中,每个类文档页面都有一个所有文档化方法的列表,顶部有链接。 Or, in other words, a toctree at the top with hyperlinks to each of the more in depth method documentation.或者,换句话说,顶部的目录树带有指向每个更深入的方法文档的超链接。

Is there a way to automatically create this toctree for each of the classes being documented with autodoc?有没有办法为每个用 autodoc 记录的类自动创建这个 toctree?

In your conf.py file for sphinx add在 sphinx 的conf.py文件中添加

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

autodoc_default_flags = ['members']
autosummary_generate = True

I put the toctree in my index.rst, and it looks like this:我把 toctree 放在我的 index.rst 中,它看起来像这样:

.. autosummary::
     :toctree: stubs

     Class1
     Class2
     Class3

See this example for the conf.py settings有关 conf.py 设置,请参阅此示例

and this example for an example of the toctree. 这个例子是toctree的一个例子。

Hope that helps!希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM