获得“平坦” sphinx automodule 的成员输出
我正在使用 Sphinx autodoc 扩展来记录模块,并且我希望在文档输出中获得模块成员的平面列表。
我尝试使用以下内容:
.. automodule:: modname
:members:
但是,这有两个问题:
它包括模块的文档字符串,我不想要在这里。
每个条目的名称都以“modname.”为前缀,这是完全多余的(因为此页面专门用于记录此模块)
但是,我无法找到任何配置选项来让我有选择地禁用这两个方面,同时仍然获得所有模块成员的自动列表。
我当前的计划是仅使用 autofunction (等)并显式枚举要记录的成员,但我仍然想知道我是否错过了实现我最初想要的东西的简单方法。
更新:我至少找到了第二部分的解决方法:在conf.py
中设置add_module_names=False
。但这是一个全球环境,所以它并不能真正回答我最初的问题。
I'm using the Sphinx autodoc extension to document a module, and I'd like to get a flat list of the module's members in the documentation output.
I tried using the following:
.. automodule:: modname
:members:
However, there are two problems with this:
It includes the module's docstring, which I don't want here.
The name of each entry is prefixed with "modname.", which is completely redundant (since this page is specifically for documenting this module)
However, I haven't been able to find any config options that would let me selectively disable these two aspects while still getting the automatic listing of all of the module members.
My current plan is to just use autofunction (etc) and explicitly enumerate the members to be documented, but I'd still like to know if I missed an easy way to achieve what I originally wanted.
Update: I at least found a workaround for the second part: set add_module_names=False
in conf.py
. That's a global setting though, so it doesn't really answer my original question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看此类似问题的答案,我发现您可以使用
autodoc-process-docstring
事件以删除来自模块的文档字符串将以下代码附加到您的conf.py
:请注意,需要
del
语句,因为根据文档,对lines
的修改code> 必须就地发生(如果你创建一个新对象,它不起作用)。最后,您还可以使用
name
来过滤少数模块的文档字符串,同时保留其他模块的文档字符串。Looking at this answer to a similar question, I've found that you can use the
autodoc-process-docstring
event to remove the docstrings from modules appending the following code to yourconf.py
:Note that the
del
statement is needed because, according to the documentation, the modification tolines
must happend in place (it you create a new object, it doesn't work).Finally, you can also use
name
to filter the docstrings of just a few modules while keeping the ones from others.