3

Sphinx 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

これがデフォルトの理由は理解できますが、最初の文または最初の段落が表示されるようにする方法はありますか?

4

1 に答える 1

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行のリストとしてのdocstringです。

autosummary 文字列は、docstring の最初の文であると想定されています。ただし、正規表現には次のような問題があります。

  1. 最初の大文字の後に、文に追加の大文字を含めることはできません。
  2. ピリオドの後には空白文字が必要です。

これは、正規表現が上記のドキュメント文字列のいずれとも一致しないことを意味します。パターンを次のように変更した場合

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

両方の docstring に一致し、完全な最初の文が出力に表示されます。(これは最適な正規表現ではないかもしれませんが、少なくともこの場合は機能します。)

于 2012-06-03T18:39:35.297 に答える