diff options
author | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-07-02 11:55:45 +0200 |
---|---|---|
committer | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-07-08 13:25:49 +0200 |
commit | e3ca9d63fd21867ad974928162a62832b36f807d (patch) | |
tree | 4d02de4746b4cfb44d18e50d1c59b309a55452e2 /sources/pyside-tools | |
parent | cecf63e72a85a33fd1163b1a13262357e7a43819 (diff) |
Desktop Deployment: Ignore directories
- Among the directories ".qtcreator", "site-packages", "deployment" etc
were excluded when finding the QML files and the Python files in the
project.
- Simplify find_and_set_qml_files(self) function by removing the
unnecessary code.
- Memoize pyside_module_imports().
Pick-to: 6.7
Task-number: PYSIDE-1612
Change-Id: I55ccb67300c27de73843ad9996da655ba04403fb
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools')
-rw-r--r-- | sources/pyside-tools/deploy_lib/__init__.py | 2 | ||||
-rw-r--r-- | sources/pyside-tools/deploy_lib/config.py | 29 | ||||
-rw-r--r-- | sources/pyside-tools/deploy_lib/dependency_util.py | 5 |
3 files changed, 14 insertions, 22 deletions
diff --git a/sources/pyside-tools/deploy_lib/__init__.py b/sources/pyside-tools/deploy_lib/__init__.py index b8f9ba659..98179ecf0 100644 --- a/sources/pyside-tools/deploy_lib/__init__.py +++ b/sources/pyside-tools/deploy_lib/__init__.py @@ -18,6 +18,8 @@ else: EXE_FORMAT = ".bin" DEFAULT_APP_ICON = str((Path(__file__).parent / f"pyside_icon{IMAGE_FORMAT}").resolve()) +DEFAULT_IGNORE_DIRS = ["site-packages", "deployment", ".qtcreator", "build", "dist", "tests"] + IMPORT_WARNING_PYSIDE = (f"[DEPLOY] Found 'import PySide6' in file {0}" ". Use 'from PySide6 import <module>' or pass the module" " needed using --extra-modules command line argument") diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py index 23d037dca..777290155 100644 --- a/sources/pyside-tools/deploy_lib/config.py +++ b/sources/pyside-tools/deploy_lib/config.py @@ -11,8 +11,8 @@ from pathlib import Path from enum import Enum from project import ProjectData -from . import (DEFAULT_APP_ICON, find_pyside_modules, find_permission_categories, - QtDependencyReader, run_qmlimportscanner) +from . import (DEFAULT_APP_ICON, DEFAULT_IGNORE_DIRS, find_pyside_modules, + find_permission_categories, QtDependencyReader, run_qmlimportscanner) # Some QML plugins like QtCore are excluded from this list as they don't contribute much to # executable size. Excluding them saves the extra processing of checking for them in files @@ -262,24 +262,12 @@ class Config(BaseConfig): qml_files_temp = None if self.source_file and self.python_path: if not self.qml_files: - qml_files_temp = list(self.source_file.parent.glob("**/*.qml")) - - # add all QML files, excluding the ones shipped with installed PySide6 - # The QML files shipped with PySide6 gets added if venv is used, - # because of recursive glob - if self.python_path.parent.parent == self.source_file.parent: - # python venv path is inside the main source dir - qml_files_temp = list( - set(qml_files_temp) - set(self.python_path.parent.parent.rglob("*.qml")) - ) - - if len(qml_files_temp) > 500: - if "site-packages" in str(qml_files_temp[-1]): - raise RuntimeError( - "You are including a lot of QML files from a local virtual env." - " This can lead to errors in deployment." - ) - else: + # filter out files from DEFAULT_IGNORE_DIRS + qml_files_temp = [file for file in self.source_file.parent.glob("**/*.qml") + if all(part not in file.parts for part in + DEFAULT_IGNORE_DIRS)] + + if len(qml_files_temp) > 500: warnings.warn( "You seem to include a lot of QML files. This can lead to errors in " "deployment." @@ -288,6 +276,7 @@ class Config(BaseConfig): if qml_files_temp: extra_qml_files = [Path(file) for file in qml_files_temp] self.qml_files.extend(extra_qml_files) + if self.qml_files: self.set_value( "qt", diff --git a/sources/pyside-tools/deploy_lib/dependency_util.py b/sources/pyside-tools/deploy_lib/dependency_util.py index 30a336f0a..6cab75cfc 100644 --- a/sources/pyside-tools/deploy_lib/dependency_util.py +++ b/sources/pyside-tools/deploy_lib/dependency_util.py @@ -14,7 +14,7 @@ import sys from pathlib import Path from functools import lru_cache -from . import IMPORT_WARNING_PYSIDE, run_command +from . import IMPORT_WARNING_PYSIDE, DEFAULT_IGNORE_DIRS, run_command @lru_cache(maxsize=None) @@ -22,7 +22,7 @@ def get_py_files(project_dir: Path, extra_ignore_dirs: list[Path] = None, projec """Finds and returns all the Python files in the project """ py_candidates = [] - ignore_dirs = ["__pycache__", "env", "venv", "deployment"] + ignore_dirs = ["__pycache__", *DEFAULT_IGNORE_DIRS] if project_data: py_candidates = project_data.python_files @@ -135,6 +135,7 @@ def find_pyside_modules(project_dir: Path, extra_ignore_dirs: list[Path] = None, all_modules = set() mod_pattern = re.compile("PySide6.Qt(?P<mod_name>.*)") + @lru_cache def pyside_module_imports(py_file: Path): modules = [] try: |