首页 > 解决方案 > Sphinx 文档,自动模块的“缩短路径”

问题描述

我目前有一个看起来像这样的项目,我想使用Sphinx 文档来记录功能。这是它的结构:

+ project
|
+- docs
|
+- app -+- orange  -+- routers -+- files (.py)
             |                  |
           other apps           +- helpers -+- util.py
            ...

我想记录没有app.orange.routers.

例如,我有一个名为test.pyin的文件app/orange/routers,它有一个clear()函数。我想记录test.clear()而不是app.orange.routers.test.clear().

我试图放入sys.path.insert(0, os.path.abspath('../app/orange/routers'))conf.py文件test.rst看起来像这样。

Test
====

.. automodule:: test
   :members:
   :undoc-members:
   :show-inheritance:

有些文件可以记录,但其中一些不能,我意识到它们的区别是那些无法记录的文件具有与导入相关的类似代码,例如from .helpers.util import *,收到的警告如下所示:

WARNING: autodoc: failed to import module 'test'; the following exception was raised:
attempted relative import with no known parent package

我试图将test.rst文件中的自动模块更改为.. automodule:: app.orange.routers.test并且它可以工作,但这不是我想要的。

帮助表示赞赏!

标签: pythondocumentationpython-sphinxautodoc

解决方案


推荐阅读