我想在Python中記錄一個包。目前,我有以下目錄結構:如何使用Sphinx文檔Python包
.
└── project
├── _build
│ ├── doctrees
│ └── html
│ ├── _sources
│ └── _static
├── conf.py
├── index.rst
├── __init__.py
├── make.bat
├── Makefile
├── mod1
│ ├── foo.py
│ └── __init__.py
├── mod2
│ ├── bar.py
│ └── __init__.py
├── _static
└── _templates
這棵樹是sphinx-quickstart
發射的結果。在conf.py
我沒有註釋sys.path.insert(0, os.path.abspath('.'))
和我有extensions = ['sphinx.ext.autodoc']
。
我index.rst
是:
.. FooBar documentation master file, created by
sphinx-quickstart on Thu Aug 28 14:22:57 2014.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to FooBar's documentation!
==================================
Contents:
.. toctree::
:maxdepth: 2
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
在所有__init__.py
的我有一個文檔字符串和同去的模塊foo.py
和bar.py
。但是,在項目中運行make html
時,我沒有看到任何docstings。
你有一個單一的頂級index.rst文件,但沒有別的。這還不夠。您需要運行[sphinx-apidoc](http://sphinx-doc.org/man/sphinx-apidoc.html)來生成所需的.rst資源(或者「手工創建」它們)。 – mzjn 2014-08-28 13:10:40
@mzjn你能詳細點嗎?我應該在哪個目錄中調用'sphinx-apidoc'? 'sphinx'不會自動查看源代碼? – Dror 2014-08-28 13:20:32
爲了生成API文檔,Sphinx需要帶有像automodule或autoclass這樣的指令的.rst文件。它沒有從源頭中提取。也許你期望Sphinx像Epydoc或Doxygen一樣工作,但事實並非如此。另請參閱以下答案:http://stackoverflow.com/a/2441159/407651,http://stackoverflow.com/a/6109098/407651。 – mzjn 2014-08-28 13:28:12