diff options
| author | Adrian Herrmann <adrian.herrmann@qt.io> | 2024-06-06 10:59:31 +0200 |
|---|---|---|
| committer | Adrian Herrmann <adrian.herrmann@qt.io> | 2024-06-20 16:10:46 +0000 |
| commit | ba2582125f6c9d470d3a5f4e1e61666de9101e0e (patch) | |
| tree | cb04e0b4a90e02e0d6026309447fbcf08a8e00a0 /sources/pyside-tools/deploy_lib | |
| parent | 7bb9c0e2f81ec474bf98690b4f90f195a6ea27c8 (diff) | |
Use modern typing syntax
We can already use the modern typing syntax introduced with Python 3.10
in 3.9 via future statement definitions, even before we raise the
minimum Python version to 3.10.
Note that direct expressions with "|" don't work yet.
Task-number: PYSIDE-2786
Change-Id: Ie36c140fc960328322502ea29cf6868805a7c558
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside-tools/deploy_lib')
7 files changed, 19 insertions, 26 deletions
diff --git a/sources/pyside-tools/deploy_lib/android/android_config.py b/sources/pyside-tools/deploy_lib/android/android_config.py index 7e39a2dbe..4cca7dfb6 100644 --- a/sources/pyside-tools/deploy_lib/android/android_config.py +++ b/sources/pyside-tools/deploy_lib/android/android_config.py @@ -8,7 +8,6 @@ import logging import zipfile import xml.etree.ElementTree as ET -from typing import List from pathlib import Path from pkginfo import Wheel @@ -27,7 +26,7 @@ class AndroidConfig(Config): """ def __init__(self, config_file: Path, source_file: Path, python_exe: Path, dry_run: bool, android_data, existing_config_file: bool = False, - extra_ignore_dirs: List[str] = None): + extra_ignore_dirs: list[str] = None): super().__init__(config_file=config_file, source_file=source_file, python_exe=python_exe, dry_run=dry_run, existing_config_file=existing_config_file) @@ -336,7 +335,7 @@ class AndroidConfig(Config): return dependent_modules - def _find_and_set_dependency_files(self) -> List[zipfile.Path]: + def _find_and_set_dependency_files(self) -> list[zipfile.Path]: """ Based on `modules`, returns the Qt6{module}_{arch}-android-dependencies.xml file, which contains the various dependencies of the module, like permissions, plugins etc @@ -385,7 +384,7 @@ class AndroidConfig(Config): return list(local_libs), list(plugins) - def _find_plugin_dependencies(self, dependent_plugins: List[str]): + def _find_plugin_dependencies(self, dependent_plugins: list[str]): # The `bundled` element in the dependency xml files points to the folder where # additional dependencies for the application exists. Inspecting the depenency files # in android, this always points to the specific Qt plugin dependency folder. diff --git a/sources/pyside-tools/deploy_lib/android/android_helper.py b/sources/pyside-tools/deploy_lib/android/android_helper.py index b26a7a69b..f9398d7ed 100644 --- a/sources/pyside-tools/deploy_lib/android/android_helper.py +++ b/sources/pyside-tools/deploy_lib/android/android_helper.py @@ -6,7 +6,6 @@ import logging import zipfile from dataclasses import dataclass from pathlib import Path -from typing import List, Set from zipfile import ZipFile from jinja2 import Environment, FileSystemLoader @@ -26,8 +25,8 @@ class AndroidData: def create_recipe(version: str, component: str, wheel_path: str, generated_files_path: Path, - qt_modules: List[str] = None, local_libs: List[str] = None, - plugins: List[str] = None): + qt_modules: list[str] = None, local_libs: list[str] = None, + plugins: list[str] = None): ''' Create python_for_android recipe for PySide6 and shiboken6 ''' @@ -95,7 +94,7 @@ def get_llvm_readobj(ndk_path: Path) -> Path: return (ndk_path / f"toolchains/llvm/prebuilt/{sys.platform}-x86_64/bin/llvm-readobj") -def find_lib_dependencies(llvm_readobj: Path, lib_path: Path, used_dependencies: Set[str] = None, +def find_lib_dependencies(llvm_readobj: Path, lib_path: Path, used_dependencies: set[str] = None, dry_run: bool = False): """ Find all the Qt dependencies of a library using llvm_readobj diff --git a/sources/pyside-tools/deploy_lib/android/buildozer.py b/sources/pyside-tools/deploy_lib/android/buildozer.py index 062706b7a..36d8313e5 100644 --- a/sources/pyside-tools/deploy_lib/android/buildozer.py +++ b/sources/pyside-tools/deploy_lib/android/buildozer.py @@ -7,7 +7,6 @@ import logging import xml.etree.ElementTree as ET import zipfile from pathlib import Path -from typing import List from . import AndroidConfig from .. import BaseConfig, run_command @@ -77,7 +76,7 @@ class BuildozerConfig(BaseConfig): self.update_config() - def __find_permissions(self, dependency_files: List[zipfile.Path]): + def __find_permissions(self, dependency_files: list[zipfile.Path]): permissions = set() for dependency_file in dependency_files: xml_content = dependency_file.read_text() @@ -86,7 +85,7 @@ class BuildozerConfig(BaseConfig): permissions.add(permission.attrib['name']) return permissions - def __find_jars(self, dependency_files: List[zipfile.Path], jars_dir: Path): + def __find_jars(self, dependency_files: list[zipfile.Path], jars_dir: Path): jars, init_classes = set(), set() for dependency_file in dependency_files: xml_content = dependency_file.read_text() diff --git a/sources/pyside-tools/deploy_lib/commands.py b/sources/pyside-tools/deploy_lib/commands.py index b65b1a769..ee1abcb15 100644 --- a/sources/pyside-tools/deploy_lib/commands.py +++ b/sources/pyside-tools/deploy_lib/commands.py @@ -6,7 +6,6 @@ import json import subprocess import sys from pathlib import Path -from typing import List """ All utility functions for deployment @@ -38,7 +37,7 @@ def run_command(command, dry_run: bool, fetch_output: bool = False): return command_str, output -def run_qmlimportscanner(qml_files: List[Path], dry_run: bool): +def run_qmlimportscanner(qml_files: list[Path], dry_run: bool): """ Runs pyside6-qmlimportscanner to find all the imported qml modules """ diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py index ca8a9355d..23d037dca 100644 --- a/sources/pyside-tools/deploy_lib/config.py +++ b/sources/pyside-tools/deploy_lib/config.py @@ -7,7 +7,6 @@ import configparser import logging import warnings from configparser import ConfigParser -from typing import List from pathlib import Path from enum import Enum @@ -76,7 +75,7 @@ class Config(BaseConfig): """ 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): super().__init__(config_file=config_file, existing_config_file=existing_config_file) self.extra_ignore_dirs = extra_ignore_dirs @@ -383,7 +382,7 @@ class DesktopConfig(Config): 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) diff --git a/sources/pyside-tools/deploy_lib/dependency_util.py b/sources/pyside-tools/deploy_lib/dependency_util.py index e5a9a25f6..30a336f0a 100644 --- a/sources/pyside-tools/deploy_lib/dependency_util.py +++ b/sources/pyside-tools/deploy_lib/dependency_util.py @@ -12,14 +12,13 @@ import logging import shutil import sys from pathlib import Path -from typing import List, Set from functools import lru_cache from . import IMPORT_WARNING_PYSIDE, run_command @lru_cache(maxsize=None) -def get_py_files(project_dir: Path, extra_ignore_dirs: List[Path] = None, project_data=None): +def get_py_files(project_dir: Path, extra_ignore_dirs: list[Path] = None, project_data=None): """Finds and returns all the Python files in the project """ py_candidates = [] @@ -79,7 +78,7 @@ def get_ast(py_file: Path): return tree -def find_permission_categories(project_dir: Path, extra_ignore_dirs: List[Path] = None, +def find_permission_categories(project_dir: Path, extra_ignore_dirs: list[Path] = None, project_data=None): """Given the project directory, finds all the permission categories required by the project. eg: Camera, Bluetooth, Contacts etc. @@ -127,7 +126,7 @@ def find_permission_categories(project_dir: Path, extra_ignore_dirs: List[Path] return all_perm_categories -def find_pyside_modules(project_dir: Path, extra_ignore_dirs: List[Path] = None, +def find_pyside_modules(project_dir: Path, extra_ignore_dirs: list[Path] = None, project_data=None): """ Searches all the python files in the project to find all the PySide modules used by @@ -235,7 +234,7 @@ class QtDependencyReader: def lib_reader(self): return self._lib_reader - def find_dependencies(self, module: str, used_modules: Set[str] = None): + def find_dependencies(self, module: str, used_modules: set[str] = None): """ Given a Qt module, find all the other Qt modules it is dependent on and add it to the 'used_modules' set @@ -286,7 +285,7 @@ class QtDependencyReader: else: logging.info(f"[DEPLOY] No Qt dependencies found for {module}") - def find_plugin_dependencies(self, used_modules: List[str], python_exe: Path) -> List[str]: + def find_plugin_dependencies(self, used_modules: list[str], python_exe: Path) -> list[str]: """ Given the modules used by the application, returns all the required plugins """ diff --git a/sources/pyside-tools/deploy_lib/nuitka_helper.py b/sources/pyside-tools/deploy_lib/nuitka_helper.py index 98a74f52c..06dba84f5 100644 --- a/sources/pyside-tools/deploy_lib/nuitka_helper.py +++ b/sources/pyside-tools/deploy_lib/nuitka_helper.py @@ -9,7 +9,6 @@ import logging import os import sys from pathlib import Path -from typing import List from . import MAJOR_VERSION, run_command from .config import DesktopConfig @@ -55,9 +54,9 @@ class Nuitka: else: return "--macos-app-icon" - 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], + 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], 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() |
