我想在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