【问题标题】:Sphinx, using automodule to find submodulesSphinx,使用自动模块查找子模块
【发布时间】:2012-07-16 16:12:41
【问题描述】:

使用 sphinx 的自动模块 (https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) 时,

我只是写在一个 .rst 文件中:

.. automodule:: my_module
    :members:

它很好地记录了 my_module,但它没有找到像 my_module.inner_module0 和 my_module.inner_module1 这样的内部模块。 __init__.py 文件中除了 __all__ 变量还有什么需要指定的吗?

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

【问题讨论】:

    标签: python-sphinx


    【解决方案1】:

    听起来你想给 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
                  ...
    

    【讨论】:

    • 这是一个很老的答案了。还是没有自动发现吗?
    • @naught101 见sphinx-apidocsphinx-autogen
    • @naught101 特别是这个related thread 可能很有趣。
    【解决方案2】:

    在我看来,using the :imported-members: option(非直接链接,请使用搜索)现在应该是可能的,如果 __init__.py 导入这些子模块。

    但是,我个人还不能完成这项工作。

    编辑:可能是known bug

    【讨论】:

    • 我不认为使用imported-members 可以解决这个问题。恕我直言,@devin_s 高度赞成的答案是正确的答案(或至少在正确的轨道上)。自 2013 年 8 月以来,提问者一直没有在 Stack Overflow 上活跃,因此我们似乎不太可能得到他的确认。
    • True...重新阅读问题,似乎我误解了它,通过我自己的任务的镜头进行解释。抱歉打扰了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多