我第一次尝试使用Sphinx来记录我的python项目,但由于某些应自动进行文档处理的模块在html输出中丢失而被卡住了。这是我的目录结构:
├── project1
│ └── lib
│ ├── a.py
│ └── b.py
├── project2
│ └── lib
│ ├── c.py
│ └── d.py
└── docs
├── Makefile
├── build
│ ├── doctrees
│ └── html
└── source
├── conf.py
└── index.rst
在a.py
b.py
c.py
和d.py
中定义了一些类。
为了使狮身人面像正常工作,我专门将以下几行添加到conf.py
中:
sys.path.insert(0, os.path.abspath('../../project1/lib'))
sys.path.insert(0, os.path.abspath('../../project2/lib'))
和index.rst
看起来像这样
Welcome to project1&2's documentation!
=================================
.. toctree::
:maxdepth: 2
:caption: Contents:
project1
==========
lib-a
==============
.. automodule:: a
:members:
lib-b
==============
.. automodule:: b
:members:
project2
==========
lib-c
==============
.. automodule:: c
:members:
lib-d
==============
.. automodule:: d
:members:
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
在html输出中,我仅看到a.py
和d.py
的文档。 b.py
和c.py
中的所有类文档均丢失。我在哪里做错了?还是这是一个错误?非常感谢。
[编辑],当我在html主页底部检查了Indices and tables
时,b
和c
的模块链接在那里,但其文档内容却从主页中丢失了。页面。
[EDIT]很抱歉,我没有将文档字符串直接放在class
名称下,而是将其放在__init__
下。在某种情况下,Sphinx不知何故认为整个课程都没有记录。将类文档字符串移动到class
定义下方之后,所有文档字符串成员都将自动进行文档化。