我正在使用Sphinx自动汇总指令来记录一个类,但是我遇到了这样的问题:自动汇总只严格显示自动汇总表中文档字符串的第一行。例如,
.. 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我可以理解为什么这是默认的,但是有没有办法让它显示第一句话或第一段呢?
发布于 2012-06-04 02:39:35
您的文档字符串显然来自标准库logging模块。它们看起来像这样:
class Manager(object):
"""
There is [under normal circumstances] just one Manager instance, which
holds the hierarchy of loggers.
"""和
class RootLogger(Logger):
"""
A root logger is not that different to any other logger, except that
it must have a logging level and there is only one instance of it in
the hierarchy.
"""这是返回自动汇总字符串(autosummary/__init__.py)的代码:
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 = '':doc是行列表形式的文档字符串。
自动汇总字符串应该是the first sentence of the docstring。但是,正则表达式存在一些问题:
这意味着正则表达式不会与上面的任何文档字符串匹配。如果模式更改为
^([A-Z].*?\.\s?)然后,它将匹配两个文档字符串,并且完整的第一个句子将出现在输出中。(这可能不是最优的正则表达式,但至少在这种情况下它可以工作。)
https://stackoverflow.com/questions/10718846
复制相似问题