得到“扁平”的狮身人面像自动模块的成员输出 [英] Get "flat" member output for sphinx automodule

查看:71
本文介绍了得到“扁平”的狮身人面像自动模块的成员输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sphinx autodoc扩展来对模块进行文档记录,我想在文档输出中获得模块成员的 flat 列表。



我尝试使用以下命令:

  .. automodule :: modname 
:members:

但是,这有两个问题:


  1. 它包括模块的文档字符串,我在这里不需要


  2. 每个条目的名称都以 modname。为前缀,这是完全多余的(因为此页面专门用于记录此模块)


但是,我一直找不到能够使我有选择地禁用这两个方面的配置选项,同时仍然获得所有模块成员的自动列表。



我目前的计划是仅使用自动功能(etc)并明确枚举要记录的成员,但是我仍然想知道是否错过了



更新:我至少找到了第二部分的解决方法:设置 conf.py 中的> add_module_names = False 。不过,这是一个全局设置,因此它并不能真正回答我的原始问题。

解决方案

查看此对类似问题的解答,我发现您可以使用 autodoc-process-docstring 事件可从附加模块中删除文档字符串将以下代码添加到您的 conf.py

  def skip_modules_docstring(app ,什么,名称,obj,选项,行):
如果=='module':
删除行[:]

def setup(app):
app.connect('autodoc-process-docstring',skip_modules_docstring)

请注意<$ c需要$ c> del 语句,因为根据文档,对的修改必须就位(在创建新对象时,它不起作用)。 / p>

最后,您还可以使用 name 过滤仅几个模块的文档字符串,同时保留其他模块的文档字符串。


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:

  1. It includes the module's docstring, which I don't want here.

  2. 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.

解决方案

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 your conf.py:

def skip_modules_docstring(app, what, name, obj, options, lines):
    if what == 'module':
        del lines[:]

def setup(app):
    app.connect('autodoc-process-docstring', skip_modules_docstring)

Note that the del statement is needed because, according to the documentation, the modification to lines 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.

这篇关于得到“扁平”的狮身人面像自动模块的成员输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆