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

MaV*_*Art 3 python python-sphinx 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
+    +    Color.py
+    +    Float.py
+    +    Gradient.py
+    +    Int.py
+    +    String.py
+    __init__.py
+    StyleOptions.py
+    StyleSheet.py
Run Code Online (Sandbox Code Playgroud)

MaV*_*Art 6

我最终最终修复了这个问题 - 似乎我忽略了一些错误,而且sphinx工作得很好.我在conf.py中添加了包中包含的所有路径,它只是从那里开始工作:

conf.py:

sys.path.insert(0, os.path.abspath('../StyledPyQt5'))
sys.path.insert(0, os.path.abspath('../StyledPyQt5/styledpyqt'))
sys.path.insert(0, os.path.abspath('../StyledPyQt5/styledpyqt/core'))
sys.path.insert(0, os.path.abspath('../StyledPyQt5/styledpyqt/core/base'))
Run Code Online (Sandbox Code Playgroud)

一切顺利.

这里需要注意的是,我在与代码不同的目录中生成文档非常重要.如果您使用sphinx-apidoc生成.rst文件,并且您正在使用gh-pages分支来获取像我这样的文档,请不要忘记在主分支上单独生成HTML页面.否则,将不会有任何代码来源.我的工作流现在看起来像这样:

  1. 通过运行确保我在主分支上 git checkout master
  2. run sphinx-apidoc -F -P -o ..output_dir ..source_dir,其中output_dir与source_dir不同.
  3. 运行make html,确保_build/html位于我的repo的任一分支中的目录中.
  4. 运行git checkout gh-pages切换到我的gh-pages分支,删除代码文件并用html文档页面替换它们.
  5. 将_build/html中所有新生成的HTML文件复制到gh-pages主文件夹,覆盖任何更改.
  6. 运行git commit -am "Docs Update" gh-pages以提交更改
  7. 运行git push origin gh-pages以将提交推送到github
  8. 跑去git checkout master让我回到主分公司

我知道有十几个教程在那里记录这个,但我希望这个小细节可能在某些时候帮助某人.