diff options
| author | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-06-04 15:48:40 +0200 |
|---|---|---|
| committer | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-06-10 10:20:06 +0200 |
| commit | 32e353e9d91f45c23dcb07b0798237c79795cf0a (patch) | |
| tree | 14d6739b4ab6c37882c220fb4a9594004730c186 /sources/pyside-tools/deploy_lib | |
| parent | 527eec228d98f1c8e23f95dc92d6eed4d5a8725a (diff) | |
Desktop Deployment: Enable Nuitka --standalone mode
- enables the standalone mode of Nuitka for pyside6-deploy
- the mode can be set either through the command line or the config file
- adapt tests
- update documentation
Pick-to: 6.7
Fixes: PYSIDE-2622
Task-number: PYSIDE-1612
Change-Id: I5a10c857d3e79174d2643139eb2e4f7b5e10d955
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib')
| -rw-r--r-- | sources/pyside-tools/deploy_lib/config.py | 23 | ||||
| -rw-r--r-- | sources/pyside-tools/deploy_lib/default.spec | 3 | ||||
| -rw-r--r-- | sources/pyside-tools/deploy_lib/deploy_util.py | 16 | ||||
| -rw-r--r-- | sources/pyside-tools/deploy_lib/nuitka_helper.py | 10 |
4 files changed, 43 insertions, 9 deletions
diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py index d59dd92ad..5d5070bef 100644 --- a/sources/pyside-tools/deploy_lib/config.py +++ b/sources/pyside-tools/deploy_lib/config.py @@ -8,6 +8,7 @@ import warnings from configparser import ConfigParser from typing import List from pathlib import Path +from enum import Enum from project import ProjectData from . import (DEFAULT_APP_ICON, find_pyside_modules, find_permission_categories, @@ -375,8 +376,13 @@ class Config(BaseConfig): class DesktopConfig(Config): """Wrapper class around pysidedeploy.spec, but specific to Desktop deployment """ + class NuitkaMode(Enum): + ONEFILE = "onefile" + STANDALONE = "standalone" + def __init__(self, config_file: Path, source_file: Path, python_exe: Path, dry_run: bool, - existing_config_file: bool = False, extra_ignore_dirs: List[str] = None): + existing_config_file: bool = False, extra_ignore_dirs: List[str] = None, + mode: str = "onefile"): super().__init__(config_file, source_file, python_exe, dry_run, existing_config_file, extra_ignore_dirs) self.dependency_reader = QtDependencyReader(dry_run=self.dry_run) @@ -402,6 +408,12 @@ class DesktopConfig(Config): else: self._find_and_set_permissions() + self._mode = self.NuitkaMode.ONEFILE + if self.get_value("nuitka", "mode") == self.NuitkaMode.STANDALONE.value: + self._mode = self.NuitkaMode.STANDALONE + elif mode == self.NuitkaMode.STANDALONE.value: + self.mode = self.NuitkaMode.STANDALONE + @property def qt_plugins(self): return self._qt_plugins @@ -420,6 +432,15 @@ class DesktopConfig(Config): self._permissions = permissions self.set_value("nuitka", "macos.permissions", ",".join(permissions)) + @property + def mode(self): + return self._mode + + @mode.setter + def mode(self, mode: NuitkaMode): + self._mode = mode + self.set_value("nuitka", "mode", mode.value) + def _find_dependent_qt_modules(self): """ Given pysidedeploy_config.modules, find all the other dependent Qt modules. diff --git a/sources/pyside-tools/deploy_lib/default.spec b/sources/pyside-tools/deploy_lib/default.spec index 0a729d585..2e28b2f7c 100644 --- a/sources/pyside-tools/deploy_lib/default.spec +++ b/sources/pyside-tools/deploy_lib/default.spec @@ -65,6 +65,9 @@ plugins = # eg: NSCameraUsageDescription:CameraAccess macos.permissions = +# mode of using Nuitka. Accepts standalone or onefile. Default is onefile. +mode = onefile + # (str) specify any extra nuitka arguments # eg: extra_args = --show-modules --follow-stdlib extra_args = --quiet --noinclude-qt-translations diff --git a/sources/pyside-tools/deploy_lib/deploy_util.py b/sources/pyside-tools/deploy_lib/deploy_util.py index e8b05e990..1e0e2712a 100644 --- a/sources/pyside-tools/deploy_lib/deploy_util.py +++ b/sources/pyside-tools/deploy_lib/deploy_util.py @@ -7,7 +7,7 @@ import sys from pathlib import Path from . import EXE_FORMAT -from .config import Config +from .config import Config, DesktopConfig def config_option_exists(): @@ -61,17 +61,21 @@ def create_config_file(dry_run: bool = False, config_file: Path = None, main_fil return config_file -def finalize(config: Config): +def finalize(config: DesktopConfig): """ Copy the executable into the final location For Android deployment, this is done through buildozer """ - generated_exec_path = config.generated_files_path / (config.source_file.stem + EXE_FORMAT) + dist_format = EXE_FORMAT + if config.mode == DesktopConfig.NuitkaMode.STANDALONE and sys.platform != "darwin": + dist_format = ".dist" + + generated_exec_path = config.generated_files_path / (config.source_file.stem + dist_format) if generated_exec_path.exists() and config.exe_dir: - if sys.platform == "darwin": - shutil.copytree(generated_exec_path, config.exe_dir / (config.title + EXE_FORMAT), + if sys.platform == "darwin" or config.mode == DesktopConfig.NuitkaMode.STANDALONE: + shutil.copytree(generated_exec_path, config.exe_dir / (config.title + dist_format), dirs_exist_ok=True) else: shutil.copy(generated_exec_path, config.exe_dir) print("[DEPLOY] Executed file created in " - f"{str(config.exe_dir / (config.source_file.stem + EXE_FORMAT))}") + f"{str(config.exe_dir / (config.source_file.stem + dist_format))}") diff --git a/sources/pyside-tools/deploy_lib/nuitka_helper.py b/sources/pyside-tools/deploy_lib/nuitka_helper.py index ac9a83f3f..5d0e9032f 100644 --- a/sources/pyside-tools/deploy_lib/nuitka_helper.py +++ b/sources/pyside-tools/deploy_lib/nuitka_helper.py @@ -1,6 +1,9 @@ # Copyright (C) 2022 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 +# enables to use typehints for classes that has not been defined yet or imported +# used for resolving circular imports +from __future__ import annotations import logging import os import sys @@ -8,6 +11,7 @@ from pathlib import Path from typing import List from . import MAJOR_VERSION, run_command +from .config import DesktopConfig class Nuitka: @@ -52,10 +56,12 @@ class Nuitka: def create_executable(self, source_file: Path, extra_args: str, qml_files: List[Path], qt_plugins: List[str], excluded_qml_plugins: List[str], icon: str, - dry_run: bool, permissions: List[str]): + dry_run: bool, permissions: List[str], + mode: DesktopConfig.NuitkaMode): qt_plugins = [plugin for plugin in qt_plugins if plugin not in self.qt_plugins_to_ignore] extra_args = extra_args.split() + # macOS uses the --standalone option by default to create an app bundle if sys.platform == "darwin": # create an app bundle extra_args.extend(["--standalone", "--macos-create-app-bundle"]) @@ -63,7 +69,7 @@ class Nuitka: for permission in permissions: extra_args.append(permission_pattern.format(permission=permission)) else: - extra_args.append("--onefile") + extra_args.append(f"--{mode.value}") qml_args = [] if qml_files: |
