【发布时间】:2014-08-28 12:53:43
【问题描述】:
我正在尝试用 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 时,我看不到任何文档。
【问题讨论】:
-
您只有一个顶级 index.rst 文件,但没有别的。这还不够。您需要运行 sphinx-apidoc 来生成所需的 .rst 源(或“手动”创建它们)。
-
Sphinx 需要带有
automodule或autoclass等指令的 .rst 文件才能生成 API 文档。没有它,它不会从来源中提取。也许您希望 Sphinx 像 Epydoc 或 Doxygen 一样工作,但事实并非如此。另请参阅以下答案:stackoverflow.com/a/2441159/407651、stackoverflow.com/a/6109098/407651。 -
刚刚用PyCharm写了一个完整的工作示例,可以用来启发。 stackoverflow.com/a/46362065/1980180
标签: python package python-sphinx sphinx-apidoc