Sphinx autodoc跨存储库的多个子包记录类

2024-10-06 06:47:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Sphinx(1.5.3)为Python repo创建文档,其结构如下:

main_repo/
├── docs
├── src
|   ├── subrepo1
|   ├── subrepo2
|   └── subrepo3
└── tests

Python代码在src中被构造成三个不同的Python包。这里subrepo1只是main_repo的一部分,但是subrepo2和{}是链接到独立Git repo的Git子模块。Sphinx文件位于docs文件夹中:

^{pr2}$

conf.py中,我使用了

sys.path.insert(0, os.path.abspath(os.path.join('path/to/src')))

为了将src目录的完整路径添加到sys.path,并且在index.rst中,我添加了以下指令来为subrepo1包中的一个类生成文档:

.. toctree::
   :maxdepth: 2
   :caption: Contents:

.. automodule:: subrepo1.module

.. autoclass:: Class1
    :members:

这里module是包subrepo1内模块module.py的名称,Class1是{}内的一个类。在

我运行make html时出现以下错误:

/path/to/src/docs/index.rst:13: WARNING: autodoc: failed to import module   u'subrepo1.module'; the module executes module level statement and it might call sys.exit().
/path/to/src/docs/index.rst:15: WARNING: don't know which module to import for autodocumenting u'Class1' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)

我想为所有子模块和子包中的所有类生成文档,包括类构造函数和所有“public”方法和属性,它们位于main_repo内的这三个子存储库中。在index.rst中执行此操作的指令是什么?在


Tags: 模块topath文档srcdocsindexmain