aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2023-01-10 15:07:18 +0100
committerChristian Tismer <tismer@stackless.com>2023-01-11 17:37:31 +0100
commitc8b8d0868bafe25e11f48ddc7a928ca1d47879ae (patch)
treeba81355fce431c92813c5bfbdfdd986dc3696524
parent4c2c58511df05febd7f51fe41c8e377435f9271e (diff)
shiboken: de-virtualize the Python files
Since a while, the virtualization of the Python helper modules in Shiboken is successfully active. This patch de-virtualizes the files by creating them under the shiboken6 directory, but only after a successful first start of shiboken/PySide. On subsequent runs, the unpacked files will stay. This way, the files are still safe against configuration problems. They are no longer safe against tampering. As an advantage, they can now easily be modified, and source code debugging will work, again. A simple reset can be done by clearing the files.dir folder. Task-number: PYSIDE-962 Change-Id: I7bc003388c4d8a424faab9d7a87908bc05c4ecfb Fixes: PYSIDE-1994 Pick-to: 6.4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/shiboken6/libshiboken/embed/signature_bootstrap.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/sources/shiboken6/libshiboken/embed/signature_bootstrap.py b/sources/shiboken6/libshiboken/embed/signature_bootstrap.py
index c11a0367a..72c042b46 100644
--- a/sources/shiboken6/libshiboken/embed/signature_bootstrap.py
+++ b/sources/shiboken6/libshiboken/embed/signature_bootstrap.py
@@ -26,6 +26,7 @@ recursion_trap = 0
import base64
import importlib
import io
+import os
import sys
import traceback
import zipfile
@@ -71,11 +72,44 @@ def bootstrap():
sys.exit(-1)
target.remove(support_path)
- target, support_path = prepare_zipfile()
+ # Here we decide if re we-incarnate the embedded files or use embedding.
+ incarnated = re_incarnate_files()
+ if incarnated:
+ target, support_path = sys.path, os.fspath(incarnated)
+ else:
+ target, support_path = prepare_zipfile()
+ # PYSIDE-962: pre-load needed after re_incarnate_files [Windows, Py3.7.9]
+ ensure_shibokensupport(target, support_path)
with ensure_shibokensupport(target, support_path):
from shibokensupport.signature import loader
return loader
+# Newer functionality:
+# This function checks if the support directory exist and returns it.
+# If does not exist, we try to create it and return it.
+# Otherwise, we return None.
+
+def re_incarnate_files():
+ import shiboken6 as root
+ files_dir = Path(root.__file__).resolve().parent / "files.dir"
+ if files_dir.exists():
+ return files_dir
+
+ target, zip = prepare_zipfile()
+ names = (_ for _ in zip.zfile.namelist() if _.endswith(".py"))
+ try:
+ # first check mkdir to get an error when we cannot write.
+ files_dir.mkdir()
+ except os.error:
+ return None
+ try:
+ # Then check for a real error when unpacking the zip file.
+ zip.zfile.extractall(path=files_dir, members=names)
+ return files_dir
+ except Exception as e:
+ print('Exception:', e)
+ traceback.print_exc(file=sys.stdout)
+ raise
# New functionality: Loading from a zip archive.
# There exists the zip importer, but as it is written, only real zip files are