-
Notifications
You must be signed in to change notification settings - Fork 253
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
Implement #105 #120
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b13dfcd
Implement #105
mottosso 8f95c5d
Implement #105
mottosso 1fe8bda
Fix Dockerfile for Python 3.5
mottosso b591fd5
Do not run under Python 3
mottosso 7474ce1
Add missing members, exclude PySide2-only members
mottosso 6264a44
Merge remote-tracking branch 'origin/master' into #105
mottosso 0003969
Explicitly run test files
mottosso cf7140a
Refine membership build
mottosso bcb22a0
Add descriptions to membership test
mottosso 1f7791e
Improve membership test, and augment documentation.
mottosso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
build_caveats_tests.py → build_caveats.py
100755 → 100644
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa. Isn't that a bug then?
I mean, at least QtWidgets should be included in
__all__
?There was a problem hiding this comment.
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.