【问题标题】:PyQt 4 import in read-the-docsPyQt 4 导入阅读文档
【发布时间】:2016-03-29 12:06:47
【问题描述】:

我目前正在通过 read-the-docs 在线获取我的代码文档,但是,让 read-the-docs 处理我的 PyQt4 依赖模块似乎有问题。

我的项目结构如下:

pkg
pkg/__init__.py
pkg/modules/
pkg/modules/__init__.py
pkg/modules/somemodules.py
pkg/gui/__init__.py
pkg/gui/someGUImodules.py

我正在使用 sphinx-autodoc 来构建不同模块的文档字符串的 html 表示。但是,在我的本地机器上一切正常,因为我需要在阅读文档时使用mock PyQt4,我遇到了以下问题:在我的一个 GUI 类中,我通过子类化 QtGui.QDialog

class listSelectorDialog(QtGui.QDialog):

    def __init__(self,parent,List):
        super(listSelectorDialog,self).__init__(parent)  

listSelectorDialog通过

class advancedListSelectorDialog(listSelectorDialog):

    def __init__(self,parent,List):
        super(advancedListSelectorDialog,self).__init__(parent,List)

Mocking QtGui 会导致 read-the-docs 告诉我:

class advancedListSelectorDialog(listSelectorDialog):
TypeError: Error when calling the metaclass bases
str() takes at most 1 argument (3 given)   

因此崩溃。我试图通过选择将我的包构建到虚拟环境中 使用 setup.py install 在 vi​​rtualenv 中安装您的项目 然而,事实证明,即使 PyQt4 在 pip 中列出,您也无法安装它,请参阅 https://superuser.com/questions/679298/how-to-install-pyqt4-and-what-are-the-practical-differences-between-pyqt4-and-py

到目前为止,我发现的唯一解决方法是,如果环境是 RTD,则不加载 GUI 模块并省略 GUI 模块的文档,但这不应该是最终解决方案。谢谢。

【问题讨论】:

  • 在尝试继承 Qt 模块时出现完全相同的问题 - 成功了吗?
  • 不幸的是,决定暂时不记录 GUI 模块。当我有一些额外的时间时,我会试着弄清楚。

标签: python-2.7 pyqt4 python-sphinx read-the-docs


【解决方案1】:

我在 PyQt5/py3 上遇到了类似的问题(与 MagickMock 的元类冲突)。我的解决方法是手动模拟 conf.py 中的模块,而不是使用 unittest.mock:

class PyQt5:
    @staticmethod
    def qVersion():
        return '5.0.0'
    class QtCore:
        class QObject:
            pass
    # etc...
sys.modules['PyQt5'] = PyQt5

这使得导入/元类冲突问题消失。不幸的是,尽管构建通过了,但 autodoc 仍然不起作用(没有输出)...

当然很乏味。

【讨论】:

    猜你喜欢
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 2013-12-24
    • 2013-02-26
    相关资源
    最近更新 更多