我正在尝试使用Sphinx自动生成我的代码库的基本文档。然而,我很难指示Sphinx递归地扫描我的文件。
我的Python代码库具有以下文件夹结构:
<workspace>
└── src
└── mypackage
├── __init__.py
│
├── subpackageA
│ ├── __init__.py
│ ├── submoduleA1
│ └── submoduleA2
│
└── subpackageB
├── __init__.py
├── submoduleB1
└── submoduleB2
我在<workspace>
中运行了sphinx-quickstart命令,现在我的结构看起来像:
<workspace>
├── src
│ └── mypackage
│ ├── __init__.py
│ │
│ ├── subpackageA
│ │ ├── __init__.py
│ │ ├── submoduleA1
│ │ └── submoduleA2
│ │
│ └── subpackageB
│ ├── __init__.py
│ ├── submoduleB1
│ └── ubmoduleB2
│
├── index.rst
├── _build
├── _static
└── _templates
我阅读了 快速入门教程,虽然我仍在尝试理解文档,但它所表达的方式使我担心Sphinx假定我将为我的代码库中的每个单独的模块/类/函数手动创建文档文件。
然而,我注意到了“automodule”语句,并在快速入门期间启用了autodoc,因此我希望大部分文档可以自动生成。我修改了我的conf.py文件以添加我的src文件夹到sys.path,然后修改了我的index.rst以使用automodule。所以现在我的index.rst看起来像:
Contents:
.. toctree::
:maxdepth: 2
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. automodule:: alphabuyer
:members:
我有许多类和函数在子包中定义。然而,当我运行:
sphinx-build -b html . ./_build
它报告如下:
updating environment: 1 added, 0 changed, 0 removed
看起来它未能导入包内的任何内容。查看生成的 index.html,"Contents:" 旁边什么也没有显示。Index 页面只显示 "mypackage (module)",但点击它后也没有任何内容。
您如何指示 Sphinx 递归解析一个包并自动为遇到的每个类/方法/函数生成文档,而无需手动列出每个类?
sphinx-apidoc
之前,通常会使用sphinx-quickstart
生成index.rst
和modules.rst
文件。但是你也可以通过使用-F
或-full
标志仅使用sphinx-apidoc
来生成这些文件。该标志将在生成的文件中包含完整的文档内容。 - bad_coder