Run ruff check --fix (MR 2357)

Now that we have target-version = "py310" in [tool.ruff] in
pyproject.toml, ruff check complains about using typing.Optional and
typing.Union instead of newer syntax. Run the tool to fix it.
This commit is contained in:
Oliver Smith 2024-07-16 00:21:13 +02:00
parent 9fd45fb334
commit 36dd53f402
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
25 changed files with 116 additions and 130 deletions

View file

@ -1,7 +1,8 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import datetime import datetime
from typing import Any, Callable, Optional, TypedDict from typing import Any, TypedDict
from collections.abc import Callable
from pmb.build.other import BuildStatus from pmb.build.other import BuildStatus
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.core.context import Context from pmb.core.context import Context
@ -215,7 +216,7 @@ def process_package(
context: Context, context: Context,
queue_build: Callable, queue_build: Callable,
pkgname: str, pkgname: str,
arch: Optional[Arch], arch: Arch | None,
fallback_arch: Arch, fallback_arch: Arch,
force: bool, force: bool,
) -> list[str]: ) -> list[str]:
@ -321,12 +322,12 @@ def process_package(
def packages( def packages(
context: Context, context: Context,
pkgnames: list[str], pkgnames: list[str],
arch: Optional[Arch] = None, arch: Arch | None = None,
force=False, force=False,
strict=False, strict=False,
src=None, src=None,
bootstrap_stage=BootstrapStage.NONE, bootstrap_stage=BootstrapStage.NONE,
log_callback: Optional[Callable] = None, log_callback: Callable | None = None,
) -> list[str]: ) -> list[str]:
""" """
Build a package and its dependencies with Alpine Linux' abuild. Build a package and its dependencies with Alpine Linux' abuild.

View file

@ -3,7 +3,7 @@
from pathlib import Path from pathlib import Path
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.helpers import logging from pmb.helpers import logging
from typing import Any, Optional, Union from typing import Any
import pmb.config import pmb.config
import pmb.chroot.apk import pmb.chroot.apk
@ -15,7 +15,7 @@ from pmb.types import CrossCompileType
# FIXME (#2324): type hint Arch # FIXME (#2324): type hint Arch
def arch_from_deviceinfo(pkgname, aport: Path) -> Optional[Arch]: def arch_from_deviceinfo(pkgname, aport: Path) -> Arch | None:
""" """
The device- packages are noarch packages. But it only makes sense to build The device- packages are noarch packages. But it only makes sense to build
them for the device's architecture, which is specified in the deviceinfo them for the device's architecture, which is specified in the deviceinfo
@ -39,7 +39,7 @@ def arch_from_deviceinfo(pkgname, aport: Path) -> Optional[Arch]:
@Cache("package") @Cache("package")
def arch(package: Union[str, dict[str, Any]]): def arch(package: str | dict[str, Any]):
""" """
Find a good default in case the user did not specify for which architecture Find a good default in case the user did not specify for which architecture
a package should be built. a package should be built.

View file

@ -1,6 +1,5 @@
# Copyright 2024 Oliver Smith # Copyright 2024 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import Optional
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.core.chroot import Chroot, ChrootType from pmb.core.chroot import Chroot, ChrootType
from pmb.core.context import Context from pmb.core.context import Context
@ -43,7 +42,7 @@ class RepoBootstrap(commands.Command):
f"Couldn't find section 'repo:{self.repo}' in pmaports.cfg of" " current branch" f"Couldn't find section 'repo:{self.repo}' in pmaports.cfg of" " current branch"
) )
def __init__(self, arch: Optional[Arch], repository: str): def __init__(self, arch: Arch | None, repository: str):
context = get_context() context = get_context()
if arch: if arch:
self.arch = arch self.arch = arch

View file

@ -10,7 +10,7 @@ import glob
import json import json
import os import os
import shutil import shutil
from typing import Any, Optional from typing import Any
import pmb.aportgen import pmb.aportgen
import pmb.config import pmb.config
@ -600,7 +600,7 @@ def ask_for_mirror():
return mirror return mirror
def ask_for_hostname(default: Optional[str], device): def ask_for_hostname(default: str | None, device):
while True: while True:
ret = pmb.helpers.cli.ask( ret = pmb.helpers.cli.ask(
"Device hostname (short form, e.g. 'foo')", None, (default or device), True "Device hostname (short form, e.g. 'foo')", None, (default or device), True

View file

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import configparser import configparser
from pathlib import Path from pathlib import Path
from typing import Optional
from pmb.core.pkgrepo import pkgrepo_default_path, pkgrepo_paths, pkgrepo_relative_path from pmb.core.pkgrepo import pkgrepo_default_path, pkgrepo_paths, pkgrepo_relative_path
from pmb.helpers import logging from pmb.helpers import logging
import os import os
@ -89,7 +88,7 @@ def read_config_repos():
@Cache("aports") @Cache("aports")
def read_config(aports: Optional[Path] = None): def read_config(aports: Path | None = None):
"""Read and verify pmaports.cfg. If aports is not """Read and verify pmaports.cfg. If aports is not
specified and systemd is enabled, the returned channel specified and systemd is enabled, the returned channel
will be the systemd one (e.g. systemd-edge instead of edge) will be the systemd one (e.g. systemd-edge instead of edge)

View file

@ -3,11 +3,10 @@
import os import os
import shutil import shutil
from functools import lru_cache from functools import lru_cache
from typing import Optional
@lru_cache @lru_cache
def which_sudo() -> Optional[str]: def which_sudo() -> str | None:
"""Return a command required to run commands as root, if any. """Return a command required to run commands as root, if any.
Find whether sudo or doas is installed for commands that require root. Find whether sudo or doas is installed for commands that require root.

View file

@ -8,7 +8,7 @@ dir."""
import configparser import configparser
import os import os
import time import time
from typing import Optional, overload from typing import overload
import pmb.config import pmb.config
import pmb.config.pmaports import pmb.config.pmaports
@ -48,7 +48,7 @@ def chroots_outdated() -> list[Chroot]: ...
def chroots_outdated(chroot: Chroot) -> bool: ... def chroots_outdated(chroot: Chroot) -> bool: ...
def chroots_outdated(chroot: Optional[Chroot] = None): def chroots_outdated(chroot: Chroot | None = None):
"""Check if init dates from workdir.cfg indicate that any chroot is """Check if init dates from workdir.cfg indicate that any chroot is
outdated. outdated.

View file

@ -1,7 +1,6 @@
import os import os
import glob import glob
from pathlib import Path from pathlib import Path
from typing import Optional
from collections.abc import Generator from collections.abc import Generator
import pmb.config import pmb.config
@ -61,7 +60,7 @@ def pkgrepo_name_from_subdir(subdir: Path) -> str:
raise RuntimeError(f"aports subdir '{subdir}' not found") raise RuntimeError(f"aports subdir '{subdir}' not found")
def pkgrepo_glob_one(path: str) -> Optional[Path]: def pkgrepo_glob_one(path: str) -> Path | None:
""" """
Search for the file denoted by path in all aports repositories. Search for the file denoted by path in all aports repositories.
path can be a glob. path can be a glob.

View file

@ -1,6 +1,5 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import Optional
import pmb.config.pmaports import pmb.config.pmaports
from pmb.core.chroot import Chroot from pmb.core.chroot import Chroot
from pmb.core.context import get_context from pmb.core.context import get_context
@ -20,8 +19,8 @@ def variables(args: PmbArgs, flavor: str, method: str):
# updated and minimum pmbootstrap version bumped. # updated and minimum pmbootstrap version bumped.
# See also https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2243 # See also https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2243
_partition_kernel: Optional[str] _partition_kernel: str | None
_partition_rootfs: Optional[str] _partition_rootfs: str | None
if method.startswith("fastboot"): if method.startswith("fastboot"):
_partition_kernel = deviceinfo.flash_fastboot_partition_kernel or "boot" _partition_kernel = deviceinfo.flash_fastboot_partition_kernel or "boot"

View file

@ -3,7 +3,6 @@
import os import os
from collections.abc import Sequence from collections.abc import Sequence
from pathlib import Path from pathlib import Path
from typing import Optional
import pmb.chroot import pmb.chroot
import pmb.config.pmaports import pmb.config.pmaports
@ -17,7 +16,7 @@ import pmb.parse.version
from pmb.core.context import get_context from pmb.core.context import get_context
def _run(command, chroot: Optional[Chroot], output="log"): def _run(command, chroot: Chroot | None, output="log"):
"""Run a command. """Run a command.
:param command: command in list form :param command: command in list form
@ -33,7 +32,7 @@ def _run(command, chroot: Optional[Chroot], output="log"):
return pmb.helpers.run.root(command, output=output) return pmb.helpers.run.root(command, output=output)
def _prepare_fifo(chroot: Optional[Chroot]): def _prepare_fifo(chroot: Chroot | None):
"""Prepare the progress fifo for reading / writing. """Prepare the progress fifo for reading / writing.
:param chroot: whether to run the command inside the chroot or on the host :param chroot: whether to run the command inside the chroot or on the host
@ -87,7 +86,7 @@ def _compute_progress(line):
return cur / tot if tot > 0 else 0 return cur / tot if tot > 0 else 0
def apk_with_progress(command: Sequence[PathString], chroot: Optional[Chroot] = None): def apk_with_progress(command: Sequence[PathString], chroot: Chroot | None = None):
"""Run an apk subcommand while printing a progress bar to STDOUT. """Run an apk subcommand while printing a progress bar to STDOUT.
:param command: apk subcommand in list form :param command: apk subcommand in list form

View file

@ -6,7 +6,6 @@ from pmb.helpers import logging
import os import os
import re import re
import urllib.parse import urllib.parse
from typing import Optional
from pmb.types import PmbArgs from pmb.types import PmbArgs
import pmb.helpers.file import pmb.helpers.file
@ -48,7 +47,7 @@ def init_req_headers() -> None:
) )
def get_package_version_info_github(repo_name: str, ref: Optional[str]): def get_package_version_info_github(repo_name: str, ref: str | None):
logging.debug(f"Trying GitHub repository: {repo_name}") logging.debug(f"Trying GitHub repository: {repo_name}")
# Get the URL argument to request a special ref, if needed # Get the URL argument to request a special ref, if needed
@ -70,7 +69,7 @@ def get_package_version_info_github(repo_name: str, ref: Optional[str]):
} }
def get_package_version_info_gitlab(gitlab_host: str, repo_name: str, ref: Optional[str]): def get_package_version_info_gitlab(gitlab_host: str, repo_name: str, ref: str | None):
logging.debug(f"Trying GitLab repository: {repo_name}") logging.debug(f"Trying GitLab repository: {repo_name}")
repo_name_safe = urllib.parse.quote(repo_name, safe="") repo_name_safe = urllib.parse.quote(repo_name, safe="")

View file

@ -2,11 +2,10 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import os import os
from pathlib import Path from pathlib import Path
from typing import Optional
from pmb.core.pkgrepo import pkgrepo_glob_one, pkgrepo_iglob from pmb.core.pkgrepo import pkgrepo_glob_one, pkgrepo_iglob
def find_path(codename: str, file="") -> Optional[Path]: def find_path(codename: str, file="") -> Path | None:
"""Find path to device APKBUILD under `device/*/device-`. """Find path to device APKBUILD under `device/*/device-`.
:param codename: device codename :param codename: device codename

View file

@ -12,7 +12,7 @@ from pmb.core.arch import Arch
from pmb.core.pkgrepo import pkgrepo_iter_package_dirs from pmb.core.pkgrepo import pkgrepo_iter_package_dirs
from pmb.helpers import logging from pmb.helpers import logging
from pathlib import Path from pathlib import Path
from typing import Any, Optional from typing import Any
from collections.abc import Sequence from collections.abc import Sequence
from pmb.meta import Cache from pmb.meta import Cache
@ -51,7 +51,7 @@ def get_list() -> Sequence[str]:
return list(_find_apkbuilds().keys()) return list(_find_apkbuilds().keys())
def guess_main_dev(subpkgname) -> Optional[Path]: def guess_main_dev(subpkgname) -> Path | None:
"""Check if a package without "-dev" at the end exists in pmaports or not, and log the appropriate message. """Check if a package without "-dev" at the end exists in pmaports or not, and log the appropriate message.
Don't call this function directly, use guess_main() instead. Don't call this function directly, use guess_main() instead.
@ -77,7 +77,7 @@ def guess_main_dev(subpkgname) -> Optional[Path]:
return None return None
def guess_main(subpkgname) -> Optional[Path]: def guess_main(subpkgname) -> Path | None:
"""Find the main package by assuming it is a prefix of the subpkgname. """Find the main package by assuming it is a prefix of the subpkgname.
We do that, because in some APKBUILDs the subpkgname="" variable gets We do that, because in some APKBUILDs the subpkgname="" variable gets
@ -165,7 +165,7 @@ def find(package, must_exist=True, subpackages=True, skip_extra_repos=False):
""" """
# Try to get a cached result first (we assume that the aports don't change # Try to get a cached result first (we assume that the aports don't change
# in one pmbootstrap call) # in one pmbootstrap call)
ret: Optional[Path] = None ret: Path | None = None
# Sanity check # Sanity check
if "*" in package: if "*" in package:
raise RuntimeError("Invalid pkgname: " + package) raise RuntimeError("Invalid pkgname: " + package)
@ -205,7 +205,7 @@ def find(package, must_exist=True, subpackages=True, skip_extra_repos=False):
return ret return ret
def find_optional(package: str) -> Optional[Path]: def find_optional(package: str) -> Path | None:
try: try:
return find(package) return find(package)
except RuntimeError: except RuntimeError:
@ -216,7 +216,7 @@ def find_optional(package: str) -> Optional[Path]:
@Cache("pkgname", subpackages=True) @Cache("pkgname", subpackages=True)
def get_with_path( def get_with_path(
pkgname, must_exist=True, subpackages=True, skip_extra_repos=False pkgname, must_exist=True, subpackages=True, skip_extra_repos=False
) -> tuple[Optional[Path], Optional[dict[str, Any]]]: ) -> tuple[Path | None, dict[str, Any] | None]:
"""Find and parse an APKBUILD file. """Find and parse an APKBUILD file.
Run 'pmbootstrap apkbuild_parse hello-world' for a full output example. Run 'pmbootstrap apkbuild_parse hello-world' for a full output example.
@ -272,7 +272,7 @@ def find_providers(provide):
# FIXME (#2324): split into an _optional variant or drop must_exist # FIXME (#2324): split into an _optional variant or drop must_exist
def get_repo(pkgname, must_exist=True) -> Optional[str]: def get_repo(pkgname, must_exist=True) -> str | None:
"""Get the repository folder of an aport. """Get the repository folder of an aport.
:pkgname: package name :pkgname: package name
@ -280,7 +280,7 @@ def get_repo(pkgname, must_exist=True) -> Optional[str]:
:returns: a string like "main", "device", "cross", ... :returns: a string like "main", "device", "cross", ...
or None when the aport could not be found or None when the aport could not be found
""" """
aport: Optional[Path] aport: Path | None
if must_exist: if must_exist:
aport = find(pkgname) aport = find(pkgname)
else: else:

View file

@ -15,7 +15,6 @@ from pmb.core.arch import Arch
from pmb.core.pkgrepo import pkgrepo_names from pmb.core.pkgrepo import pkgrepo_names
from pmb.helpers import logging from pmb.helpers import logging
from pathlib import Path from pathlib import Path
from typing import Optional
import pmb.config.pmaports import pmb.config.pmaports
from pmb.meta import Cache from pmb.meta import Cache
@ -104,7 +103,7 @@ def urls(user_repository=False, mirrors_exclude: list[str] = []):
def apkindex_files( def apkindex_files(
arch: Optional[Arch] = None, user_repository=True, exclude_mirrors: list[str] = [] arch: Arch | None = None, user_repository=True, exclude_mirrors: list[str] = []
) -> list[Path]: ) -> list[Path]:
"""Get a list of outside paths to all resolved APKINDEX.tar.gz files for a specific arch. """Get a list of outside paths to all resolved APKINDEX.tar.gz files for a specific arch.
@ -130,7 +129,7 @@ def apkindex_files(
@Cache("arch", force=False) @Cache("arch", force=False)
def update(arch: Optional[Arch] = None, force=False, existing_only=False): def update(arch: Arch | None = None, force=False, existing_only=False):
"""Download the APKINDEX files for all URLs depending on the architectures. """Download the APKINDEX files for all URLs depending on the architectures.
:param arch: * one Alpine architecture name ("x86_64", "armhf", ...) :param arch: * one Alpine architecture name ("x86_64", "armhf", ...)
@ -206,7 +205,7 @@ def update(arch: Optional[Arch] = None, force=False, existing_only=False):
return True return True
def alpine_apkindex_path(repo="main", arch: Optional[Arch] = None): def alpine_apkindex_path(repo="main", arch: Arch | None = None):
"""Get the path to a specific Alpine APKINDEX file on disk and download it if necessary. """Get the path to a specific Alpine APKINDEX file on disk and download it if necessary.
:param repo: Alpine repository name (e.g. "main") :param repo: Alpine repository name (e.g. "main")

View file

@ -5,17 +5,16 @@ from pathlib import Path
import subprocess import subprocess
from pmb.core.arch import Arch from pmb.core.arch import Arch
import pmb.helpers.run_core import pmb.helpers.run_core
from typing import Optional
from collections.abc import Sequence from collections.abc import Sequence
from pmb.types import Env, PathString from pmb.types import Env, PathString
def user( def user(
cmd: Sequence[PathString], cmd: Sequence[PathString],
working_dir: Optional[Path] = None, working_dir: Path | None = None,
output: str = "log", output: str = "log",
output_return: bool = False, output_return: bool = False,
check: Optional[bool] = None, check: bool | None = None,
env: Env = {}, env: Env = {},
sudo: bool = False, sudo: bool = False,
) -> str | int | subprocess.Popen: ) -> str | int | subprocess.Popen:
@ -56,9 +55,9 @@ def user(
# FIXME: should probably use some kind of wrapper class / builder pattern for all these parameters... # FIXME: should probably use some kind of wrapper class / builder pattern for all these parameters...
def user_output( def user_output(
cmd: Sequence[PathString], cmd: Sequence[PathString],
working_dir: Optional[Path] = None, working_dir: Path | None = None,
output: str = "log", output: str = "log",
check: Optional[bool] = None, check: bool | None = None,
env: Env = {}, env: Env = {},
sudo: bool = False, sudo: bool = False,
) -> str: ) -> str:

View file

@ -13,7 +13,6 @@ import subprocess
import sys import sys
import threading import threading
import time import time
from typing import Optional
from collections.abc import Sequence from collections.abc import Sequence
import pmb.helpers.run import pmb.helpers.run
@ -23,7 +22,7 @@ import pmb.helpers.run
def flat_cmd( def flat_cmd(
cmds: Sequence[Sequence[PathString]], working_dir: Optional[Path] = None, env: Env = {} cmds: Sequence[Sequence[PathString]], working_dir: Path | None = None, env: Env = {}
): ):
"""Convert a shell command passed as list into a flat shell string with proper escaping. """Convert a shell command passed as list into a flat shell string with proper escaping.

View file

@ -7,7 +7,6 @@ import re
import glob import glob
import shlex import shlex
import sys import sys
from typing import Optional
from collections.abc import Sequence from collections.abc import Sequence
from pathlib import Path from pathlib import Path
@ -388,7 +387,7 @@ def setup_timezone(chroot: Chroot, timezone: str):
pmb.chroot.root(setup_tz_cmd, chroot) pmb.chroot.root(setup_tz_cmd, chroot)
def setup_hostname(device: str, hostname: Optional[str]): def setup_hostname(device: str, hostname: str | None):
""" """
Set the hostname and update localhost address in /etc/hosts Set the hostname and update localhost address in /etc/hosts
""" """
@ -840,7 +839,7 @@ def install_system_image(
boot_label="pmOS_boot", boot_label="pmOS_boot",
root_label="pmOS_root", root_label="pmOS_root",
split=False, split=False,
disk: Optional[Path] = None, disk: Path | None = None,
): ):
""" """
:param size_reserve: empty partition between root and boot in MiB (pma#463) :param size_reserve: empty partition between root and boot in MiB (pma#463)

View file

@ -1,6 +1,5 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import Optional
from pmb.helpers import logging from pmb.helpers import logging
import os import os
from pathlib import Path from pathlib import Path
@ -122,7 +121,7 @@ def create_and_mount_image(args: PmbArgs, size_boot, size_root, size_reserve, sp
pmb.helpers.mount.bind_file(device, Chroot.native() / mount_point) pmb.helpers.mount.bind_file(device, Chroot.native() / mount_point)
def create(args: PmbArgs, size_boot, size_root, size_reserve, split, disk: Optional[Path]): def create(args: PmbArgs, size_boot, size_root, size_reserve, split, disk: Path | None):
""" """
Create /dev/install (the "install blockdevice"). Create /dev/install (the "install blockdevice").

View file

@ -1,7 +1,6 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from pathlib import Path from pathlib import Path
from typing import Optional
from pmb.helpers import logging from pmb.helpers import logging
import os import os
import time import time
@ -13,7 +12,7 @@ from pmb.core import Chroot
# FIXME (#2324): this function drops disk to a string because it's easier # FIXME (#2324): this function drops disk to a string because it's easier
# to manipulate, this is probably bad. # to manipulate, this is probably bad.
def partitions_mount(device: str, layout, disk: Optional[Path]): def partitions_mount(device: str, layout, disk: Path | None):
""" """
Mount blockdevices of partitions inside native chroot Mount blockdevices of partitions inside native chroot
:param layout: partition layout from get_partition_layout() :param layout: partition layout from get_partition_layout()

View file

@ -2,7 +2,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import copy import copy
from typing import Callable, Generic, Optional, TypeVar, overload from typing import Generic, Optional, TypeVar, overload
from collections.abc import Callable
import inspect import inspect
@ -78,7 +79,7 @@ class Cache:
# Build the cache key, or return None to not cache in the case where # Build the cache key, or return None to not cache in the case where
# we only cache when an argument has a specific value # we only cache when an argument has a specific value
def build_key(self, func: Callable, *args, **kwargs) -> Optional[str]: def build_key(self, func: Callable, *args, **kwargs) -> str | None:
key = "~" key = "~"
# Easy case: cache irrelevant of arguments # Easy case: cache irrelevant of arguments
if not self.params and not self.kwargs: if not self.params and not self.kwargs:

View file

@ -1,7 +1,7 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import collections import collections
from typing import Any, Optional from typing import Any
from collections.abc import Sequence from collections.abc import Sequence
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.core.context import get_context from pmb.core.context import get_context
@ -284,7 +284,7 @@ def clear_cache(path: Path):
return False return False
def providers(package, arch: Optional[Arch] = None, must_exist=True, indexes=None): def providers(package, arch: Arch | None = None, must_exist=True, indexes=None):
""" """
Get all packages, which provide one package. Get all packages, which provide one package.
@ -380,7 +380,7 @@ def provider_shortest(providers, pkgname):
return providers[ret] return providers[ret]
def package(package, arch: Optional[Arch] = None, must_exist=True, indexes=None): def package(package, arch: Arch | None = None, must_exist=True, indexes=None):
""" """
Get a specific package's data from an apkindex. Get a specific package's data from an apkindex.

View file

@ -1,10 +1,9 @@
# Copyright 2023 Lary Gibaud # Copyright 2023 Lary Gibaud
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import re import re
from typing import Optional
def arm_big_little_first_group_ncpus() -> Optional[int]: def arm_big_little_first_group_ncpus() -> int | None:
""" """
Infer from /proc/cpuinfo on aarch64 if this is a big/little architecture Infer from /proc/cpuinfo on aarch64 if this is a big/little architecture
(if there is different processor models) and the number of cores in the (if there is different processor models) and the number of cores in the

View file

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import copy import copy
from pathlib import Path from pathlib import Path
from typing import Optional
from pmb.core.context import get_context from pmb.core.context import get_context
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.helpers import logging from pmb.helpers import logging
@ -102,73 +101,73 @@ class Deviceinfo:
# device # device
chassis: str chassis: str
keyboard: Optional[str] = "" keyboard: str | None = ""
external_storage: Optional[str] = "" external_storage: str | None = ""
gpu_accelerated: Optional[bool] = False gpu_accelerated: bool | None = False
dev_touchscreen: Optional[str] = "" dev_touchscreen: str | None = ""
dev_touchscreen_calibration: Optional[str] = "" dev_touchscreen_calibration: str | None = ""
append_dtb: Optional[str] = "" append_dtb: str | None = ""
# bootloader # bootloader
flash_method: str = "" flash_method: str = ""
boot_filesystem: Optional[str] = "" boot_filesystem: str | None = ""
# flash # flash
flash_heimdall_partition_kernel: Optional[str] = "" flash_heimdall_partition_kernel: str | None = ""
flash_heimdall_partition_initfs: Optional[str] = "" flash_heimdall_partition_initfs: str | None = ""
flash_heimdall_partition_rootfs: Optional[str] = "" flash_heimdall_partition_rootfs: str | None = ""
flash_heimdall_partition_system: Optional[str] = "" # deprecated flash_heimdall_partition_system: str | None = "" # deprecated
flash_heimdall_partition_vbmeta: Optional[str] = "" flash_heimdall_partition_vbmeta: str | None = ""
flash_heimdall_partition_dtbo: Optional[str] = "" flash_heimdall_partition_dtbo: str | None = ""
flash_fastboot_partition_kernel: Optional[str] = "" flash_fastboot_partition_kernel: str | None = ""
flash_fastboot_partition_rootfs: Optional[str] = "" flash_fastboot_partition_rootfs: str | None = ""
flash_fastboot_partition_system: Optional[str] = "" # deprecated flash_fastboot_partition_system: str | None = "" # deprecated
flash_fastboot_partition_vbmeta: Optional[str] = "" flash_fastboot_partition_vbmeta: str | None = ""
flash_fastboot_partition_dtbo: Optional[str] = "" flash_fastboot_partition_dtbo: str | None = ""
flash_rk_partition_kernel: Optional[str] = "" flash_rk_partition_kernel: str | None = ""
flash_rk_partition_rootfs: Optional[str] = "" flash_rk_partition_rootfs: str | None = ""
flash_rk_partition_system: Optional[str] = "" # deprecated flash_rk_partition_system: str | None = "" # deprecated
flash_mtkclient_partition_kernel: Optional[str] = "" flash_mtkclient_partition_kernel: str | None = ""
flash_mtkclient_partition_rootfs: Optional[str] = "" flash_mtkclient_partition_rootfs: str | None = ""
flash_mtkclient_partition_vbmeta: Optional[str] = "" flash_mtkclient_partition_vbmeta: str | None = ""
flash_mtkclient_partition_dtbo: Optional[str] = "" flash_mtkclient_partition_dtbo: str | None = ""
generate_legacy_uboot_initfs: Optional[str] = "" generate_legacy_uboot_initfs: str | None = ""
kernel_cmdline: Optional[str] = "" kernel_cmdline: str | None = ""
generate_bootimg: Optional[str] = "" generate_bootimg: str | None = ""
header_version: Optional[str] = "" header_version: str | None = ""
bootimg_qcdt: Optional[str] = "" bootimg_qcdt: str | None = ""
bootimg_mtk_mkimage: Optional[str] = "" # deprecated bootimg_mtk_mkimage: str | None = "" # deprecated
bootimg_mtk_label_kernel: Optional[str] = "" bootimg_mtk_label_kernel: str | None = ""
bootimg_mtk_label_ramdisk: Optional[str] = "" bootimg_mtk_label_ramdisk: str | None = ""
bootimg_dtb_second: Optional[str] = "" bootimg_dtb_second: str | None = ""
bootimg_custom_args: Optional[str] = "" bootimg_custom_args: str | None = ""
flash_offset_base: Optional[str] = "" flash_offset_base: str | None = ""
flash_offset_dtb: Optional[str] = "" flash_offset_dtb: str | None = ""
flash_offset_kernel: Optional[str] = "" flash_offset_kernel: str | None = ""
flash_offset_ramdisk: Optional[str] = "" flash_offset_ramdisk: str | None = ""
flash_offset_second: Optional[str] = "" flash_offset_second: str | None = ""
flash_offset_tags: Optional[str] = "" flash_offset_tags: str | None = ""
flash_pagesize: Optional[str] = "" flash_pagesize: str | None = ""
flash_fastboot_max_size: Optional[str] = "" flash_fastboot_max_size: str | None = ""
flash_sparse: Optional[str] = "" flash_sparse: str | None = ""
flash_sparse_samsung_format: Optional[str] = "" flash_sparse_samsung_format: str | None = ""
rootfs_image_sector_size: Optional[str] = "" rootfs_image_sector_size: str | None = ""
sd_embed_firmware: Optional[str] = "" sd_embed_firmware: str | None = ""
sd_embed_firmware_step_size: Optional[str] = "" sd_embed_firmware_step_size: str | None = ""
partition_blacklist: Optional[str] = "" partition_blacklist: str | None = ""
boot_part_start: Optional[str] = "" boot_part_start: str | None = ""
partition_type: Optional[str] = "" partition_type: str | None = ""
root_filesystem: Optional[str] = "" root_filesystem: str | None = ""
flash_kernel_on_update: Optional[str] = "" flash_kernel_on_update: str | None = ""
cgpt_kpart: Optional[str] = "" cgpt_kpart: str | None = ""
cgpt_kpart_start: Optional[str] = "" cgpt_kpart_start: str | None = ""
cgpt_kpart_size: Optional[str] = "" cgpt_kpart_size: str | None = ""
# weston # weston
weston_pixman_type: Optional[str] = "" weston_pixman_type: str | None = ""
# keymaps # keymaps
keymaps: Optional[str] = "" keymaps: str | None = ""
@staticmethod @staticmethod
def __validate(info: dict[str, str], path: Path): def __validate(info: dict[str, str], path: Path):
@ -250,7 +249,7 @@ class Deviceinfo:
f" and try again: {path}" f" and try again: {path}"
) )
def __init__(self, path: Path, kernel: Optional[str] = None): def __init__(self, path: Path, kernel: str | None = None):
ret = {} ret = {}
with open(path) as handle: with open(path) as handle:
for line in handle: for line in handle:

View file

@ -97,7 +97,7 @@ def ssh_install_apks(args: PmbArgs, user, host, port, paths):
def sideload( def sideload(
args: PmbArgs, user: str, host: str, port: str, arch: Optional[Arch], copy_key: bool, pkgnames args: PmbArgs, user: str, host: str, port: str, arch: Arch | None, copy_key: bool, pkgnames
): ):
"""Build packages if necessary and install them via SSH. """Build packages if necessary and install them via SSH.

View file

@ -7,7 +7,7 @@ from typing import Literal, Optional, TypedDict, Union
from pmb.core.arch import Arch from pmb.core.arch import Arch
CrossCompileType = Optional[Union[Literal["native"], Literal["crossdirect"]]] CrossCompileType = Optional[Literal["native"] | Literal["crossdirect"]]
PathString = Union[Path, str] PathString = Union[Path, str]
Env = dict[str, PathString] Env = dict[str, PathString]
@ -17,9 +17,9 @@ Env = dict[str, PathString]
class PartitionLayout(TypedDict): class PartitionLayout(TypedDict):
kernel: Optional[int] kernel: int | None
boot: int boot: int
reserve: Optional[int] reserve: int | None
root: int root: int
@ -42,8 +42,8 @@ class PmbArgs(Namespace):
all_stable: bool all_stable: bool
android_recovery_zip: bool android_recovery_zip: bool
apkindex_path: Path apkindex_path: Path
aports: Optional[list[Path]] aports: list[Path] | None
arch: Optional[Arch] arch: Arch | None
as_root: bool as_root: bool
assume_yes: bool assume_yes: bool
auto: bool auto: bool