gpt4 book ai didi

python-sphinx - sphinx 构建上的重复索引警告;如何在不索引文件内容的情况下包含文件?

转载 作者:行者123 更新时间:2023-12-04 06:04:33 25 4
gpt4 key购买 nike

我想创建一个 single_html.rst包含我所有 class 的文件/method/attribute/etc... ,但也将分类符号拆分为单独的页面。

例如

single_html.rst

.. single html

.. include:: foo.rst

.. include:: bar.rst

酒吧.rst
.. autoclass:: my.mod.Bar
:members:

第一步
.. autoclass:: my.mod.Foo
:members:

这会抛出多个 duplicate object description错误:

/path/to/project/my/mod.py:docstring of my.module.Bar:0: WARNING: duplicate object description of my.mod.Bar, other instance in /path/to/project/docs/source/api/single_html.rst, use :noindex: for one of them

/path/to/project/my/mod.py:docstring of my.module.Bar:0: WARNING: duplicate object description of my.mod.Foo, other instance in /path/to/project/docs/source/api/single_html.rst, use :noindex: for one of them



我不能简单地放置 :noindex:autoclass::指令,因为这将完全删除所有索引。 (所以要么有重复的索引,要么根本没有!)

有一个更好的方法吗?

最佳答案

您可以通过更改包含文件的扩展名来避免这些警告。

Sphinx 考虑每个 .rst (默认情况下,它可以在 conf.py 文件中更改)作为“要解析的源”文件。所以它会尝试解析 foo.rstbar.rst文件并查找 autodoc my.mod.Foo 的指令和 my.mod.Bar .
当它试图解析 single_html.rst , 它首先包含 foo.rst 的内容和 bar.rst ;因此,它然后再次找到 my.mod.Foo 的指令和 my.mod.Bar .

通过重命名 foo.rstbar.rstfoo.incbar.inc (任何你想要的扩展名),你将阻止 Sphinx 解析包含的文件并避免警告。

关于python-sphinx - sphinx 构建上的重复索引警告;如何在不索引文件内容的情况下包含文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39738852/

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