Sphinx,使用自动模块查找子模块

Chr*_*ian 27 python-sphinx

使用sphinx的自动模块时(http://sphinx.pocoo.org/ext/autodoc.html#directive-automodule),

我只是写一个.rst文件:

.. automodule:: my_module
    :members:
Run Code Online (Sandbox Code Playgroud)

它记录了my_module,但它没有找到像my_module.inner_module0和my_module.inner_module1这样的内部模块.除了__all__变量之外,是否还需要在__init__.py文件中指定某些内容?

另外,我知道sphinx-apidoc.但是这个命令文件太多了(暴露了每个函数/文件夹,包括未记录的文件).

dev*_*n_s 32

听起来你想给automodule指令一个包名,并将它递归到目录中并记录每个Python模块.这还不支持.您将需要为要记录的每个模块指定完整的虚线模块名称.

例如,给定以下目录结构(来自Python文档).您无法指定.. automodule:: sound.formats并记录目录中的所有模块.您必须指定automodule每个模块的命令:.. automodule:: sound.formats.waveread, .. automodule:: sound.formats.wavewrite,等.

sound/                          Top-level package
      __init__.py               Initialize the sound package
      formats/                  Subpackage for file format conversions
              __init__.py
              wavread.py
              wavwrite.py
              aiffread.py
              aiffwrite.py
              auread.py
              auwrite.py
              ...
      effects/                  Subpackage for sound effects
              __init__.py
              echo.py
              surround.py
              reverse.py
              ...
Run Code Online (Sandbox Code Playgroud)

  • 现在这是一个相当老的答案。仍然存在自动发现的情况吗? (6认同)

Noe*_*rsk 5

在我看来,如果导入这些子模块,现在应该可以使用该:imported-members:选项(非直接链接,使用搜索)__init__.py

但是,我个人(还)无法完成这项工作。

编辑:可能是一个已知的错误