aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside2/PySide2/CMakeLists.txt16
-rw-r--r--sources/pyside2/PySide2/__init__.py.in5
-rw-r--r--sources/pyside2/PySide2/support/generate_pyi.py18
-rw-r--r--sources/pyside2/PySide2/support/signature/layout.py42
-rw-r--r--sources/pyside2/PySide2/support/signature/lib/enum_sig.py42
-rw-r--r--sources/pyside2/PySide2/support/signature/typing.py42
-rw-r--r--sources/pyside2/tests/QtWidgets/signature_test.py2
-rw-r--r--sources/pyside2/tests/registry/init_platform.py2
-rw-r--r--sources/shiboken2/libshiboken/CMakeLists.txt9
-rw-r--r--sources/shiboken2/libshiboken/signature.cpp30
-rw-r--r--sources/shiboken2/shibokenmodule/CMakeLists.txt46
-rw-r--r--sources/shiboken2/shibokenmodule/__init__.py.in7
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__init__.py (renamed from sources/pyside2/PySide2/support/signature/lib/__init__.py)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/PSF-3.7.0.txt (renamed from sources/shiboken2/shibokenmodule/support/signature/PSF-3.7.0.txt)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/__init__.py (renamed from sources/pyside2/PySide2/support/signature/__init__.py)8
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/backport_inspect.py (renamed from sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py)2
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py (renamed from sources/shiboken2/shibokenmodule/support/signature/errorhandler.py)4
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/fix-complaints.py (renamed from sources/shiboken2/shibokenmodule/support/signature/fix-complaints.py)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py (renamed from sources/shiboken2/shibokenmodule/support/signature/layout.py)6
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/__init__.py (renamed from sources/shiboken2/shibokenmodule/support/signature/lib/__init__.py)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py (renamed from sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py)2
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py (renamed from sources/shiboken2/shibokenmodule/support/signature/loader.py)94
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py (renamed from sources/pyside2/PySide2/support/signature/mapping.py)303
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py (renamed from sources/shiboken2/shibokenmodule/support/signature/parser.py)6
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/qt_attribution.json (renamed from sources/shiboken2/shibokenmodule/support/signature/qt_attribution.json)0
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/typing27.py (renamed from sources/shiboken2/shibokenmodule/support/signature/typing27.py)2
-rw-r--r--sources/shiboken2/shibokenmodule/support/__init__.py40
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/__init__.py47
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/contextlib36.py472
-rw-r--r--sources/shiboken2/shibokenmodule/support/signature/mapping.py347
30 files changed, 412 insertions, 1182 deletions
diff --git a/sources/pyside2/PySide2/CMakeLists.txt b/sources/pyside2/PySide2/CMakeLists.txt
index ea1a7de1..5a371b8a 100644
--- a/sources/pyside2/PySide2/CMakeLists.txt
+++ b/sources/pyside2/PySide2/CMakeLists.txt
@@ -6,22 +6,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/global.h.in"
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in"
"${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/generate_pyi.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/generate_pyi.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/layout.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/layout.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/mapping.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/mapping.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/typing.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/typing.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/lib/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/lib/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/lib/enum_sig.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/lib/enum_sig.py" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/_config.py.in"
"${CMAKE_CURRENT_BINARY_DIR}/_config.py" @ONLY)
diff --git a/sources/pyside2/PySide2/__init__.py.in b/sources/pyside2/PySide2/__init__.py.in
index ac75f52b..4548f89b 100644
--- a/sources/pyside2/PySide2/__init__.py.in
+++ b/sources/pyside2/PySide2/__init__.py.in
@@ -19,6 +19,11 @@ def _setupQtDirectories():
# loads the libraries into the process memory beforehand, and
# thus takes care of it for us.
import shiboken2
+ # We might be running from CTest and missing shiboken2.__init__,
+ # so here it is again: Help Python2 by pre-loading modules.
+ import sys, zipfile, base64, marshal, io
+ # Trigger signature initialization.
+ type.__signature__
pyside_package_dir = os.path.abspath(os.path.dirname(__file__))
diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py
index a92ee76f..8474fa73 100644
--- a/sources/pyside2/PySide2/support/generate_pyi.py
+++ b/sources/pyside2/PySide2/support/generate_pyi.py
@@ -55,6 +55,7 @@ import argparse
import glob
from contextlib import contextmanager
from textwrap import dedent
+import traceback
import logging
@@ -105,10 +106,11 @@ class Formatter(Writer):
def module(self, mod_name):
self.mod_name = mod_name
self.print("# Module", mod_name)
+ self.print("import PySide2")
self.print("import shiboken2 as Shiboken")
- from PySide2.support.signature import typing
- self.print("from PySide2.support.signature import typing")
- self.print("from PySide2.support.signature.mapping import (")
+ from shibokensupport.signature import typing
+ self.print("from shibokensupport.signature import typing")
+ self.print("from shibokensupport.signature.mapping import (")
self.print(" Virtual, Missing, Invalid, Default, Instance)")
self.print()
self.print("class Object(object): pass")
@@ -254,7 +256,11 @@ def generate_pyi(import_name, outpath, options):
logger.info("Generated: {outfilepath}".format(**locals()))
if is_py3:
# Python 3: We can check the file directly if the syntax is ok.
- subprocess.check_output([sys.executable, outfilepath])
+ try:
+ subprocess.check_output([sys.executable, outfilepath])
+ except Exception as e:
+ print("+++ Problem executing test, although it works")
+ traceback.print_exc(file=sys.stdout)
return 1
@@ -283,8 +289,8 @@ def generate_all_pyi(outpath, options):
# now we can import
global PySide2, inspect, HintingEnumerator
import PySide2
- from PySide2.support.signature import inspect
- from PySide2.support.signature.lib.enum_sig import HintingEnumerator
+ from shibokensupport.signature import inspect
+ from shibokensupport.signature.lib.enum_sig import HintingEnumerator
valid = check = 0
if not outpath:
diff --git a/sources/pyside2/PySide2/support/signature/layout.py b/sources/pyside2/PySide2/support/signature/layout.py
deleted file mode 100644
index c8a4062c..00000000
--- a/sources/pyside2/PySide2/support/signature/layout.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-from __future__ import print_function, absolute_import
-
-from signature_loader.layout import *
diff --git a/sources/pyside2/PySide2/support/signature/lib/enum_sig.py b/sources/pyside2/PySide2/support/signature/lib/enum_sig.py
deleted file mode 100644
index 1d19ad5e..00000000
--- a/sources/pyside2/PySide2/support/signature/lib/enum_sig.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-from __future__ import print_function, absolute_import
-
-from signature_loader.enum_sig import *
diff --git a/sources/pyside2/PySide2/support/signature/typing.py b/sources/pyside2/PySide2/support/signature/typing.py
deleted file mode 100644
index dd52a2c4..00000000
--- a/sources/pyside2/PySide2/support/signature/typing.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-from __future__ import print_function, absolute_import
-
-from signature_loader.typing import *
diff --git a/sources/pyside2/tests/QtWidgets/signature_test.py b/sources/pyside2/tests/QtWidgets/signature_test.py
index 15a9333b..3a0114b0 100644
--- a/sources/pyside2/tests/QtWidgets/signature_test.py
+++ b/sources/pyside2/tests/QtWidgets/signature_test.py
@@ -42,7 +42,7 @@ from __future__ import print_function, absolute_import
import unittest
import PySide2.QtCore
import PySide2.QtWidgets
-from PySide2.support.signature import inspect
+from shibokensupport.signature import inspect
class PySideSignatureTest(unittest.TestCase):
diff --git a/sources/pyside2/tests/registry/init_platform.py b/sources/pyside2/tests/registry/init_platform.py
index a324c36a..31e21228 100644
--- a/sources/pyside2/tests/registry/init_platform.py
+++ b/sources/pyside2/tests/registry/init_platform.py
@@ -139,7 +139,7 @@ for modname in "minimal sample other smart".split():
all_modules.append(modname)
from PySide2.QtCore import __version__
-from PySide2.support.signature.lib.enum_sig import SimplifyingEnumerator
+from shibokensupport.signature.lib.enum_sig import SimplifyingEnumerator
is_py3 = sys.version_info[0] == 3
is_ci = os.environ.get("QTEST_ENVIRONMENT", "") == "ci"
diff --git a/sources/shiboken2/libshiboken/CMakeLists.txt b/sources/shiboken2/libshiboken/CMakeLists.txt
index 79f83ec7..636d8c01 100644
--- a/sources/shiboken2/libshiboken/CMakeLists.txt
+++ b/sources/shiboken2/libshiboken/CMakeLists.txt
@@ -26,6 +26,14 @@ endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sbkversion.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/sbkversion.h" @ONLY)
+# configure_file("${CMAKE_CURRENT_SOURCE_DIR}/embed/signature_loader.py"
+# "${CMAKE_CURRENT_BINARY_DIR}/embed/signature_loader.py" @ONLY)
+
+# add_custom_command(
+# OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/embed/signature.inc"
+# COMMAND ${PYTHON_EXECUTABLE} -E
+# "${CMAKE_CURRENT_SOURCE_DIR}/embed/embedding_generator.py"
+# --cmake-dir "${CMAKE_CURRENT_BINARY_DIR}/embed")
set(libshiboken_MAJOR_VERSION ${shiboken_MAJOR_VERSION})
set(libshiboken_MINOR_VERSION ${shiboken_MINOR_VERSION})
@@ -52,6 +60,7 @@ pep384impl.cpp
voidptr.cpp
typespec.cpp
bufferprocs_py37.cpp
+# embed/signature.inc
)
get_numpy_location()
diff --git a/sources/shiboken2/libshiboken/signature.cpp b/sources/shiboken2/libshiboken/signature.cpp
index cd00a148..a99927c1 100644
--- a/sources/shiboken2/libshiboken/signature.cpp
+++ b/sources/shiboken2/libshiboken/signature.cpp
@@ -92,11 +92,6 @@ static PyObject *PySide_BuildSignatureProps(PyObject *class_mod);
static void init_module_1(void);
static void init_module_2(void);
-const char helper_module_name[] = "signature_loader";
-const char bootstrap_name[] = "bootstrap";
-const char arg_name[] = "pyside_arg_dict";
-const char func_name[] = "pyside_type_init";
-
static PyObject *
CreateSignature(PyObject *props, PyObject *key)
{
@@ -423,6 +418,10 @@ GetSignature_Cached(PyObject *props, const char *sig_kind, const char *modifier)
return Py_INCREF(value), value;
}
+// const char *PySide_SignatureModule[] = {
+// #include "embed/signature.inc"
+// };
+
static const char PySide_PythonCode[] =
"from __future__ import print_function, absolute_import\n" R"~(if True:
@@ -438,21 +437,18 @@ static const char PySide_PythonCode[] =
import shiboken2 as root
except ImportError:
# uninstalled case without ctest, try only this one which has __init__:
- from shibokenmodule import shiboken2 as root
+ import shibokenmodule as root
rp = os.path.realpath(os.path.dirname(root.__file__))
# This can be the shiboken2 directory or the binary module, so search.
- while len(rp) > 3 and not os.path.exists(os.path.join(rp, 'support')):
+ while len(rp) > 3 and not os.path.exists(os.path.join(rp, 'files.dir')):
rp = os.path.abspath(os.path.join(rp, '..'))
- __file__ = os.path.join(rp, 'support', 'signature', 'loader.py')
+ __file__ = os.path.join(rp, 'files.dir', 'shibokensupport', 'signature', 'loader.py')
try:
with open(__file__) as _f:
exec(compile(_f.read(), __file__, 'exec'))
except Exception as e:
- try:
- from shiboken2.support.signature import loader
- except:
- print('Exception:', e)
- traceback.print_exc(file=sys.stdout)
+ print('Exception:', e)
+ traceback.print_exc(file=sys.stdout)
globals().update(locals())
)~";
@@ -465,7 +461,7 @@ init_phase_1(void)
malloc(sizeof(safe_globals_struc));
if (p == NULL)
goto error;
- p->helper_module = PyImport_AddModule((char *) helper_module_name);
+ p->helper_module = PyImport_AddModule((char *) "signature_loader");
if (p->helper_module == NULL)
goto error;
@@ -486,7 +482,7 @@ init_phase_1(void)
// build a dict for the prepared arguments
p->arg_dict = PyDict_New();
if (p->arg_dict == NULL
- || PyObject_SetAttrString(p->helper_module, arg_name, p->arg_dict) < 0)
+ || PyObject_SetAttrString(p->helper_module, "pyside_arg_dict", p->arg_dict) < 0)
goto error;
return p;
@@ -509,12 +505,12 @@ init_phase_2(safe_globals_struc *p, PyMethodDef *methods)
goto error;
Py_DECREF(v);
}
- bootstrap_func = PyObject_GetAttrString(p->helper_module, bootstrap_name);
+ bootstrap_func = PyObject_GetAttrString(p->helper_module, "bootstrap");
if (bootstrap_func == NULL
|| PyObject_CallFunction(bootstrap_func, (char *)"()") == NULL)
goto error;
// now the loader should be initialized
- p->sigparse_func = PyObject_GetAttrString(p->helper_module, func_name);
+ p->sigparse_func = PyObject_GetAttrString(p->helper_module, "pyside_type_init");
if (p->sigparse_func == NULL)
goto error;
p->createsig_func = PyObject_GetAttrString(p->helper_module, "create_signature");
diff --git a/sources/shiboken2/shibokenmodule/CMakeLists.txt b/sources/shiboken2/shibokenmodule/CMakeLists.txt
index b37d0c94..612055b3 100644
--- a/sources/shiboken2/shibokenmodule/CMakeLists.txt
+++ b/sources/shiboken2/shibokenmodule/CMakeLists.txt
@@ -51,32 +51,32 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/_config.py"
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in"
"${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/errorhandler.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/errorhandler.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/layout.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/layout.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/loader.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/loader.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/mapping.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/mapping.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/parser.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/parser.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/lib/__init__.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/lib/__init__.py" COPYONLY)
-configure_file("${CMAKE_CURRENT_SOURCE_DIR}/support/signature/lib/enum_sig.py"
- "${CMAKE_CURRENT_BINARY_DIR}/support/signature/lib/enum_sig.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/__init__.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/__init__.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/__init__.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/__init__.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/errorhandler.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/errorhandler.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/layout.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/layout.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/loader.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/loader.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/mapping.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/mapping.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/parser.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/parser.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/lib/__init__.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/lib/__init__.py" COPYONLY)
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/lib/enum_sig.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/lib/enum_sig.py" COPYONLY)
if (PYTHON_VERSION_MAJOR EQUAL 3)
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/typing27.py" COPYONLY)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/backport_inspect.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/backport_inspect.py" COPYONLY)
+ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/files.dir/shibokensupport/signature/typing27.py"
+ "${CMAKE_CURRENT_BINARY_DIR}/files.dir/shibokensupport/signature/typing27.py" COPYONLY)
endif()
-install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/support"
+install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/files.dir"
DESTINATION "${PYTHON_SITE_PACKAGES}/shiboken2")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/__init__.py"
diff --git a/sources/shiboken2/shibokenmodule/__init__.py.in b/sources/shiboken2/shibokenmodule/__init__.py.in
index 81ab0063..92e469df 100644
--- a/sources/shiboken2/shibokenmodule/__init__.py.in
+++ b/sources/shiboken2/shibokenmodule/__init__.py.in
@@ -1,4 +1,11 @@
__version__ = "@FINAL_PACKAGE_VERSION@"
__version_info__ = (@shiboken_MAJOR_VERSION@, @shiboken_MINOR_VERSION@, @shiboken_MICRO_VERSION@, "@shiboken_PRE_RELEASE_VERSION_TYPE@", "@shiboken_PRE_RELEASE_VERSION@")
+# PYSIDE-932: Python 2 cannot import 'zipfile' for embedding while being imported, itself.
+# We simply pre-load all imports for the signature extension.
+import sys, zipfile, base64, marshal, io
+
from .shiboken2 import *
+
+# Trigger signature initialization.
+type.__signature__
diff --git a/sources/pyside2/PySide2/support/signature/lib/__init__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__init__.py
index 2d640cb8..2d640cb8 100644
--- a/sources/pyside2/PySide2/support/signature/lib/__init__.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/__init__.py
diff --git a/sources/shiboken2/shibokenmodule/support/signature/PSF-3.7.0.txt b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/PSF-3.7.0.txt
index be42010d..be42010d 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/PSF-3.7.0.txt
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/PSF-3.7.0.txt
diff --git a/sources/pyside2/PySide2/support/signature/__init__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/__init__.py
index 5a87a814..9447e9c2 100644
--- a/sources/pyside2/PySide2/support/signature/__init__.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/__init__.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -39,8 +39,6 @@
from __future__ import print_function, absolute_import
-# Trigger initialization phase 2.
-_ = type.__signature__
-from signature_loader import get_signature, inspect, typing
-
+# from shibokensupport.signature import get_signature, inspect, typing
+# This gives a problem with Python 2. We do it in the loader, instead.
__all__ = "get_signature inspect typing layout mapping lib".split()
diff --git a/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/backport_inspect.py
index e890dcdc..fbd82cc5 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/backport_inspect.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/backport_inspect.py
@@ -3,7 +3,7 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
diff --git a/sources/shiboken2/shibokenmodule/support/signature/errorhandler.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py
index df24234e..1443d792 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/errorhandler.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/errorhandler.py
@@ -56,8 +56,8 @@ enough to produce a useful ValueError.
This matter will be improved in a later version.
"""
-from signature_loader import get_signature, inspect
-from signature_loader.mapping import update_mapping, namespace
+from shibokensupport.signature import get_signature, inspect
+from shibokensupport.signature.mapping import update_mapping, namespace
from textwrap import dedent
diff --git a/sources/shiboken2/shibokenmodule/support/signature/fix-complaints.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/fix-complaints.py
index cdd84f9b..cdd84f9b 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/fix-complaints.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/fix-complaints.py
diff --git a/sources/shiboken2/shibokenmodule/support/signature/layout.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py
index cd3a5dc8..c43d6d07 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/layout.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -56,8 +56,8 @@ used literally as strings like "signature", "existence", etc.
"""
from textwrap import dedent
-from signature_loader import inspect
-from signature_loader.mapping import ellipsis
+from shibokensupport.signature import inspect
+from shibokensupport.signature.mapping import ellipsis
class SimpleNamespace(object):
diff --git a/sources/shiboken2/shibokenmodule/support/signature/lib/__init__.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/__init__.py
index 2d640cb8..2d640cb8 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/lib/__init__.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/__init__.py
diff --git a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
index 013ec36c..90affbcf 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/lib/enum_sig.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
@@ -50,7 +50,7 @@ by producing a lot of clarity.
"""
import sys
-from signature_loader import get_signature, inspect
+from shibokensupport.signature import get_signature, inspect
class ExactEnumerator(object):
diff --git a/sources/shiboken2/shibokenmodule/support/signature/loader.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py
index 45875984..3a8d614d 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/loader.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -45,13 +45,8 @@ loader.py
The loader has to lazy-load the signature module and also provides a few
Python modules to support Python 2.7 .
-This file was originally directly embedded into the C source.
-After it grew more and more, I now prefer to have it as Python file.
-The remaining stub loader in the C source is now only a short string.
-
-This version does no longer use an embedded .zip file but is a package.
-The old code without a package but with zip compression can still be found
-at https://codereview.qt-project.org/#/c/203533/ for reference.
+This version uses both a normal directory, but has also an embedded zip file
+as a fallback solution.
"""
import sys
@@ -85,29 +80,28 @@ except NameError:
ModuleNotFoundError = ImportError
@contextmanager
-def ensure_import_support():
- # Make sure that we always have the shiboken containing package first.
- # This is sometimes hidden by the ctest paths.
- # We adjust the path in a way that the support folder comes first.
- # This can be in "shiboken2/support" or in "shibokenmodule/support",
- # so we use the "support" folder as toplevel.
+def ensure_import_shibokensupport():
+ # Make sure that we always have the shibokensupport containing package first.
+ # Also remove any prior loaded module of this name, just in case.
sbk_support_dir = os.path.abspath(os.path.join(__file__, "..", "..", ".."))
+ assert os.path.basename(sbk_support_dir) == "files.dir"
sys.path.insert(0, sbk_support_dir)
- sbk = "shiboken2"
- save_sbk = sys.modules.pop(sbk) if sbk in sys.modules else None
- # make sure that we get at the support folder
+
+ sbk = "shibokensupport"
+ if sbk in sys.modules:
+ del sys.modules[sbk]
+ for key in list(key for key in sys.modules if key.startswith(sbk + ".")):
+ del sys.modules[key]
try:
- import support
+ import shibokensupport
yield
except Exception as e:
- print("Problem importing support:")
+ print("Problem importing shibokensupport:")
print(e)
traceback.print_exc()
sys.stdout.flush()
sys.exit(-1)
- if save_sbk:
- sys.modules[sbk] = save_sbk
- sys.path.pop(0)
+ sys.path.remove(sbk_support_dir)
# patching inspect's formatting to keep the word "typing":
@@ -117,7 +111,7 @@ def formatannotation(annotation, base_module=None):
if isinstance(annotation, type):
if annotation.__module__ in ('builtins', base_module):
return annotation.__qualname__
- return annotation.__module__+'.'+annotation.__qualname__
+ return annotation.__module__ + '.' + annotation.__qualname__
return repr(annotation)
# patching __repr__ to disable the __repr__ of typing.TypeVar:
@@ -149,10 +143,11 @@ def seterror_argument(args, func_name):
def make_helptext(func):
return errorhandler.make_helptext(func)
-with ensure_import_support():
- # We store all needed modules in signature_loader.
- # This way, they are always accessible.
+with ensure_import_shibokensupport():
import signature_loader
+ import shibokensupport.signature
+ shibokensupport.signature.get_signature = signature_loader.get_signature
+ del signature_loader # protect this dir, too?
if sys.version_info >= (3,):
import typing
@@ -161,7 +156,7 @@ with ensure_import_support():
else:
import inspect
namespace = inspect.__dict__
- from support.signature import typing27 as typing
+ from shibokensupport.signature import typing27 as typing
typing.__name__ = "typing"
# Fix the module names in typing if possible. This is important since
# the typing names should be I/O compatible, so that typing.Dict
@@ -172,7 +167,7 @@ with ensure_import_support():
obj.__module__ = "typing"
except (TypeError, AttributeError):
pass
- from support.signature import backport_inspect as inspect
+ from shibokensupport.signature import backport_inspect as inspect
_doc = inspect.__doc__
inspect.__dict__.update(namespace)
inspect.__doc__ += _doc
@@ -180,42 +175,21 @@ with ensure_import_support():
inspect.__all__ = list(x for x in dir(inspect) if not x.startswith("_"))
typing.TypeVar.__repr__ = _typevar__repr__
- def put_into_loader_package(module, loader=signature_loader):
- # Note: the "with" statement hides that we are no longer in a
- # global context, but inside ensure_import_support. Therefore,
- # we need to explicitly pass the signature_loader in.
-
+ def put_into_package(module, package):
# take the last component of the module name
name = module.__name__.rsplit(".", 1)[-1]
- # allow access as signature_loader.typing
- setattr(loader, name, module)
+ # allow access as {package}.typing
+ setattr(package, name, module)
# put into sys.modules as a package to allow all import options
- fullname = "{}.{}".format(loader.__name__, name)
+ fullname = "{}.{}".format(package.__name__, name)
sys.modules[fullname] = module
- put_into_loader_package(typing)
- put_into_loader_package(inspect)
- from support.signature import mapping as sbk_mapping
- sbk_mapping.__name__ = "sbk_mapping"
- put_into_loader_package(sbk_mapping)
- # We may or may not use PySide.
- try:
- from PySide2.support.signature import mapping
- except ModuleNotFoundError:
- mapping = sbk_mapping
- mapping.__name__ = "mapping"
- put_into_loader_package(mapping)
- from support.signature import errorhandler
- put_into_loader_package(errorhandler)
- from support.signature import layout
- put_into_loader_package(layout)
- from support.signature.lib import enum_sig
- put_into_loader_package(enum_sig)
- from support.signature.parser import pyside_type_init
- put_into_loader_package(pyside_type_init)
- put_into_loader_package(create_signature)
- put_into_loader_package(seterror_argument)
- put_into_loader_package(make_helptext)
-
+ put_into_package(typing, shibokensupport.signature)
+ put_into_package(inspect, shibokensupport.signature)
+ from shibokensupport.signature import mapping
+ from shibokensupport.signature import errorhandler
+ from shibokensupport.signature import layout
+ from shibokensupport.signature.lib import enum_sig
+ from shibokensupport.signature.parser import pyside_type_init
# end of file
diff --git a/sources/pyside2/PySide2/support/signature/mapping.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
index 2b234ecd..470dd676 100644
--- a/sources/pyside2/PySide2/support/signature/mapping.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -49,24 +49,307 @@ The PySide modules are not loaded in advance, but only after they appear
in sys.modules. This minimizes the loading overhead.
"""
-import PySide2
+import sys
+import struct
+import os
+import pkgutil
-from signature_loader.sbk_mapping import *
-from signature_loader.sbk_mapping import _NotCalled
+from shibokensupport.signature import typing
+from shibokensupport.signature.typing import TypeVar, Generic
-Sbk_Reloader = Reloader
+class ellipsis(object):
+ def __repr__(self):
+ return "..."
-class Reloader(Sbk_Reloader):
- _uninitialized = Sbk_Reloader._uninitialized + PySide2.__all__ + ["testbinding"]
- _prefixes = Sbk_Reloader._prefixes + ["PySide2."]
+ellipsis = ellipsis()
+StringList = typing.List[str]
+IntList = typing.List[int]
+Point = typing.Tuple[float, float]
+PointList = typing.List[Point]
+IntMatrix = typing.List[IntList]
+Variant = typing.Any
+ModelIndexList = typing.List[int]
+QImageCleanupFunction = typing.Callable
+
+# First time installing our own Pair type into typing.
+T = TypeVar('T')
+S = TypeVar('S')
+
+class Pair(Generic[T, S]):
+ __module__ = "typing"
+
+typing.Pair = Pair
+
+
+# Building our own Char type, which is much nicer than
+# Char = typing.Union[str, int] # how do I model the limitation to 1 char?
+
+# Copied from the six module:
+def with_metaclass(meta, *bases):
+ """Create a base class with a metaclass."""
+ # This requires a bit of explanation: the basic idea is to make a dummy
+ # metaclass for one level of class instantiation that replaces itself with
+ # the actual metaclass.
+ class metaclass(type):
+
+ def __new__(cls, name, this_bases, d):
+ return meta(name, bases, d)
+
+ @classmethod
+ def __prepare__(cls, name, this_bases):
+ return meta.__prepare__(name, bases)
+ return type.__new__(metaclass, 'temporary_class', (), {})
+
+class _CharMeta(type):
+ def __repr__(self):
+ return '%s.%s' % (self.__module__, self.__name__)
+
+
+class Char(with_metaclass(_CharMeta)):
+ """
+ From http://doc.qt.io/qt-5/qchar.html :
+
+ In Qt, Unicode characters are 16-bit entities without any markup or
+ structure. This class represents such an entity. It is lightweight,
+ so it can be used everywhere. Most compilers treat it like an
+ unsigned short.
+
+ Here, we provide a simple implementation just to avoid long aliases.
+ """
+ __module__ = "typing"
+
+ def __init__(self, code):
+ if isinstance(code, int):
+ self.code = code & 0xffff
+ else:
+ self.code = ord(code)
+
+ def __add__(self, other):
+ return chr(self.code) + other
+
+ def __radd__(self, other):
+ return other + chr(self.code)
+
+ def __repr__(self):
+ return "typing.Char({})".format(self.code)
+
+typing.Char = Char
+
+
+MultiMap = typing.DefaultDict[str, typing.List[str]]
+
+# ulong_max is only 32 bit on windows.
+ulong_max = 2*sys.maxsize+1 if len(struct.pack("L", 1)) != 4 else 0xffffffff
+ushort_max = 0xffff
+
+GL_COLOR_BUFFER_BIT = 0x00004000
+GL_NEAREST = 0x2600
+
+WId = int
+
+# from 5.9
+GL_TEXTURE_2D = 0x0DE1
+GL_RGBA = 0x1908
+
+
+class _NotCalled(str):
+ """
+ Wrap some text with semantics
+
+ This class is wrapped around text in order to avoid calling it.
+ There are three reasons for this:
+
+ - some instances cannot be created since they are abstract,
+ - some can only be created after qApp was created,
+ - some have an ugly __repr__ with angle brackets in it.
+
+ By using derived classes, good looking instances can be created
+ which can be used to generate source code or .pyi files. When the
+ real object is needed, the wrapper can simply be called.
+ """
+ def __repr__(self):
+ suppress = "support.signature.typing27."
+ text = self[len(suppress):] if self.startswith(suppress) else self
+ return "{}({})".format(type(self).__name__, text)
+
+ def __call__(self):
+ from shibokensupport.signature.mapping import __dict__ as namespace
+ text = self if self.endswith(")") else self + "()"
+ return eval(text, namespace)
+
+USE_PEP563 = sys.version_info[:2] >= (3, 7)
+
+
+# Some types are abstract. They just show their name.
+class Virtual(_NotCalled):
+ pass
+
+# Other types I simply could not find.
+class Missing(_NotCalled):
+ if not USE_PEP563:
+ # The string must be quoted, because the object does not exist.
+ def __repr__(self):
+ return '{}("{}")'.format(type(self).__name__, self)
+
+
+class Invalid(_NotCalled):
+ pass
+
+# Helper types
+class Default(_NotCalled):
+ pass
+
+
+class Instance(_NotCalled):
+ pass
+
+
+class Reloader(object):
+ """
+ Reloder class
+
+ This is a singleton class which provides the update function for the
+ shiboken and PySide classes.
+ """
+ _uninitialized = "Shiboken minimal sample other smart".split()
+ _prefixes = [""]
+ try:
+ import PySide2
+ _uninitialized += PySide2.__all__ + ["testbinding"]
+ _prefixes += ["PySide2."]
+ except ImportError:
+ pass
+
+ def __init__(self):
+ self.sys_module_count = 0
+ self.uninitialized = self._uninitialized
def update(self):
- Sbk_Reloader.update(self, globals())
+ """
+ update is responsible to import all modules from shiboken and PySide
+ which are already in sys.modules.
+ The purpose is to follow all user imports without introducing new
+ ones.
+ This function is called by pyside_type_init to adapt imports
+ when the number of imported modules has changed.
+ """
+ if self.sys_module_count == len(sys.modules):
+ return
+ self.sys_module_count = len(sys.modules)
+ g = globals()
+ for mod_name in self.uninitialized[:]:
+ for prefix in self._prefixes:
+ import_name = prefix + mod_name
+ if import_name in sys.modules:
+ # check if this is a real module
+ check_module(sys.modules[import_name])
+ # module is real
+ self.uninitialized.remove(mod_name)
+ proc_name = "init_" + mod_name
+ if proc_name in g:
+ # Do the 'import {import_name}' first.
+ # 'top' is PySide2 when we do 'import PySide.QtCore'
+ # or Shiboken if we do 'import Shiboken'.
+ # Convince yourself that these two lines below have the same
+ # global effect as "import Shiboken" or "import PySide2.QtCore".
+ top = __import__(import_name)
+ g[top.__name__] = top
+ # Modules are in place, we can update the type_map.
+ g.update(g[proc_name]())
+
+def check_module(mod):
+ # During a build, there exist the modules already as directories,
+ # although the '*.so' was not yet created. This causes a problem
+ # in Python 3, because it accepts folders as namespace modules
+ # without enforcing an '__init__.py'.
+ if not getattr(mod, "__file__", None) or os.path.isdir(mod.__file__):
+ mod_name = mod.__name__
+ raise ImportError("Module '{mod_name}' is at most a namespace!"
+ .format(**locals()))
+
update_mapping = Reloader().update
-namespace = globals() # our module's __dict__, updated
+type_map = {}
+namespace = globals() # our module's __dict__
+
+type_map.update({
+ "QList": typing.List,
+ "QVector": typing.List,
+ "QSet": typing.Set,
+ "QPair": Pair,
+ })
+
+# The Shiboken Part
+def init_Shiboken():
+ type_map.update({
+ "shiboken2.bool": bool,
+ "size_t": int,
+ "PyType": type,
+ })
+ return locals()
+
+
+def init_minimal():
+ type_map.update({
+ "MinBool": bool,
+ })
+ return locals()
+
+
+def init_sample():
+ import datetime
+ type_map.update({
+ "double": float,
+ "sample.int": int,
+ "Complex": complex,
+ "sample.OddBool": bool,
+ "sample.bool": bool,
+ "sample.PStr": str,
+ "OddBool": bool,
+ "PStr": str,
+ "char": Char,
+ "sample.char": Char,
+ "sample.Point": Point,
+ "sample.ObjectType": object,
+ "std.string": str,
+ "HANDLE": int,
+ "Foo.HANDLE": int,
+ "sample.Photon.TemplateBase": Missing("sample.Photon.TemplateBase"),
+ "ObjectType.Identifier": Missing("sample.ObjectType.Identifier"),
+ "zero(HANDLE)": 0,
+ "Null": None,
+ "zero(sample.ObjectType)": None,
+ "std.size_t": int,
+ 'Str("<unknown>")': "<unknown>",
+ 'Str("<unk")': "<unk",
+ 'Str("nown>")': "nown>",
+ "zero(sample.ObjectModel)": None,
+ "sample.unsigned char": Char,
+ "sample.double": float,
+ "zero(sample.bool)": False,
+ "PyDate": datetime.date,
+ "ZeroIn": 0,
+ })
+ return locals()
+
+
+def init_other():
+ import numbers
+ type_map.update({
+ "other.Number": numbers.Number,
+ "other.ExtendsNoImplicitConversion": Missing("other.ExtendsNoImplicitConversion"),
+ })
+ return locals()
+
+
+def init_smart():
+ type_map.update({
+ "smart.SharedPtr": Missing("smart.SharedPtr"), # bad object "SharedPtr<Obj >"
+ })
+ return locals()
+# The PySide Part
def init_QtCore():
from PySide2.QtCore import Qt, QUrl, QDir
from PySide2.QtCore import QRect, QSize, QPoint, QLocale, QByteArray
diff --git a/sources/shiboken2/shibokenmodule/support/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
index 5c9a1e4f..09e78f1b 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/parser.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
@@ -1,6 +1,6 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
@@ -45,8 +45,8 @@ import warnings
import types
import keyword
import functools
-from signature_loader.mapping import (type_map, update_mapping, namespace,
- typing, _NotCalled)
+from shibokensupport.signature.mapping import (type_map, update_mapping,
+ namespace, typing, _NotCalled)
_DEBUG = False
LIST_KEYWORDS = False
diff --git a/sources/shiboken2/shibokenmodule/support/signature/qt_attribution.json b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/qt_attribution.json
index 491ae805..491ae805 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/qt_attribution.json
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/qt_attribution.json
diff --git a/sources/shiboken2/shibokenmodule/support/signature/typing27.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/typing27.py
index 5d1c6058..dba8f8c7 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/typing27.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/typing27.py
@@ -3,7 +3,7 @@
#############################################################################
##
-## Copyright (C) 2018 The Qt Company Ltd.
+## Copyright (C) 2019 The Qt Company Ltd.
## Contact: https://www.qt.io/licensing/
##
## This file is part of Qt for Python.
diff --git a/sources/shiboken2/shibokenmodule/support/__init__.py b/sources/shiboken2/shibokenmodule/support/__init__.py
deleted file mode 100644
index 760d8957..00000000
--- a/sources/shiboken2/shibokenmodule/support/__init__.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#############################################################################
-##
-## Copyright (C) 2017 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-# this file intentionally left blank
diff --git a/sources/shiboken2/shibokenmodule/support/signature/__init__.py b/sources/shiboken2/shibokenmodule/support/signature/__init__.py
deleted file mode 100644
index d0791df0..00000000
--- a/sources/shiboken2/shibokenmodule/support/signature/__init__.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-from __future__ import print_function, absolute_import
-
-# Trigger initialization phase 2.
-_ = type.__signature__
-
-## 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/contextlib36.py b/sources/shiboken2/shibokenmodule/support/signature/contextlib36.py
deleted file mode 100644
index d416eef2..00000000
--- a/sources/shiboken2/shibokenmodule/support/signature/contextlib36.py
+++ /dev/null
@@ -1,472 +0,0 @@
-# This Python file uses the following encoding: utf-8
-# It has been edited by fix-complaints.py .
-
-#############################################################################
-##
-## Copyright (C) 2019 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-"""
-PSF LICENSE AGREEMENT FOR PYTHON 3.7.0
-
-1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and
- the Individual or Organization ("Licensee") accessing and otherwise using Python
- 3.7.0 software in source or binary form and its associated documentation.
-
-2. Subject to the terms and conditions of this License Agreement, PSF hereby
- grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
- analyze, test, perform and/or display publicly, prepare derivative works,
- distribute, and otherwise use Python 3.7.0 alone or in any derivative
- version, provided, however, that PSF's License Agreement and PSF's notice of
- copyright, i.e., "Copyright © 2001-2018 Python Software Foundation; All Rights
- Reserved" are retained in Python 3.7.0 alone or in any derivative version
- prepared by Licensee.
-
-3. In the event Licensee prepares a derivative work that is based on or
- incorporates Python 3.7.0 or any part thereof, and wants to make the
- derivative work available to others as provided herein, then Licensee hereby
- agrees to include in any such work a brief summary of the changes made to Python
- 3.7.0.
-
-4. PSF is making Python 3.7.0 available to Licensee on an "AS IS" basis.
- PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF
- EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR
- WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE
- USE OF PYTHON 3.7.0 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
-
-5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.7.0
- FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
- MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.7.0, OR ANY DERIVATIVE
- THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
-
-6. This License Agreement will automatically terminate upon a material breach of
- its terms and conditions.
-
-7. Nothing in this License Agreement shall be deemed to create any relationship
- of agency, partnership, or joint venture between PSF and Licensee. This License
- Agreement does not grant permission to use PSF trademarks or trade name in a
- trademark sense to endorse or promote products or services of Licensee, or any
- third party.
-
-8. By copying, installing or otherwise using Python 3.7.0, Licensee agrees
- to be bound by the terms and conditions of this License Agreement.
-"""
-
-"""Utilities for with-statement contexts. See PEP 343."""
-import abc
-import sys
-import _collections_abc
-from collections import deque
-from functools import wraps
-
-__all__ = ["contextmanager", "closing", "AbstractContextManager",
- "ContextDecorator", "ExitStack", "redirect_stdout",
- "redirect_stderr", "suppress"]
-
-
-class AbstractContextManager(abc.ABC):
-
- """An abstract base class for context managers."""
-
- def __enter__(self):
- """Return `self` upon entering the runtime context."""
- return self
-
- @abc.abstractmethod
- def __exit__(self, exc_type, exc_value, traceback):
- """Raise any exception triggered within the runtime context."""
- return None
-
- @classmethod
- def __subclasshook__(cls, C):
- if cls is AbstractContextManager:
- return _collections_abc._check_methods(C, "__enter__", "__exit__")
- return NotImplemented
-
-
-class ContextDecorator(object):
- "A base class or mixin that enables context managers to work as decorators."
-
- def _recreate_cm(self):
- """Return a recreated instance of self.
-
- Allows an otherwise one-shot context manager like
- _GeneratorContextManager to support use as
- a decorator via implicit recreation.
-
- This is a private interface just for _GeneratorContextManager.
- See issue #11647 for details.
- """
- return self
-
- def __call__(self, func):
- @wraps(func)
- def inner(*args, **kwds):
- with self._recreate_cm():
- return func(*args, **kwds)
- return inner
-
-
-class _GeneratorContextManager(ContextDecorator, AbstractContextManager):
- """Helper for @contextmanager decorator."""
-
- def __init__(self, func, args, kwds):
- self.gen = func(*args, **kwds)
- self.func, self.args, self.kwds = func, args, kwds
- # Issue 19330: ensure context manager instances have good docstrings
- doc = getattr(func, "__doc__", None)
- if doc is None:
- doc = type(self).__doc__
- self.__doc__ = doc
- # Unfortunately, this still doesn't provide good help output when
- # inspecting the created context manager instances, since pydoc
- # currently bypasses the instance docstring and shows the docstring
- # for the class instead.
- # See http://bugs.python.org/issue19404 for more details.
-
- def _recreate_cm(self):
- # _GCM instances are one-shot context managers, so the
- # CM must be recreated each time a decorated function is
- # called
- return self.__class__(self.func, self.args, self.kwds)
-
- def __enter__(self):
- try:
- return next(self.gen)
- except StopIteration:
- raise RuntimeError("generator didn't yield") from None
-
- def __exit__(self, type, value, traceback):
- if type is None:
- try:
- next(self.gen)
- except StopIteration:
- return False
- else:
- raise RuntimeError("generator didn't stop")
- else:
- if value is None:
- # Need to force instantiation so we can reliably
- # tell if we get the same exception back
- value = type()
- try:
- self.gen.throw(type, value, traceback)
- except StopIteration as exc:
- # Suppress StopIteration *unless* it's the same exception that
- # was passed to throw(). This prevents a StopIteration
- # raised inside the "with" statement from being suppressed.
- return exc is not value
- except RuntimeError as exc:
- # Don't re-raise the passed in exception. (issue27122)
- if exc is value:
- return False
- # Likewise, avoid suppressing if a StopIteration exception
- # was passed to throw() and later wrapped into a RuntimeError
- # (see PEP 479).
- if type is StopIteration and exc.__cause__ is value:
- return False
- raise
- except:
- # only re-raise if it's *not* the exception that was
- # passed to throw(), because __exit__() must not raise
- # an exception unless __exit__() itself failed. But throw()
- # has to raise the exception to signal propagation, so this
- # fixes the impedance mismatch between the throw() protocol
- # and the __exit__() protocol.
- #
- if sys.exc_info()[1] is value:
- return False
- raise
- raise RuntimeError("generator didn't stop after throw()")
-
-
-def contextmanager(func):
- """@contextmanager decorator.
-
- Typical usage:
-
- @contextmanager
- def some_generator(<arguments>):
- <setup>
- try:
- yield <value>
- finally:
- <cleanup>
-
- This makes this:
-
- with some_generator(<arguments>) as <variable>:
- <body>
-
- equivalent to this:
-
- <setup>
- try:
- <variable> = <value>
- <body>
- finally:
- <cleanup>
-
- """
- @wraps(func)
- def helper(*args, **kwds):
- return _GeneratorContextManager(func, args, kwds)
- return helper
-
-
-class closing(AbstractContextManager):
- """Context to automatically close something at the end of a block.
-
- Code like this:
-
- with closing(<module>.open(<arguments>)) as f:
- <block>
-
- is equivalent to this:
-
- f = <module>.open(<arguments>)
- try:
- <block>
- finally:
- f.close()
-
- """
- def __init__(self, thing):
- self.thing = thing
- def __enter__(self):
- return self.thing
- def __exit__(self, *exc_info):
- self.thing.close()
-
-
-class _RedirectStream(AbstractContextManager):
-
- _stream = None
-
- def __init__(self, new_target):
- self._new_target = new_target
- # We use a list of old targets to make this CM re-entrant
- self._old_targets = []
-
- def __enter__(self):
- self._old_targets.append(getattr(sys, self._stream))
- setattr(sys, self._stream, self._new_target)
- return self._new_target
-
- def __exit__(self, exctype, excinst, exctb):
- setattr(sys, self._stream, self._old_targets.pop())
-
-
-class redirect_stdout(_RedirectStream):
- """Context manager for temporarily redirecting stdout to another file.
-
- # How to send help() to stderr
- with redirect_stdout(sys.stderr):
- help(dir)
-
- # How to write help() to a file
- with open('help.txt', 'w') as f:
- with redirect_stdout(f):
- help(pow)
- """
-
- _stream = "stdout"
-
-
-class redirect_stderr(_RedirectStream):
- """Context manager for temporarily redirecting stderr to another file."""
-
- _stream = "stderr"
-
-
-class suppress(AbstractContextManager):
- """Context manager to suppress specified exceptions
-
- After the exception is suppressed, execution proceeds with the next
- statement following the with statement.
-
- with suppress(FileNotFoundError):
- os.remove(somefile)
- # Execution still resumes here if the file was already removed
- """
-
- def __init__(self, *exceptions):
- self._exceptions = exceptions
-
- def __enter__(self):
- pass
-
- def __exit__(self, exctype, excinst, exctb):
- # Unlike isinstance and issubclass, CPython exception handling
- # currently only looks at the concrete type hierarchy (ignoring
- # the instance and subclass checking hooks). While Guido considers
- # that a bug rather than a feature, it's a fairly hard one to fix
- # due to various internal implementation details. suppress provides
- # the simpler issubclass based semantics, rather than trying to
- # exactly reproduce the limitations of the CPython interpreter.
- #
- # See http://bugs.python.org/issue12029 for more details
- return exctype is not None and issubclass(exctype, self._exceptions)
-
-
-# Inspired by discussions on http://bugs.python.org/issue13585
-class ExitStack(AbstractContextManager):
- """Context manager for dynamic management of a stack of exit callbacks
-
- For example:
-
- with ExitStack() as stack:
- files = [stack.enter_context(open(fname)) for fname in filenames]
- # All opened files will automatically be closed at the end of
- # the with statement, even if attempts to open files later
- # in the list raise an exception
-
- """
- def __init__(self):
- self._exit_callbacks = deque()
-
- def pop_all(self):
- """Preserve the context stack by transferring it to a new instance"""
- new_stack = type(self)()
- new_stack._exit_callbacks = self._exit_callbacks
- self._exit_callbacks = deque()
- return new_stack
-
- def _push_cm_exit(self, cm, cm_exit):
- """Helper to correctly register callbacks to __exit__ methods"""
- def _exit_wrapper(*exc_details):
- return cm_exit(cm, *exc_details)
- _exit_wrapper.__self__ = cm
- self.push(_exit_wrapper)
-
- def push(self, exit):
- """Registers a callback with the standard __exit__ method signature
-
- Can suppress exceptions the same way __exit__ methods can.
-
- Also accepts any object with an __exit__ method (registering a call
- to the method instead of the object itself)
- """
- # We use an unbound method rather than a bound method to follow
- # the standard lookup behavior for special methods
- _cb_type = type(exit)
- try:
- exit_method = _cb_type.__exit__
- except AttributeError:
- # Not a context manager, so assume its a callable
- self._exit_callbacks.append(exit)
- else:
- self._push_cm_exit(exit, exit_method)
- return exit # Allow use as a decorator
-
- def callback(self, callback, *args, **kwds):
- """Registers an arbitrary callback and arguments.
-
- Cannot suppress exceptions.
- """
- def _exit_wrapper(exc_type, exc, tb):
- callback(*args, **kwds)
- # We changed the signature, so using @wraps is not appropriate, but
- # setting __wrapped__ may still help with introspection
- _exit_wrapper.__wrapped__ = callback
- self.push(_exit_wrapper)
- return callback # Allow use as a decorator
-
- def enter_context(self, cm):
- """Enters the supplied context manager
-
- If successful, also pushes its __exit__ method as a callback and
- returns the result of the __enter__ method.
- """
- # We look up the special methods on the type to match the with statement
- _cm_type = type(cm)
- _exit = _cm_type.__exit__
- result = _cm_type.__enter__(cm)
- self._push_cm_exit(cm, _exit)
- return result
-
- def close(self):
- """Immediately unwind the context stack"""
- self.__exit__(None, None, None)
-
- def __exit__(self, *exc_details):
- received_exc = exc_details[0] is not None
-
- # We manipulate the exception state so it behaves as though
- # we were actually nesting multiple with statements
- frame_exc = sys.exc_info()[1]
- def _fix_exception_context(new_exc, old_exc):
- # Context may not be correct, so find the end of the chain
- while 1:
- exc_context = new_exc.__context__
- if exc_context is old_exc:
- # Context is already set correctly (see issue 20317)
- return
- if exc_context is None or exc_context is frame_exc:
- break
- new_exc = exc_context
- # Change the end of the chain to point to the exception
- # we expect it to reference
- new_exc.__context__ = old_exc
-
- # Callbacks are invoked in LIFO order to match the behavior of
- # nested context managers
- suppressed_exc = False
- pending_raise = False
- while self._exit_callbacks:
- cb = self._exit_callbacks.pop()
- try:
- if cb(*exc_details):
- suppressed_exc = True
- pending_raise = False
- exc_details = (None, None, None)
- except:
- new_exc_details = sys.exc_info()
- # simulate the stack of exceptions by setting the context
- _fix_exception_context(new_exc_details[1], exc_details[1])
- pending_raise = True
- exc_details = new_exc_details
- if pending_raise:
- try:
- # bare "raise exc_details[1]" replaces our carefully
- # set-up context
- fixed_ctx = exc_details[1].__context__
- raise exc_details[1]
- except BaseException:
- exc_details[1].__context__ = fixed_ctx
- raise
- return received_exc and suppressed_exc
diff --git a/sources/shiboken2/shibokenmodule/support/signature/mapping.py b/sources/shiboken2/shibokenmodule/support/signature/mapping.py
deleted file mode 100644
index d4c630ac..00000000
--- a/sources/shiboken2/shibokenmodule/support/signature/mapping.py
+++ /dev/null
@@ -1,347 +0,0 @@
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
-
-from __future__ import print_function, absolute_import
-
-"""
-mapping.py
-
-This module has the mapping from the pyside C-modules view of signatures
-to the Python representation.
-
-The PySide modules are not loaded in advance, but only after they appear
-in sys.modules. This minimizes the loading overhead.
-"""
-
-import sys
-import struct
-import os
-import pkgutil
-
-from signature_loader import typing
-from signature_loader.typing import TypeVar, Generic
-
-class ellipsis(object):
- def __repr__(self):
- return "..."
-
-ellipsis = ellipsis()
-StringList = typing.List[str]
-IntList = typing.List[int]
-Point = typing.Tuple[float, float]
-PointList = typing.List[Point]
-IntMatrix = typing.List[IntList]
-Variant = typing.Any
-ModelIndexList = typing.List[int]
-QImageCleanupFunction = typing.Callable
-
-# First time installing our own Pair type into typing.
-T = TypeVar('T')
-S = TypeVar('S')
-
-class Pair(Generic[T, S]):
- __module__ = "typing"
-
-typing.Pair = Pair
-
-
-# Building our own Char type, which is much nicer than
-# Char = typing.Union[str, int] # how do I model the limitation to 1 char?
-
-# Copied from the six module:
-def with_metaclass(meta, *bases):
- """Create a base class with a metaclass."""
- # This requires a bit of explanation: the basic idea is to make a dummy
- # metaclass for one level of class instantiation that replaces itself with
- # the actual metaclass.
- class metaclass(type):
-
- def __new__(cls, name, this_bases, d):
- return meta(name, bases, d)
-
- @classmethod
- def __prepare__(cls, name, this_bases):
- return meta.__prepare__(name, bases)
- return type.__new__(metaclass, 'temporary_class', (), {})
-
-class _CharMeta(type):
- def __repr__(self):
- return '%s.%s' % (self.__module__, self.__name__)
-
-
-class Char(with_metaclass(_CharMeta)):
- """
- From http://doc.qt.io/qt-5/qchar.html :
-
- In Qt, Unicode characters are 16-bit entities without any markup or
- structure. This class represents such an entity. It is lightweight,
- so it can be used everywhere. Most compilers treat it like an
- unsigned short.
-
- Here, we provide a simple implementation just to avoid long aliases.
- """
- __module__ = "typing"
-
- def __init__(self, code):
- if isinstance(code, int):
- self.code = code & 0xffff
- else:
- self.code = ord(code)
-
- def __add__(self, other):
- return chr(self.code) + other
-
- def __radd__(self, other):
- return other + chr(self.code)
-
- def __repr__(self):
- return "typing.Char({})".format(self.code)
-
-typing.Char = Char
-
-
-MultiMap = typing.DefaultDict[str, typing.List[str]]
-
-# ulong_max is only 32 bit on windows.
-ulong_max = 2*sys.maxsize+1 if len(struct.pack("L", 1)) != 4 else 0xffffffff
-ushort_max = 0xffff
-
-GL_COLOR_BUFFER_BIT = 0x00004000
-GL_NEAREST = 0x2600
-
-WId = int
-
-# from 5.9
-GL_TEXTURE_2D = 0x0DE1
-GL_RGBA = 0x1908
-
-
-class _NotCalled(str):
- """
- Wrap some text with semantics
-
- This class is wrapped around text in order to avoid calling it.
- There are three reasons for this:
-
- - some instances cannot be created since they are abstract,
- - some can only be created after qApp was created,
- - some have an ugly __repr__ with angle brackets in it.
-
- By using derived classes, good looking instances can be created
- which can be used to generate source code or .pyi files. When the
- real object is needed, the wrapper can simply be called.
- """
- def __repr__(self):
- suppress = "support.signature.typing27."
- text = self[len(suppress):] if self.startswith(suppress) else self
- return "{}({})".format(type(self).__name__, text)
-
- def __call__(self):
- from signature_loader.mapping import __dict__ as namespace
- text = self if self.endswith(")") else self + "()"
- return eval(text, namespace)
-
-USE_PEP563 = sys.version_info[:2] >= (3, 7)
-
-
-# Some types are abstract. They just show their name.
-class Virtual(_NotCalled):
- pass
-
-# Other types I simply could not find.
-class Missing(_NotCalled):
- if not USE_PEP563:
- # The string must be quoted, because the object does not exist.
- def __repr__(self):
- return '{}("{}")'.format(type(self).__name__, self)
-
-
-class Invalid(_NotCalled):
- pass
-
-# Helper types
-class Default(_NotCalled):
- pass
-
-
-class Instance(_NotCalled):
- pass
-
-
-class Reloader(object):
- """
- Reloder class
-
- This is a singleton class which provides the update function for the
- shiboken and PySide classes.
- """
- ## Note: We needed to rename shiboken2 in order to avoid a name clash.
- _uninitialized = "Shiboken minimal sample other smart".split()
- _prefixes = [""]
-
- def __init__(self):
- self.sys_module_count = 0
- self.uninitialized = self._uninitialized
-
- def update(self, g=None):
- """
- update is responsible to import all modules from shiboken and PySide
- which are already in sys.modules.
- The purpose is to follow all user imports without introducing new
- ones.
- This function is called by pyside_type_init to adapt imports
- when the number of imported modules has changed.
- """
- if self.sys_module_count == len(sys.modules):
- return
- self.sys_module_count = len(sys.modules)
- if g is None:
- g = globals()
- for mod_name in self.uninitialized[:]:
- for prefix in self._prefixes:
- import_name = prefix + mod_name
- if import_name in sys.modules:
- # check if this is a real module
- check_module(sys.modules[import_name])
- # module is real
- self.uninitialized.remove(mod_name)
- proc_name = "init_" + mod_name
- if proc_name in g:
- # Do the 'import {import_name}' first.
- # 'top' is PySide2 when we do 'import PySide.QtCore'
- # or Shiboken if we do 'import Shiboken'.
- # Convince yourself that these two lines below have the same
- # global effect as "import Shiboken" or "import PySide2.QtCore".
- top = __import__(import_name)
- g[top.__name__] = top
- # Modules are in place, we can update the type_map.
- g.update(g[proc_name]())
-
-def check_module(mod):
- # During a build, there exist the modules already as directories,
- # although the '*.so' was not yet created. This causes a problem
- # in Python 3, because it accepts folders as namespace modules
- # without enforcing an '__init__.py'.
- if not getattr(mod, "__file__", None) or os.path.isdir(mod.__file__):
- mod_name = mod.__name__
- raise ImportError("Module '{mod_name}' is at most a namespace!"
- .format(**locals()))
-
-
-update_mapping = Reloader().update
-type_map = {}
-namespace = globals() # our module's __dict__
-
-type_map.update({
- "QList": typing.List,
- "QVector": typing.List,
- "QSet": typing.Set,
- "QPair": Pair,
- })
-
-
-def init_Shiboken():
- type_map.update({
- "shiboken2.bool": bool,
- "size_t": int,
- "PyType": type,
- })
- return locals()
-
-
-def init_minimal():
- type_map.update({
- "MinBool": bool,
- })
- return locals()
-
-
-def init_sample():
- import datetime
- type_map.update({
- "double": float,
- "sample.int": int,
- "Complex": complex,
- "sample.OddBool": bool,
- "sample.bool": bool,
- "sample.PStr": str,
- "OddBool": bool,
- "PStr": str,
- "char": Char,
- "sample.char": Char,
- "sample.Point": Point,
- "sample.ObjectType": object,
- "std.string": str,
- "HANDLE": int,
- "Foo.HANDLE": int,
- "sample.Photon.TemplateBase": Missing("sample.Photon.TemplateBase"),
- "ObjectType.Identifier": Missing("sample.ObjectType.Identifier"),
- "zero(HANDLE)": 0,
- "Null": None,
- "zero(sample.ObjectType)": None,
- "std.size_t": int,
- 'Str("<unknown>")': "<unknown>",
- 'Str("<unk")': "<unk",
- 'Str("nown>")': "nown>",
- "zero(sample.ObjectModel)": None,
- "sample.unsigned char": Char,
- "sample.double": float,
- "zero(sample.bool)": False,
- "PyDate": datetime.date,
- "ZeroIn": 0,
- })
- return locals()
-
-
-def init_other():
- import numbers
- type_map.update({
- "other.Number": numbers.Number,
- "other.ExtendsNoImplicitConversion": Missing("other.ExtendsNoImplicitConversion"),
- })
- return locals()
-
-
-def init_smart():
- type_map.update({
- "smart.SharedPtr": Missing("smart.SharedPtr"), # bad object "SharedPtr<Obj >"
- })
- return locals()
-
-# end of file