2012-05-23 28 views
3

我正在使用Sphinx autosummary指令來記錄一個類,但我遇到的問題是自動摘要僅嚴格顯示自動摘要表中docstring的第一行。例如,在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 

我可以理解爲什麼這是默認的,但有沒有辦法讓這個第一句或第一段是顯示?

回答

2

您的文檔顯然來自標準庫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。但是,正則表達式存在問題:

  1. 在初始大寫字母后面,句子不能包含其他大寫字母。
  2. 期間後期望有空格字符。

這意味着正則表達式不會與上述任何文檔字符串匹配。如果模式更改爲

^([A-Z].*?\.\s?) 

那麼它將匹配兩個文檔字符串,並且完整的第一句將出現在輸出中。 (這可能不是最佳的正則表達式,但至少它在這種情況下起作用。)

相關問題