aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/deploy_lib/design_studio.py
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-09-20 17:00:39 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-10-07 13:54:03 +0200
commit1e5fe140b485209a30d7dd38b3334440c58cbb05 (patch)
tree43511980e289c57b6208ad0bf9b0c09ea58a483e /sources/pyside-tools/deploy_lib/design_studio.py
parent9a10caa1e22773ce7563f82680c67596293178e4 (diff)
Deployment: Support Design Studio projects
- new class 'DesignStudio' to handle Design Studio projects. - Currently uses a way of monkey patching to override the 'main.py' to use 'main_patch.py' which has the same content but with 'app_dir' set to the parent of `main.py``. The reason for doing this is that Nuitka requires the `main.py` to be in the same directory as other resources required for the project. Once the corresponding patch, to alternate between evaluating 'app_dir' based on whether the application is deployed or called through the Python interpreter, is merged then this temporary fix of creating 'main_patch.py' can be removed. - Add tests. Pick-to: 6.7 Change-Id: I79e6572bdbbf4576fbdd9039a4922997a22139f8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib/design_studio.py')
-rw-r--r--sources/pyside-tools/deploy_lib/design_studio.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/sources/pyside-tools/deploy_lib/design_studio.py b/sources/pyside-tools/deploy_lib/design_studio.py
new file mode 100644
index 000000000..1fc1a4cc8
--- /dev/null
+++ b/sources/pyside-tools/deploy_lib/design_studio.py
@@ -0,0 +1,57 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+import logging
+import atexit
+from pathlib import Path
+
+# FIXME: Remove this idea of creating main_patch.py once the corresponding changes are
+# made in Design Studio main.py file:
+# if '__compiled__' in globals(): #nuitka
+# app_dir = Path(__file__).parent
+# else:
+# app_dir = Path(__file__).parent.parent
+
+
+class DesignStudio:
+ """
+ Class to handle Design Studio projects
+ """
+
+ def __init__(self, main_file: Path):
+ self.ds_project_dir = main_file.parent.parent
+ self.current_main_file = main_file
+ self.new_main_file = main_file.parent / 'main_patch.py'
+ self._create_new_main_file()
+ atexit.register(self._delete_main_patch_file)
+
+ def _create_new_main_file(self):
+ # read the content of main file
+ content = ""
+ with open(self.current_main_file, 'r', encoding='utf-8') as main_file:
+ content = main_file.read()
+
+ # replace app_dir
+ content = content.replace("app_dir = Path(__file__).parent.parent", # old value
+ "app_dir = Path(__file__).parent") # new value
+
+ # write the content to new main file
+ with open(self.new_main_file, 'w', encoding="utf-8") as main_file:
+ main_file.write(content)
+
+ def _delete_main_patch_file(self):
+ if self.new_main_file.exists():
+ logging.info(f"[DEPLOY] Removing {self.new_main_file}")
+ self.new_main_file.unlink()
+
+ @staticmethod
+ def isDSProject(main_file: Path) -> bool:
+ return (main_file.parent / 'autogen/settings.py').exists()
+
+ @property
+ def project_dir(self) -> str:
+ return self.ds_project_dir
+
+ @property
+ def ds_source_file(self) -> Path:
+ return self.new_main_file