Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #105 #120

Merged
merged 10 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Dockerfile-py2.7
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ ENV DISPLAY :99

WORKDIR /workspace/Qt.py
ENTRYPOINT cp -r /Qt.py /workspace && \
python build_caveats_tests.py && \
python build_caveats.py && \
python build_membership.py && \
Xvfb :99 -screen 0 1024x768x16 2>/dev/null & \
sleep 3 && \
nosetests \
--verbose \
--with-process-isolation \
--with-doctest \
--exe
--exe \
test_membership.py \
test_caveats.py \
tests.py
6 changes: 4 additions & 2 deletions Dockerfile-py3.5
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ ENV DISPLAY :99

WORKDIR /workspace/Qt.py
ENTRYPOINT cp -r /Qt.py /workspace && \
python3 build_caveats_tests.py && \
python3 build_caveats.py && \
Xvfb :99 -screen 0 1024x768x16 2>/dev/null & \
sleep 3 && \
nosetests \
--verbose \
--with-process-isolation \
--with-doctest \
--exe
--exe \
test_caveats.py \
tests.py
2 changes: 2 additions & 0 deletions Qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _pyqt4():
PyQt4.QtCore.QStringListModel = PyQt4.QtGui.QStringListModel
PyQt4.QtCore.QItemSelectionModel = PyQt4.QtGui.QItemSelectionModel
PyQt4.QtCore.QSortFilterProxyModel = PyQt4.QtGui.QSortFilterProxyModel
PyQt4.QtCore.QAbstractProxyModel = PyQt4.QtGui.QAbstractProxyModel

try:
from PyQt4 import QtWebKit
Expand Down Expand Up @@ -117,6 +118,7 @@ def _pyside():
PySide.QtCore.QStringListModel = PySide.QtGui.QStringListModel
PySide.QtCore.QItemSelection = PySide.QtGui.QItemSelection
PySide.QtCore.QItemSelectionModel = PySide.QtGui.QItemSelectionModel
PySide.QtCore.QAbstractProxyModel = PySide.QtGui.QAbstractProxyModel

try:
from PySide import QtWebKit
Expand Down
File renamed without changes.
333 changes: 333 additions & 0 deletions build_membership.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
import json


def build_membership():
"""Generate a .json file with all members of PySide2"""

# NOTE: PySide2, as of this writing, is incomplete.
# In it's __all__ module is a module, `QtOpenGL`
# that does no exists. This causes `import *` to fail.

from PySide2 import __all__
__all__.remove("QtOpenGL")

# These modules do not exist pre-Qt 5,
# so do not bother testing for them.
__all__.remove("QtSql")
__all__.remove("QtSvg")

# These should be present in PySide2,
# but are not as of this writing.
for missing in ("QtWidgets",
"QtXml",
"QtHelp",
"QtPrintSupport"):
__all__.append(missing)

# Why `import *`?
#
# PySide, and PyQt, perform magic that triggers via Python's
# import mechanism. If we try and sidestep it in any way, say
# by using `imp.load_module` or `__import__`, the mechanism
# will not trigger and the compiled libraries will not get loaded.
#
# Wildcard was the only way I could think of to import everything,
# without hardcoding the members, such as QtCore into the function.
from PySide2 import *

# Serialise members
members = {}
for name, module in locals().copy().items():
if name.startswith("_"):
continue

if name in ("json", "members", "missing"):
continue

members[name] = list(member for member in dir(module)
if not member.startswith("_"))

# Write to disk
with open("reference_members.json", "w") as f:
json.dump(members, f, indent=4)


def build_tests():
"""Build membership tests

Members only available in Qt 5 are excluded, along with member
exclusive to a paricular binding.

"""

header = """\
#
# AUTOMATICALLY GENERATED MEMBERSHIP TEST, DO NOT MODIFY
#

import os
import json

with open("reference_members.json") as f:
reference_members = json.load(f)

excluded = {excluded}

""".format(excluded=json.dumps(excluded, indent=4))

test = """\
def test_{binding}_members():
os.environ["QT_PREFERRED_BINDING"] = "{Binding}"

if "PyQt" in "{Binding}":
# PyQt4 and 5 performs some magic here
# that must take place before attempting
# to import with wildcard.
from Qt import Qt as _

if "PySide2" == "{Binding}":
# PySide2, as of this writing, doesn't include
# these modules in it's __all__ list; leaving
# the wildcard import below untrue.
from Qt import __all__
for missing in ("QtWidgets",
"QtXml",
"QtHelp",
"QtPrintSupport"):
__all__.append(missing)
Copy link
Collaborator

@fredrikaverpil fredrikaverpil Aug 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PySide2, as of this writing, doesn't include these modules in it's __all__ list; leaving the wildcard import below untrue.

Whoa. Isn't that a bug then?
I mean, at least QtWidgets should be included in __all__?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bug, yeah. Talking about it just now on Gitter.


from Qt import *

if "PySide" == "{Binding}":
# Qt 4 bindings do not include QtWidgets
# in their __all__ list. And who knows what else.
#
# TODO: This needs a more robust implementation.
from Qt import QtWidgets

target_members = dict()
for name, module in locals().copy().items():
if name.startswith("_"):
continue

target_members[name] = dir(module)

missing = dict()
for module, members in reference_members.items():
for member in members:

# Ignore those that have no Qt 4-equivalent.
if member in excluded.get(module, []):
continue

if member not in target_members.get(module, []):
if module not in missing:
missing[module] = []
missing[module].append(member)

message = ""
for module, members in missing.items():
message += "\\n%s: \\n - %s" % (module, "\\n - ".join(members))

assert not missing, "{Binding} is missing members: %s" % message

"""

tests = list(test.format(Binding=binding,
binding=binding.lower())
for binding in ["PyQt5",
"PyQt4",
"PySide"])

with open("test_membership.py", "w") as f:
contents = header + "\n".join(tests)
print(contents) # Preview content during tests
f.write(contents)


# Do not consider these members.
#
# Some of these are either:
# 1. Unique to a particular binding
# 2. Unique to Qt 5
# 3. Not yet included in PySide2
#
# TODO: Clearly mark which are which. (3) should
# eventually be removed from this dictionary.
excluded = {
"QtCore": [
# missing from PySide
"Connection",
"QBasicMutex",
"QFileDevice",
"QItemSelectionRange",
"QJsonArray",
"QJsonDocument",
"QJsonParseError",
"QJsonValue",
"QMessageLogContext",
"QtInfoMsg",
"qInstallMessageHandler",

# missing from PyQt4
"ClassInfo",
"MetaFunction",
"QFactoryInterface",
"QSortFilterProxyModel",
"QStringListModel",
"QT_TRANSLATE_NOOP3",
"QT_TRANSLATE_NOOP_UTF8",
"__moduleShutdown",
"__version__", # (2) unique to PyQt
"__version_info__", # (2) unique to PyQt
"qAcos",
"qAsin",
"qAtan",
"qAtan2",
"qExp",
"qFabs",
"qFastCos",
"qFastSin",
"qFuzzyIsNull",
"qTan",
"qtTrId",

# missing from PyQt5
"SIGNAL",
"SLOT",
],

"QtGui": [
# missing from PySide
"QGuiApplication", # (2) unique to Qt 5
"QPagedPaintDevice",
"QSurface",
"QSurfaceFormat",
"QTouchDevice",
"QWindow", # (2) unique to Qt 5

# missing from PyQt4
"QAccessibleEvent",
"QToolBarChangeEvent",

# missing from PyQt5
"QMatrix",
"QPyTextObject",
"QStringListModel",
],

"QtWebKit": [
# missing from PyQt4
"WebCore",

# missing from PyQt5
"__doc__",
"__file__",
"__name__",
"__package__",
],

"QtScript": [
# missing from PyQt4
"QScriptExtensionInterface",
"QScriptExtensionPlugin",
"QScriptProgram",
"QScriptable",

# missing from PyQt5
"QScriptClass",
"QScriptClassPropertyIterator",
"QScriptContext",
"QScriptContextInfo",
"QScriptEngine",
"QScriptEngineAgent",
"QScriptString",
"QScriptValue",
"QScriptValueIterator",
"__doc__",
"__file__",
"__name__",
"__package__",
],

"QtNetwork": [
# missing from PyQt4
"QIPv6Address",
],

"QtPrintSupport": [
# PyQt4
"QAbstractPrintDialog",
"QPageSetupDialog",
"QPrintDialog",
"QPrintEngine",
"QPrintPreviewDialog",
"QPrintPreviewWidget",
"QPrinter",
"QPrinterInfo",
],

"QtWidgets": [
# PyQt4
"QTileRules",

# PyQt5
"QGraphicsItemAnimation",
"QTileRules",
],

"QtHelp": [
# PySide
"QHelpContentItem",
"QHelpContentModel",
"QHelpContentWidget",
"QHelpEngine",
"QHelpEngineCore",
"QHelpIndexModel",
"QHelpIndexWidget",
"QHelpSearchEngine",
"QHelpSearchQuery",
"QHelpSearchQueryWidget",
"QHelpSearchResultWidget",
],

"QtXml": [
# PySide
"QDomAttr",
"QDomCDATASection",
"QDomCharacterData",
"QDomComment",
"QDomDocument",
"QDomDocumentFragment",
"QDomDocumentType",
"QDomElement",
"QDomEntity",
"QDomEntityReference",
"QDomImplementation",
"QDomNamedNodeMap",
"QDomNode",
"QDomNodeList",
"QDomNotation",
"QDomProcessingInstruction",
"QDomText",
"QXmlAttributes",
"QXmlContentHandler",
"QXmlDTDHandler",
"QXmlDeclHandler",
"QXmlDefaultHandler",
"QXmlEntityResolver",
"QXmlErrorHandler",
"QXmlInputSource",
"QXmlLexicalHandler",
"QXmlLocator",
"QXmlNamespaceSupport",
"QXmlParseException",
"QXmlReader",
"QXmlSimpleReader",
],

}

if __name__ == '__main__':
build_membership()
build_tests()