aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/libshiboken
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2019-02-26 09:44:01 +0100
committerChristian Tismer <tismer@stackless.com>2019-03-20 17:33:21 +0000
commite8786b9cdccb63aa590af50fe5fa5496c6b216c7 (patch)
tree89f30d78603c81937f0c6dd9f768576b6463f9f7 /sources/shiboken2/libshiboken
parentc32dacab85b435751db2811e7a88d5c03b1856e1 (diff)
Simplify Python Imports For Embedding
After the project split, shiboken exposed its own modules, and the overall structure with shiboken2.support.signature and PySide2.support.signature was already quite complicated. When introducing embedding, it is necessary to have some support folder that gets unpacked from a zipfile. That means, the shiboken2 root directory would be in the zip file in the embedding case. This does not only increase the complexity, it further means that we must make shiboken2.so available in the shiboken2 containing zipfile! In order to avoid that, we stop the dependency from the two support directories and use shibokensupport, instead. The simplification of the loader and other modules is also significant. Task-number: PYSIDE-510 Change-Id: Ic735a8d36f10f03698378f2ac9685a5955e40b0c Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/libshiboken')
-rw-r--r--sources/shiboken2/libshiboken/CMakeLists.txt9
-rw-r--r--sources/shiboken2/libshiboken/signature.cpp30
2 files changed, 22 insertions, 17 deletions
diff --git a/sources/shiboken2/libshiboken/CMakeLists.txt b/sources/shiboken2/libshiboken/CMakeLists.txt
index 79f83ec73..636d8c01b 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 cd00a1482..a99927c15 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");