aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/deploy_lib/dependency_util.py
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-02-23 14:29:42 +0100
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-03-07 09:34:12 +0100
commitb8d29e0381235785f1726a8cc28b8b7579c32e03 (patch)
treebe9117a904fa7ec1e3713b442b8446a9f82802f0 /sources/pyside-tools/deploy_lib/dependency_util.py
parent94c62891f9aa28c53f8c0a86904499ead4d52aad (diff)
Desktop Deployment: Optimize the plugins included
- Applications that use certain modules like Multimedia does not work because the plugins for it were not included. However, including all the plugins can make the application executable huge. This patch filters out the necessary plugins by looking at PySide6_Essentials.json and PySide6_Addons.json shipped with the wheels and only bundles these necessary plugins with the application. - Adjust tests. Task-number: PYSIDE-1612 Task-number: PYSIDE-2597 Change-Id: I35c74907a1782ae5101fb7c0861adcb97db5792d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib/dependency_util.py')
-rw-r--r--sources/pyside-tools/deploy_lib/dependency_util.py64
1 files changed, 44 insertions, 20 deletions
diff --git a/sources/pyside-tools/deploy_lib/dependency_util.py b/sources/pyside-tools/deploy_lib/dependency_util.py
index c7821794f..53c12ad92 100644
--- a/sources/pyside-tools/deploy_lib/dependency_util.py
+++ b/sources/pyside-tools/deploy_lib/dependency_util.py
@@ -5,6 +5,7 @@ import ast
import re
import os
import site
+import json
import warnings
import logging
import shutil
@@ -15,25 +16,6 @@ from typing import List, Set
from . import IMPORT_WARNING_PYSIDE, run_command
-def get_qt_libs_dir():
- """
- Finds the path to the Qt libs directory inside PySide6 package installation
- """
- pyside_install_dir = None
- for possible_site_package in site.getsitepackages():
- if possible_site_package.endswith("site-packages"):
- pyside_install_dir = Path(possible_site_package) / "PySide6"
-
- if not pyside_install_dir:
- print("Unable to find site-packages. Exiting ...")
- sys.exit(-1)
-
- if sys.platform == "win32":
- return pyside_install_dir
-
- return pyside_install_dir / "Qt" / "lib" # for linux and macOS
-
-
def find_pyside_modules(project_dir: Path, extra_ignore_dirs: List[Path] = None,
project_data=None):
"""
@@ -164,9 +146,27 @@ class QtDependencyReader:
print(f"[DEPLOY] Deployment on unsupported platfrom {sys.platform}")
sys.exit(1)
- self.qt_libs_dir = get_qt_libs_dir()
+ self.pyside_install_dir = None
+ self.qt_libs_dir = self.get_qt_libs_dir()
self._lib_reader = shutil.which(self.lib_reader_name)
+ def get_qt_libs_dir(self):
+ """
+ Finds the path to the Qt libs directory inside PySide6 package installation
+ """
+ for possible_site_package in site.getsitepackages():
+ if possible_site_package.endswith("site-packages"):
+ self.pyside_install_dir = Path(possible_site_package) / "PySide6"
+
+ if not self.pyside_install_dir:
+ print("Unable to find site-packages. Exiting ...")
+ sys.exit(-1)
+
+ if sys.platform == "win32":
+ return self.pyside_install_dir
+
+ return self.pyside_install_dir / "Qt" / "lib" # for linux and macOS
+
@property
def lib_reader(self):
return self._lib_reader
@@ -216,3 +216,27 @@ class QtDependencyReader:
logging.info(f"[DEPLOY] Following dependencies found for {module}: {dependent_modules}")
else:
logging.info(f"[DEPLOY] No Qt dependencies found for {module}")
+
+ def find_plugin_dependencies(self, used_modules: List[str]) -> List[str]:
+ """
+ Given the modules used by the application, returns all the required plugins
+ """
+ plugins = set()
+ pyside_mod_plugin_jsons = ["PySide6_Essentials.json", "PySide6_Addons.json"]
+ for pyside_mod_plugin_json_name in pyside_mod_plugin_jsons:
+ pyside_mod_plugin_json_file = self.pyside_install_dir / pyside_mod_plugin_json_name
+ if not pyside_mod_plugin_json_file.exists():
+ warnings.warn(f"[DEPLOY] Unable to find {pyside_mod_plugin_json_file}.",
+ category=RuntimeWarning)
+ continue
+
+ # convert the json to dict
+ pyside_mod_dict = {}
+ with open(pyside_mod_plugin_json_file) as pyside_json:
+ pyside_mod_dict = json.load(pyside_json)
+
+ # find all the plugins in the modules
+ for module in used_modules:
+ plugins.update(pyside_mod_dict.get(module, []))
+
+ return list(plugins)