相关疑难解决方法(0)

Sphinx 的 autodoc 的 automodule 显然没有效果

我在rst包含automodule但似乎没有任何效果的文件上运行 Sphinx 。

以下是详细信息:我有一个 Python 项目,其中agent.py包含一个包含类的文件Agent。我还有一个子目录,里面apidoc有一个文件agent.rst(由 生成sphinx-apidoc):

agent module
============

.. automodule:: agent
   :members:
   :undoc-members:
   :show-inheritance:
Run Code Online (Sandbox Code Playgroud)

sphinx-build -b html apidoc apidoc/_build使用项目目录作为当前工作目录运行 sphinx 。

为了确保找到 Python 文件,我在 中包含了以下内容apidoc/conf.py

agent module
============

.. automodule:: agent
   :members:
   :undoc-members:
   :show-inheritance:
Run Code Online (Sandbox Code Playgroud)

它运行时没有错误,但是当我打开生成的 HTML 文件时,它只显示“代理模块”并且一切都是空白的。为什么不显示类Agent及其成员?

更新:最初的问题很可能是由于我没有包含sphinx.ext.autodocconf.py. 但是,现在我这样做了,我收到了如下警告:

import os
import sys
sys.path.insert(0, os.path.abspath('.'))
Run Code Online (Sandbox Code Playgroud)

python python-sphinx autodoc sphinx-apidoc

4
推荐指数
1
解决办法
1443
查看次数

sphinx-apidoc获取子模块,但autodoc不会记录它们

我一直在研究PyQt5的项目(在这里找到:https://github.com/MaVCArt/StyledPyQt5),它使用包结构使导入更合乎逻辑.到目前为止,我已经相对成功地使用Sphinx记录了代码,至少在我介绍包结构之前.(以前,一切都在一个文件夹中)

以下是问题:当我运行sphinx-apidoc时,一切运行正常,没有错误.更重要的是,autodoc很好地接收了我所有的子模块.这是我的一个文件的内容:

styledpyqt package
==================

Subpackages
-----------

.. toctree::
    :maxdepth: 8

    styledpyqt.core

Submodules
----------

styledpyqt.StyleOptions module
------------------------------

.. automodule:: styledpyqt.StyleOptions
    :members:
    :undoc-members:
    :show-inheritance:

styledpyqt.StyleSheet module
----------------------------

.. automodule:: styledpyqt.StyleSheet
    :members:
    :undoc-members:
    :show-inheritance:


Module contents
---------------

.. automodule:: styledpyqt
    :members:
    :undoc-members:
    :show-inheritance:
Run Code Online (Sandbox Code Playgroud)

如您所知,所有子模块都被拾取.

但是,当我在此运行make html时,这些模块都没有被记录(意味着标题存在,但没有显示任何方法,类或成员).在生成的HTML中,它们只是标题,下面没有任何内容.我知道他们在代码注释中已正确设置,因为代码在现在和包结构的设置之间没有改变,也就是当文档确实有效时.

有没有人有任何想法可能是什么原因?

注意:为了帮助解决这个问题,这里是我的文件夹结构的简短细分:

styledpyqt
+    core
+    +    base
+    +    +    __init__.py ( containing a class definition )
+    +    +    AnimationGroups.py
+    +    +    Animations.py
+    +    __init__.py
+ …
Run Code Online (Sandbox Code Playgroud)

python python-sphinx autodoc

3
推荐指数
1
解决办法
3291
查看次数

标签 统计

autodoc ×2

python ×2

python-sphinx ×2

sphinx-apidoc ×1