gpt4 book ai didi

python-sphinx - Sphinx 自定义 autoclass 输出

转载 作者:行者123 更新时间:2023-12-01 02:27:59 27 4
gpt4 key购买 nike

我有一个包含几个类的模块。目前我正在使用..automodule记录模块。我希望每个类都有自己的带有类名的标题部分。我可以通过替换 ..automodule foo 来实现这一点和:

Bar
===

..autoclass foo.Bar

Baz
===

..autoclass foo.Baz

...

但是,这需要我手动列出我为其执行此操作的每个模块中的每个类。自定义 automodule 生成的内容的最佳方法是什么?

最佳答案

Sphinx 不像 Epydoc 或 Doxygen 那样直接用于从源代码生成 API 文档。这是一种不同的工具。

Sphinx 适用于 .rst (reStructuredText) 文件,如果您希望每个类都有自己的标题和类名,您必须自己添加标题并使用 .. autoclass:: .仅使用 .. automodule:: 是无法做到的.是的,这很不方便(表达了类似的情绪 here )。另见 this answerthis answer .

该问题可以通过遍历 Python 代码并生成 .rst 输出的脚本来缓解。 Sphinx 已经自带了这样的脚本,sphinx-apidoc .但是,它不会产生任何 .. autoclass::指令,仅 .. automodule:: .

这是另一个可以输出.. autoclass::的脚本: https://github.com/PyMVPA/PyMVPA/blob/master/tools/apigen.py .也许你可以使用它。

关于python-sphinx - Sphinx 自定义 autoclass 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14903111/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com