短縮版
- 走る
sphinx-apidoc -o . mymodule
- コメントを外して変更し
conf.py
ます。この例では、sys.path.insert(0, os.path.abspath('mymodule'))
- 再実行
make html
長い答え
このサンプル モジュールで問題を再現できます。
$cat mymodule/mymodule.py
def fn1():
'''First function'''
pass
def fn2():
'''Second function'''
pass
実行sphinx-quickstart
すると、次のツリーが生成されます。
$tree
.
├── Makefile
├── _build
├── _static
├── _templates
├── conf.py
├── index.rst
├── mymodule
└── mymodule.py
$cat index.rst
.. sphinx example documentation master file, created by
sphinx-quickstart on Mon Mar 30 15:28:37 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
デフォルトでindex.rst
:
Welcome to sphinx example's documentation!
==========================================
Contents:
.. toctree::
:maxdepth: 2
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
make html
この時点で実行しても、 には何も出力されません_build/html/py-modindex.html
。これは、sphinx
すべてのモジュールを記述する .rst ファイルが必要だからです。幸いなことに、 を使用して簡単に作成できsphinx-apidoc -o . mymodule
ます。これにより、mymodule.rst
問題の modindex 問題を修正するためにのみ必要な 2 つの新しいファイルが作成されます。
$head *mod*rst
==> modules.rst <==
mymodule
========
.. toctree::
:maxdepth: 4
mymodule
==> mymodule.rst <==
mymodule module
===============
.. automodule:: mymodule
:members:
:undoc-members:
:show-inheritance:
この時点での実行make html
はまだ機能しません。sys.path.insert
しかし、コメントを外してin で始まる行を変更すると問題が解決しconf.py
ます。
私は:sys.path.insert(0, os.path.abspath('mymodule'))
PS: 追加の警告を回避するには、ファイルの toctree に追加modules
してください。Contents:
index.rst