aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2023-10-02 14:07:40 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2023-10-02 18:20:53 +0200
commit0f98cb69d4e8a2beec64102abef97b46aa7626ba (patch)
treefabe55d998e7190e0d3b8ccbf5f9b30693b00662 /sources/pyside-tools
parent0a1710429333001fbf5a96cdc9043f9ec2f559ba (diff)
Android Deployment: Identify Qt modules from generated Python files
- This patch adds an extra step to check the existence of Python files generated from `pyside6-uic` and `pyside6-qrc` for identifying the imported Qt modules in the application. This only applies when the application has a .pyproject file. When the project does not have a .pyproject file, all the Python files in the application are checked for Qt module imports. The .pyproject file does not consider the generated Python files and hence the need of this patch. - For pyside6-deploy, this patch is irrelevant because Nuitka identifies all the required Python files of the project. Task-number: PYSIDE-1612 Pick-to: 6.6 Change-Id: Ic9a2812c42226b6baebab1b23fac8e410910578e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools')
-rw-r--r--sources/pyside-tools/deploy_lib/python_helper.py26
-rw-r--r--sources/pyside-tools/project/project_data.py17
2 files changed, 43 insertions, 0 deletions
diff --git a/sources/pyside-tools/deploy_lib/python_helper.py b/sources/pyside-tools/deploy_lib/python_helper.py
index af8753257..1a48b0e9a 100644
--- a/sources/pyside-tools/deploy_lib/python_helper.py
+++ b/sources/pyside-tools/deploy_lib/python_helper.py
@@ -6,6 +6,7 @@ import os
import re
import sys
import logging
+import warnings
from typing import List
from importlib import util
if sys.version_info >= (3, 8):
@@ -73,6 +74,31 @@ def find_pyside_modules(project_dir: Path, extra_ignore_dirs: List[Path] = None,
if project_data:
py_candidates = project_data.python_files
+ ui_candidates = project_data.ui_files
+ qrc_candidates = project_data.qrc_files
+ ui_py_candidates = None
+ qrc_ui_candidates = None
+
+ if ui_candidates:
+ ui_py_candidates = [(file.parent / f"ui_{file.stem}.py") for file in ui_candidates
+ if (file.parent / f"ui_{file.stem}.py").exists()]
+
+ if len(ui_py_candidates) != len(ui_candidates):
+ warnings.warn("[DEPLOY] The number of uic files and their corresponding Python"
+ " files don't match.", category=RuntimeWarning)
+
+ py_candidates.extend(ui_py_candidates)
+
+ if qrc_candidates:
+ qrc_ui_candidates = [(file.parent / f"rc_{file.stem}.py") for file in qrc_candidates
+ if (file.parent / f"rc_{file.stem}.py").exists()]
+
+ if len(qrc_ui_candidates) != len(qrc_candidates):
+ warnings.warn("[DEPLOY] The number of qrc files and their corresponding Python"
+ " files don't match.", category=RuntimeWarning)
+
+ py_candidates.extend(qrc_ui_candidates)
+
for py_candidate in py_candidates:
all_modules = all_modules.union(pyside_imports(py_candidate))
return list(all_modules)
diff --git a/sources/pyside-tools/project/project_data.py b/sources/pyside-tools/project/project_data.py
index 4cd30c42b..b8d27f33e 100644
--- a/sources/pyside-tools/project/project_data.py
+++ b/sources/pyside-tools/project/project_data.py
@@ -29,6 +29,10 @@ class ProjectData:
# Python files
self.main_file: Path = None
self._python_files: List[Path] = []
+ # ui files
+ self._ui_files: List[Path] = []
+ # qrc files
+ self._qrc_files: List[Path] = []
with project_file.open("r") as pyf:
pyproject = json.load(pyf)
@@ -44,6 +48,11 @@ class ProjectData:
if file.stem == "main":
self.main_file = file
self._python_files.append(file)
+ elif file.suffix == ".ui":
+ self._ui_files.append(file)
+ elif file.suffix == ".qrc":
+ self._qrc_files.append(file)
+
if not self.main_file:
self._find_main_file()
@@ -68,6 +77,14 @@ class ProjectData:
return self._python_files
@property
+ def ui_files(self):
+ return self._ui_files
+
+ @property
+ def qrc_files(self):
+ return self._qrc_files
+
+ @property
def qml_files(self):
return self._qml_files