我正在尝试记录一个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
命令后,我看不到任何文档字符串。
automodule
或autoclass
)的.rst文件才能生成API文档。如果没有这些指令,它就无法从源代码中提取信息。也许您期望Sphinx像Epydoc或Doxygen一样工作,但实际上并非如此。请参阅以下答案:https://dev59.com/y3E95IYBdhLWcg3wI6bt#2441159,https://dev59.com/YG025IYBdhLWcg3wRTxK#6109098。 - mzjn