10

クラスのない関数 (lib.py) を含む python ファイルがあります。各関数には次のスタイルがあります。

def fnc1(a,b,c):
    '''
    This fonction does something.

    :param a: lalala
    :type a: str
    :param b: hahaha
    :type b: int
    :param c: hohoho
    :type c: int

    :rtype: int

    '''

    print a
    d = b + c

    return d

Sphinx を使用して各関数 (入力と出力) を文書化したいだけです。

sphinx-quickstartを実行した後、 lib.pyを使用して conf.pyにパスを定義しました。しかし、出力 HTML ファイル (ようこそページ) は空です。

index.rstに自分自身を書いた場合:

.. function:: func1(a,b,c)
    This fonction does something.

    :param a: lalala
    :type a: str
    :param b: hahaha
    :type b: int
    :param c: hohoho
    :type c: int
    :rtype: int

html ファイルに入力と出力が表示されます。しかし、それを自動的に行う方法は?

通常、 sphinx-apidoc -oを実行した後にlib.rstで実行する必要があると思いますが、lib.rstには次のようなものしかありません。

lib module
==================

.. automodule:: lib
    :members:
    :undoc-members:
    :show-inheritance:

誰かが私が正確に何をしなければならないかを段階的に説明できますか?

4

1 に答える 1

17

まず、 sphinx-quickstartを実行するときは、必ずautodocを選択してください:

autodoc: automatically insert docstrings from modules (y/N) [n]: y

次に、生成されたindex.rstにモジュールを追加して、すべてのモジュールを自動的に含めます (識別を監視します)。

.. toctree::
   :maxdepth: 4

   modules

このsphinx-apidoc -o の後、ドキュメントが生成されます。

組み込みシステムで使用される Python コードに Sphinx を使用するためのガイドを書きましたが、ガイドの最初のステップはあなたにも役立つかもしれません。

組み込みシステムで実行されている Python コードの sphinx ドキュメントを生成する方法

[編集]

ここに段階的なリストがあります:

  1. lib.py を作成する
  2. ドキュメント フォルダを作成します。mkdir doc

    ├── doc/
    └── lib.py
    
  3. doc/ を入力してください:cd doc
  4. 実行sphinx-quickstart (必ず 、 をautodoc: y選択Makefile: y
  5. conf.py を編集してsys.pathを指定します。sys.path.insert(0, os.path.abspath('..'))
  6. index.rst を編集し、toctree でモジュールを指定します。

    .. toctree::
        :maxdepth: 2
    
        modules
    
  7. 実行するsphinx-apidoc -o . ..
  8. HTML 出力を生成します。make html
  9. ドキュメントを表示します。firefox _build/html/index.html
于 2013-12-03T15:36:17.183 に答える