我目前正在通过读取文档在线获取代码的文档,然而,读取文档来处理我的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)
和通过的CCD_ 3
class advancedListSelectorDialog(listSelectorDialog):
def __init__(self,parent,List):
super(advancedListSelectorDialog,self).__init__(parent,List)
模拟QtGui
将导致阅读文档告诉我:
class advancedListSelectorDialog(listSelectorDialog):
TypeError: Error when calling the metaclass bases
str() takes at most 1 argument (3 given)
并因此崩溃。我尝试通过选择使用setup.py Install在virtualenv中安装您的项目然而,事实证明,即使PyQt4在pip
中列出,您也不能安装它,请参阅https://superuser.com/questions/679298/how-to-install-pyqt4-and-what-are-the-practical-differences-between-pyqt4-and-py.
到目前为止,我找到的唯一解决方案是,如果环境是RTD,则不加载GUI模块,并省略GUI模块的文档,但这不应该是最终解决方案。谢谢
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仍然无法工作(没有输出),尽管构建通过了…
当然很挑剔。