Python 在Sphinx自动摘要中使用第一段而不是第一行

Python 在Sphinx自动摘要中使用第一段而不是第一行,python,python-sphinx,Python,Python Sphinx,我正在使用autosummary指令来记录一个类,但是我遇到了autosummary只严格显示autosummary表中docstring的第一行的问题。比如说, .. currentmodule:: logging .. autosummary:: ~Logger.manager ~Logger.root 生成具有以下内容的表: manager There is [under normal circumstances] just one Manager instance, whi

我正在使用autosummary指令来记录一个类,但是我遇到了autosummary只严格显示autosummary表中docstring的第一行的问题。比如说,

.. currentmodule:: logging
.. autosummary::
  ~Logger.manager
  ~Logger.root
生成具有以下内容的表:

manager   There is [under normal circumstances] just one Manager instance, which
root      A root logger is not that different to any other logger, except that

我可以理解为什么这是默认设置,但有没有办法使第一句或第一段显示出来?

您的文档字符串显然来自标准库模块。它们看起来像这样:

class Manager(object):
    """
    There is [under normal circumstances] just one Manager instance, which
    holds the hierarchy of loggers.
    """

这是返回自动摘要字符串()的代码:

doc
是作为行列表的docstring

自动摘要字符串应该是。但是,正则表达式存在以下问题:

  • 在首字母大写后,句子不能包含其他大写字母
  • 句点后应包含空格字符 这意味着正则表达式将不匹配上面的任何docstring。如果模式更改为

    ^([A-Z].*?\.\s?)
    
    然后它将匹配两个文档字符串,完整的第一个句子将出现在输出中。(这可能不是最佳的正则表达式,但至少在这种情况下是有效的。)

    m = re.search(r"^([A-Z][^A-Z]*?\.\s)", " ".join(doc).strip())
    if m:
        summary = m.group(1).strip()
    elif doc:
        summary = doc[0].strip()
    else:
        summary = '':
    
    ^([A-Z].*?\.\s?)