PyQt 4 在阅读文档中导入 [英] PyQt 4 import in read-the-docs

查看:39
本文介绍了PyQt 4 在阅读文档中导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am currently in the process of getting the documentation of my code online via read-the-docs, however, getting read-the-docs to process my PyQt4 dependent modules seems problematic.

我的项目具有以下结构:

My project has the following structure:

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 表示.然而,在我的本地机器上一切正常,因为我需要在 read-the-docs 上 mock PyQt4,我遇到了以下问题:在我的一个 GUI 类中,我子类 QtGui.QDialog 通过

I am using sphinx-autodoc to build a html representation of the docstring of the different modules. On my local machine everything works fine, however, since I need to mock PyQt4 on read-the-docs, I ran into the following problem: In one of my GUI classes, I subclass QtGui.QDialog via

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 告诉我:

Mocking QtGui will result in read-the-docs telling me:

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.

and hence crashing. I've tried to build my package into a virtual environment by selecting Install your project inside a virtualenv using setup.py install however, it turns out even though PyQt4 is listed in pip, you can not install it, see https://superuser.com/questions/679298/how-to-install-pyqt4-and-what-are-the-practical-differences-between-pyqt4-and-py.

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

The only workaround I've found so far is to not load the GUI modules if the environment is RTD and leave out the documentation of the GUI modules, however this should not be the final solution. Thanks.

推荐答案

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

I had a similar problem with PyQt5/py3 (a metaclass conflict with MagickMock). My workaround is to manually mock the module in conf.py instead of using unittest.mock:

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

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

This makes the import / metaclass conflict problem disappear. Unfortunately autodoc still doesn't work (no output), though the builds pass...

当然很乏味.

这篇关于PyQt 4 在阅读文档中导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆