diff options
author | Shyamnath Premnadh <shyamnath.premnadh@qt.io> | 2023-04-04 16:18:47 +0200 |
---|---|---|
committer | Shyamnath Premnadh <shyamnath.premnadh@qt.io> | 2023-04-17 11:12:55 +0200 |
commit | 0e40c7af91df19a2ac20d88b55d4ef4d71845c55 (patch) | |
tree | b1002ad68cba00384ea0ee5c390c088ea630afe1 /sources/pyside-tools/deploy_lib | |
parent | b80c7822c61b70d9704b42db64db0d9637fa7079 (diff) |
Deployment: Refactoring
- Fix --dry-run in Android deployment
- Add option to control raising a warning when adding new entries
to config file
- Remove unnecessary code and comments
Pick-to: 6.5
Task-number: PYSIDE-1612
Change-Id: I5975d76024d6289fe6b9af1caeca374acb81e8cc
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib')
-rw-r--r-- | sources/pyside-tools/deploy_lib/android/android_helper.py | 10 | ||||
-rw-r--r-- | sources/pyside-tools/deploy_lib/android/buildozer.py | 14 | ||||
-rw-r--r-- | sources/pyside-tools/deploy_lib/config.py | 23 | ||||
-rw-r--r-- | sources/pyside-tools/deploy_lib/deploy_util.py | 21 |
4 files changed, 40 insertions, 28 deletions
diff --git a/sources/pyside-tools/deploy_lib/android/android_helper.py b/sources/pyside-tools/deploy_lib/android/android_helper.py index b0c8254ab..b93fcdbdc 100644 --- a/sources/pyside-tools/deploy_lib/android/android_helper.py +++ b/sources/pyside-tools/deploy_lib/android/android_helper.py @@ -30,7 +30,7 @@ def create_recipe(version: str, component: str, wheel_path: str, generated_files recipe_path = generated_files_path / "recipes" / f"{component}" recipe_path.mkdir(parents=True, exist_ok=True) - logging.info(f"Writing {component} recipe into {recipe_path}") + logging.info(f"[DEPLOY] Writing {component} recipe into {recipe_path}") with open(recipe_path / "__init__.py", mode="w", encoding="utf-8") as recipe: recipe.write(content) @@ -38,7 +38,7 @@ def create_recipe(version: str, component: str, wheel_path: str, generated_files def extract_and_copy_jar(wheel_path: Path, generated_files_path: Path) -> str: ''' extracts the PySide6 wheel and copies the 'jar' folder to 'generated_files_path'. - These .jar files are added to the buildozer.spec file to be later use by buildozer + These .jar files are added to the buildozer.spec file to be used later by buildozer ''' jar_path = generated_files_path / "jar" jar_path.mkdir(parents=True, exist_ok=True) @@ -49,8 +49,10 @@ def extract_and_copy_jar(wheel_path: Path, generated_files_path: Path) -> str: return jar_path -def get_wheel_android_arch(wheel: str): - wheel = Path(wheel) +def get_wheel_android_arch(wheel: Path): + ''' + Get android architecture from wheel + ''' supported_archs = ["aarch64", "armv7a", "i686", "x86_64"] for arch in supported_archs: if arch in wheel.stem: diff --git a/sources/pyside-tools/deploy_lib/android/buildozer.py b/sources/pyside-tools/deploy_lib/android/buildozer.py index 91d55f4ca..2ebd49d1a 100644 --- a/sources/pyside-tools/deploy_lib/android/buildozer.py +++ b/sources/pyside-tools/deploy_lib/android/buildozer.py @@ -7,8 +7,8 @@ from .. import run_command, BaseConfig, Config class BuildozerConfig(BaseConfig): - def __init__(self, buildozer_spec_file: Path, pysidedeploy_config: Config, dry_run: bool): - super().__init__(buildozer_spec_file, dry_run, comment_prefixes="#") + def __init__(self, buildozer_spec_file: Path, pysidedeploy_config: Config): + super().__init__(buildozer_spec_file, comment_prefixes="#") self.set_value("app", "title", pysidedeploy_config.title) self.set_value("app", "package.name", pysidedeploy_config.title) self.set_value("app", "package.domain", @@ -16,7 +16,7 @@ class BuildozerConfig(BaseConfig): include_exts = self.get_value("app", "source.include_exts") include_exts = f"{include_exts},qml" - self.set_value("app", "source.include_exts", include_exts) + self.set_value("app", "source.include_exts", include_exts, raise_warning=False) self.set_value("app", "requirements", "python3,shiboken6,PySide6") @@ -73,12 +73,12 @@ class Buildozer: # creates buildozer.spec config file command = ["buildozer", "init"] run_command(command=command, dry_run=Buildozer.dry_run) - if not Buildozer.dry_run and not buildozer_spec.exists(): - raise RuntimeError(f"buildozer.spec not found in {Path.cwd()}") - BuildozerConfig(buildozer_spec, pysidedeploy_config, Buildozer.dry_run) + if not Buildozer.dry_run: + if not buildozer_spec.exists(): + raise RuntimeError(f"buildozer.spec not found in {Path.cwd()}") + BuildozerConfig(buildozer_spec, pysidedeploy_config) @staticmethod def create_executable(mode: str): - # build the application in release mode command = ["buildozer", "android", mode] run_command(command=command, dry_run=Buildozer.dry_run) diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py index 781c2155d..af019a093 100644 --- a/sources/pyside-tools/deploy_lib/config.py +++ b/sources/pyside-tools/deploy_lib/config.py @@ -4,7 +4,6 @@ from pathlib import Path import configparser from configparser import ConfigParser -import shutil import logging from project import ProjectData @@ -17,17 +16,11 @@ EXCLUDED_QML_PLUGINS = {"QtQuick", "QtQuick3D", "QtCharts", "QtWebEngine", "QtTe class BaseConfig: - def __init__(self, config_file: Path, dry_run: bool, comment_prefixes: str = "/") -> None: + def __init__(self, config_file: Path, comment_prefixes: str = "/") -> None: self.config_file = config_file self.parser = ConfigParser(comment_prefixes=comment_prefixes, allow_no_value=True) - if not self.config_file.exists(): - if not dry_run: - logging.info(f"[DEPLOY] Creating config file {self.config_file}") - shutil.copy(Path(__file__).parent / "default.spec", self.config_file) - else: - self.config_file = Path(__file__).parent / "default.spec" - else: - logging.info(f"Using existing config file {config_file}") + if not config_file.exists(): + raise RuntimeError(f"[DEPLOY] {config_file} does not exist") self.parser.read(self.config_file) def update_config(self): @@ -35,15 +28,17 @@ class BaseConfig: with open(self.config_file, "w+") as config_file: self.parser.write(config_file, space_around_delimiters=True) - def set_value(self, section: str, key: str, new_value: str): + def set_value(self, section: str, key: str, new_value: str, raise_warning: bool = True): try: current_value = self.get_value(section, key, ignore_fail=True) if current_value != new_value: self.parser.set(section, key, new_value) except configparser.NoOptionError: - logging.warning(f"[DEPLOY] Key {key} does not exist") + if raise_warning: + logging.warning(f"[DEPLOY] Key {key} does not exist") except configparser.NoSectionError: - logging.warning(f"[DEPLOY] Section {section} does not exist") + if raise_warning: + logging.warning(f"[DEPLOY] Section {section} does not exist") def get_value(self, section: str, key: str, ignore_fail: bool = False): try: @@ -64,7 +59,7 @@ class Config(BaseConfig): def __init__(self, config_file: Path, source_file: Path, python_exe: Path, dry_run: bool, android_data, is_android: bool): - super().__init__(config_file, dry_run) + super().__init__(config_file) self._dry_run = dry_run # set source_file diff --git a/sources/pyside-tools/deploy_lib/deploy_util.py b/sources/pyside-tools/deploy_lib/deploy_util.py index de545e3a5..bb986344c 100644 --- a/sources/pyside-tools/deploy_lib/deploy_util.py +++ b/sources/pyside-tools/deploy_lib/deploy_util.py @@ -42,16 +42,31 @@ def cleanup(generated_files_path: Path, config: Config, is_android: bool = False def get_config(python_exe: Path, dry_run: bool = False, config_file: Path = None, main_file: - Path = None, android_data = None, is_android: bool = False): + Path = None, android_data=None, is_android: bool = False): """ - Sets up a new deployment configuration or use an existing config file + Sets up a new pysidedeploy.spec or use an existing config file """ - if main_file and not config_file: + + config_file_exists = config_file and Path(config_file).exists() + + if main_file and not config_file_exists: if main_file.parent != Path.cwd(): config_file = main_file.parent / "pysidedeploy.spec" else: config_file = Path.cwd() / "pysidedeploy.spec" + if config_file_exists: + logging.info(f"[DEPLOY] Using existing config file {config_file}") + else: + logging.info(f"[DEPLOY] Creating config file {config_file}") + if not dry_run: + shutil.copy(Path(__file__).parent / "default.spec", config_file) + + # the config parser needs a reference to parse. So, in the case of --dry-run + # use the default.spec file. + if dry_run and not config_file_exists: + config_file = Path(__file__).parent / "default.spec" + config = Config(config_file=config_file, source_file=main_file, python_exe=python_exe, dry_run=dry_run, android_data=android_data, is_android=is_android) |