aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/shibokenmodule
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2018-11-25 15:55:45 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-12-03 20:31:58 +0000
commit14af709e10fa8a2e3c84094c13ebdda9833be124 (patch)
treef6be857ed5d6502e4073a395b21e22cce278da75 /sources/shiboken2/shibokenmodule
parent5778103f5c86dc7f95bd79eabc24de4021eb2734 (diff)
Generate Hinting Stubs Automatically
The script is now automatically called in the cmake build, as part of the create_pyside_module macro. The script runs after every module build and tries to generate .pyi files. This does not need to succeed, but will generate all files in the end. The script has been prepared to allow partial runs without overhead. After integration of the .pyi generation into cmake, these files are also installed into the install directory by cmake. For wheel building, setup.py has entries, too. Building a full project with all modules revealed a bug in the signature module that allowed unsupported function objects. Module enum_sig had to be changed to suppress types which have no ancestry in shiboken. PYTHONPATH was avoided because it was not Windows compatible. Instead, the script was changed to accept "--sys-path" and "--lib-path" parameters. The latter evaluates either to PATH or LD_LIBRARY_PATH. The necessity to create .pyi files while the project is in the build process showed a hard to track down error condition in PySide_BuildSignatureProps. Simple logging was added as a start of introducing logging everywhere. Task-number: PYSIDE-735 Change-Id: I6b3eec4b823d026583e902023badedeb06fe0961 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/shibokenmodule')
-rw-r--r--sources/shiboken2/shibokenmodule/CMakeLists.txt2
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/__init__.py5
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py4
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/loader.py3
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/mapping.py14
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/parser.py1
6 files changed, 23 insertions, 6 deletions
diff --git a/sources/shiboken2/shibokenmodule/CMakeLists.txt b/sources/shiboken2/shibokenmodule/CMakeLists.txt
index 342b6d908..0eba3eaff 100644
--- a/sources/shiboken2/shibokenmodule/CMakeLists.txt
+++ b/sources/shiboken2/shibokenmodule/CMakeLists.txt
@@ -74,7 +74,7 @@ else()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/backport_inspect.py"
"${CMAKE_CURRENT_BINARY_DIR}/support/signature/backport_inspect.py" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/typing27.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/typing.py" COPYONLY)
+ "${CMAKE_CURRENT_BINARY_DIR}/support/signature/typing27.py" COPYONLY)
endif()
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/support"
DESTINATION "${PYTHON_SITE_PACKAGES}/shiboken2")
diff --git a/sources/shiboken2/shibokenmodule/support/signature/__init__.py b/sources/shiboken2/shibokenmodule/support/signature/__init__.py
index 253ba98dc..d0791df04 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/__init__.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/__init__.py
@@ -41,4 +41,7 @@ from __future__ import print_function, absolute_import
# Trigger initialization phase 2.
_ = type.__signature__
-from signature_loader import get_signature, inspect, typing
+
+## from signature_loader import get_signature, inspect, typing
+# This causes a recursion in Python 2!
+# We do everything from signature_loader, instead.
diff --git a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py
index f79f3266a..013ec36cc 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py
@@ -81,6 +81,10 @@ class ExactEnumerator(object):
return ret
def klass(self, class_name, klass):
+ if not "Shiboken" in repr(klass.mro()):
+ # don't look into any foreign classes!
+ ret = self.result_type()
+ return ret
bases_list = []
for base in klass.__bases__:
name = base.__name__
diff --git a/sources/shiboken2/shibokenmodule/support/signature/loader.py b/sources/shiboken2/shibokenmodule/support/signature/loader.py
index 170fb0a2a..de27d441c 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/loader.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/loader.py
@@ -146,7 +146,8 @@ with ensure_import_support():
else:
import inspect
namespace = inspect.__dict__
- from support.signature import typing
+ from support.signature import typing27 as typing
+ typing.__name__ = "typing"
from support.signature import backport_inspect as inspect
_doc = inspect.__doc__
inspect.__dict__.update(namespace)
diff --git a/sources/shiboken2/shibokenmodule/support/signature/mapping.py b/sources/shiboken2/shibokenmodule/support/signature/mapping.py
index bca1ce307..3e76cd94a 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/mapping.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/mapping.py
@@ -104,7 +104,7 @@ class _NotCalled(str):
real object is needed, the wrapper can simply be called.
"""
def __repr__(self):
- suppress = "PySide2.support.signature.typing."
+ suppress = "support.signature.typing."
text = self[len(suppress):] if self.startswith(suppress) else self
return "{}({})".format(type(self).__name__, text)
@@ -119,7 +119,8 @@ class Virtual(_NotCalled):
# Other types I simply could not find.
class Missing(_NotCalled):
- pass
+ def __repr__(self):
+ return '{}("{}")'.format(type(self).__name__, self)
class Invalid(_NotCalled):
pass
@@ -148,7 +149,14 @@ class Reloader(object):
g = globals()
for mod_name in self.uninitialized[:]:
for prefix in self._prefixes:
- if prefix + mod_name in sys.modules:
+ import_name = prefix + mod_name
+ if import_name in sys.modules:
+ # check if this is a real module
+ obj = sys.modules[import_name]
+ if not getattr(obj, "__file__", None) or os.path.isdir(obj.__file__):
+ raise ImportError("Module '{mod_name}' is at most a "
+ "namespace!".format(**locals()))
+ # module is real
self.uninitialized.remove(mod_name)
proc_name = "init_" + mod_name
if proc_name in g:
diff --git a/sources/shiboken2/shibokenmodule/support/signature/parser.py b/sources/shiboken2/shibokenmodule/support/signature/parser.py
index 4bb1bf234..5178d9ef9 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/parser.py
+++ b/sources/shiboken2/shibokenmodule/support/signature/parser.py
@@ -76,6 +76,7 @@ def dprint(*args, **kw):
import pprint
for arg in args:
pprint.pprint(arg)
+ sys.stdout.flush()
def _parse_line(line):
line_re = r"""