1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 03:19:47 +03:00

Ruff: fix typing.Xxx is deprecated, use xxx instead (MR 2327)

This commit is contained in:
Oliver Smith 2024-06-23 18:56:04 +02:00
parent 61cb4f4abb
commit 18fa4e58a3
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
47 changed files with 137 additions and 147 deletions

View file

@ -6,7 +6,7 @@
import sys import sys
import os import os
import datetime import datetime
from typing import Any, Dict from typing import Any
sys.path.insert(0, os.path.abspath("..")) # Allow modules to be found sys.path.insert(0, os.path.abspath("..")) # Allow modules to be found
@ -47,7 +47,7 @@ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
html_theme = "sphinx_rtd_theme" html_theme = "sphinx_rtd_theme"
html_favicon = "https://wiki.postmarketos.org/favicon.ico" html_favicon = "https://wiki.postmarketos.org/favicon.ico"
html_theme_options: Dict[str, Any] = { html_theme_options: dict[str, Any] = {
"style_nav_header_background": "008b69", "style_nav_header_background": "008b69",
} }

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 List
from pmb.core.context import get_context from pmb.core.context import get_context
from pmb.parse.deviceinfo import Deviceinfo from pmb.parse.deviceinfo import Deviceinfo
import pmb.helpers.run import pmb.helpers.run
@ -8,7 +7,7 @@ import pmb.aportgen.core
import pmb.parse.apkindex import pmb.parse.apkindex
def generate_apkbuild(pkgname: str, deviceinfo: Deviceinfo, patches: List[str]): def generate_apkbuild(pkgname: str, deviceinfo: Deviceinfo, patches: list[str]):
device = "-".join(pkgname.split("-")[1:]) device = "-".join(pkgname.split("-")[1:])
carch = deviceinfo.arch.kernel() carch = deviceinfo.arch.kernel()

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 datetime import datetime
from typing import Any, Callable, Dict, List, Optional, Set, TypedDict from typing import Any, Callable, Optional, TypedDict
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
@ -149,7 +149,7 @@ def finish(apkbuild, channel, arch, output: Path, chroot: Chroot, strict=False):
logging.info(f"@YELLOW@=>@END@ @BLUE@{channel}/{apkbuild['pkgname']}@END@: Done!") logging.info(f"@YELLOW@=>@END@ @BLUE@{channel}/{apkbuild['pkgname']}@END@: Done!")
_package_cache: Dict[str, List[str]] = {} _package_cache: dict[str, list[str]] = {}
def is_cached_or_cache(arch: Arch, pkgname: str) -> bool: def is_cached_or_cache(arch: Arch, pkgname: str) -> bool:
@ -192,10 +192,10 @@ class BuildQueueItem(TypedDict):
name: str name: str
arch: Arch # Arch to build for arch: Arch # Arch to build for
aports: str aports: str
apkbuild: Dict[str, Any] apkbuild: dict[str, Any]
output_path: Path output_path: Path
channel: str channel: str
depends: List[str] depends: list[str]
cross: str cross: str
chroot: Chroot chroot: Chroot
@ -208,7 +208,7 @@ def process_package(
arch: Optional[Arch], arch: Optional[Arch],
fallback_arch: Arch, fallback_arch: Arch,
force: bool, force: bool,
) -> List[str]: ) -> list[str]:
# Only build when APKBUILD exists # Only build when APKBUILD exists
base_aports, base_apkbuild = get_apkbuild(pkgname) base_aports, base_apkbuild = get_apkbuild(pkgname)
if not base_apkbuild: if not base_apkbuild:
@ -306,14 +306,14 @@ def process_package(
def packages( def packages(
context: Context, context: Context,
pkgnames: List[str], pkgnames: list[str],
arch: Optional[Arch] = None, arch: Optional[Arch] = 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: Optional[Callable] = 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.
@ -331,14 +331,14 @@ def packages(
""" """
global _package_cache global _package_cache
build_queue: List[BuildQueueItem] = [] build_queue: list[BuildQueueItem] = []
built_packages: Set[str] = set() built_packages: set[str] = set()
# Add a package to the build queue, fetch it's dependency, and # Add a package to the build queue, fetch it's dependency, and
# add record build helpers to installed (e.g. sccache) # add record build helpers to installed (e.g. sccache)
def queue_build( def queue_build(
aports: Path, apkbuild: Dict[str, Any], depends: List[str], cross: Optional[str] = None aports: Path, apkbuild: dict[str, Any], depends: list[str], cross: Optional[str] = None
) -> List[str]: ) -> list[str]:
# Skip if already queued # Skip if already queued
name = apkbuild["pkgname"] name = apkbuild["pkgname"]
if any(item["name"] == name for item in build_queue): if any(item["name"] == name for item in build_queue):
@ -389,7 +389,7 @@ def packages(
# Process the packages we've been asked to build, queuing up any # Process the packages we've been asked to build, queuing up any
# dependencies that need building as well as the package itself # dependencies that need building as well as the package itself
all_dependencies: List[str] = [] all_dependencies: list[str] = []
for pkgname in pkgnames: for pkgname in pkgnames:
all_dependencies += process_package( all_dependencies += process_package(
context, queue_build, pkgname, arch, fallback_arch, force context, queue_build, pkgname, arch, fallback_arch, force

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, Dict, Optional, Union from typing import Any, Optional, Union
import pmb.config import pmb.config
import pmb.chroot.apk import pmb.chroot.apk
@ -38,7 +38,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: Union[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.
@ -83,7 +83,7 @@ def arch(package: Union[str, Dict[str, Any]]):
return Arch.native() return Arch.native()
def chroot(apkbuild: Dict[str, str], arch: Arch) -> Chroot: def chroot(apkbuild: dict[str, str], arch: Arch) -> Chroot:
if arch == Arch.native(): if arch == Arch.native():
return Chroot.native() return Chroot.native()

View file

@ -1,6 +1,5 @@
import enum import enum
from pathlib import Path from pathlib import Path
from typing import Dict
from pmb.core.pkgrepo import pkgrepo_paths from pmb.core.pkgrepo import pkgrepo_paths
import pmb.helpers.run import pmb.helpers.run
import pmb.chroot import pmb.chroot
@ -115,12 +114,12 @@ def override_source(apkbuild, pkgver, src, chroot: Chroot = Chroot.native()):
pmb.chroot.user(["mv", append_path + "_", apkbuild_path], chroot) pmb.chroot.user(["mv", append_path + "_", apkbuild_path], chroot)
def mount_pmaports(chroot: Chroot = Chroot.native()) -> Dict[str, Path]: def mount_pmaports(chroot: Chroot = Chroot.native()) -> dict[str, Path]:
""" """
Mount pmaports.git in chroot. Mount pmaports.git in chroot.
:param chroot: chroot to target :param chroot: chroot to target
:returns: Dictionary mapping pkgrepo name to dest path :returns: dictionary mapping pkgrepo name to dest path
""" """
dest_paths = {} dest_paths = {}
for repo in pkgrepo_paths(skip_extras=True): for repo in pkgrepo_paths(skip_extras=True):

View file

@ -1,6 +1,5 @@
# Copyright 2023 Robert Yang # Copyright 2023 Robert Yang
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import List
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.core.context import Context from pmb.core.context import Context
from pmb.helpers import logging from pmb.helpers import logging
@ -187,7 +186,7 @@ def run_abuild(context: Context, pkgname: str, arch: Arch, apkbuild_path: Path,
pmb.chroot.root(["ln", "-s", "/mnt/linux", build_path / "src"]) pmb.chroot.root(["ln", "-s", "/mnt/linux", build_path / "src"])
pmb.chroot.root(["ln", "-s", kbuild_out_source, build_path / "src" / kbuild_out]) pmb.chroot.root(["ln", "-s", kbuild_out_source, build_path / "src" / kbuild_out])
cmd: List[PathString] = ["cp", apkbuild_path, chroot / build_path / "APKBUILD"] cmd: list[PathString] = ["cp", apkbuild_path, chroot / build_path / "APKBUILD"]
pmb.helpers.run.root(cmd) pmb.helpers.run.root(cmd)
# Create the apk package # Create the apk package

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 List
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.core.context import Context from pmb.core.context import Context
from pmb.helpers import logging from pmb.helpers import logging
@ -16,7 +15,7 @@ from pmb.core import Chroot
from pmb.core.context import get_context from pmb.core.context import get_context
def init_abuild_minimal(chroot: Chroot = Chroot.native(), additional_pkgs: List[str] = []): def init_abuild_minimal(chroot: Chroot = Chroot.native(), additional_pkgs: list[str] = []):
"""Initialize a minimal chroot with abuild where one can do 'abuild checksum'.""" """Initialize a minimal chroot with abuild where one can do 'abuild checksum'."""
marker = chroot / "tmp/pmb_chroot_abuild_init_done" marker = chroot / "tmp/pmb_chroot_abuild_init_done"
if os.path.exists(marker): if os.path.exists(marker):

View file

@ -4,7 +4,7 @@ import os
from pmb.core.context import get_context from pmb.core.context import get_context
from pmb.helpers import logging from pmb.helpers import logging
from pathlib import Path from pathlib import Path
from typing import Any, Dict from typing import Any
import pmb.build import pmb.build
import pmb.build.autodetect import pmb.build.autodetect
@ -50,7 +50,7 @@ def get_arch(apkbuild):
return apkbuild["arch"][0] return apkbuild["arch"][0]
def get_outputdir(pkgname: str, apkbuild: Dict[str, Any]) -> Path: def get_outputdir(pkgname: str, apkbuild: dict[str, Any]) -> Path:
"""Get the folder for the kernel compilation output. """Get the folder for the kernel compilation output.
For most APKBUILDs, this is $builddir. But some older ones still use For most APKBUILDs, this is $builddir. But some older ones still use

View file

@ -6,7 +6,6 @@ import os
from pathlib import Path from pathlib import Path
import shlex import shlex
import datetime import datetime
from typing import List
import pmb.chroot import pmb.chroot
import pmb.config.pmaports import pmb.config.pmaports
@ -138,7 +137,7 @@ def index_repo(arch=None):
""" """
pmb.build.init() pmb.build.init()
paths: List[Path] = [] paths: list[Path] = []
for channel in pmb.config.pmaports.all_channels(): for channel in pmb.config.pmaports.all_channels():
pkgdir: Path = get_context().config.work / "packages" / channel pkgdir: Path = get_context().config.work / "packages" / channel

View file

@ -7,7 +7,7 @@ import pmb.chroot.apk_static
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.helpers import logging from pmb.helpers import logging
import shlex import shlex
from typing import List, Sequence, Set from collections.abc import Sequence
import pmb.build import pmb.build
import pmb.chroot import pmb.chroot
@ -28,7 +28,7 @@ from pmb.types import PathString
@Cache("chroot", "user_repository", mirrors_exclude=[]) @Cache("chroot", "user_repository", mirrors_exclude=[])
def update_repository_list( def update_repository_list(
chroot: Chroot, user_repository=False, mirrors_exclude: List[str] = [], check=False chroot: Chroot, user_repository=False, mirrors_exclude: list[str] = [], check=False
): ):
""" """
Update /etc/apk/repositories, if it is outdated (when the user changed the Update /etc/apk/repositories, if it is outdated (when the user changed the
@ -42,7 +42,7 @@ def update_repository_list(
""" """
# Read old entries or create folder structure # Read old entries or create folder structure
path = chroot / "etc/apk/repositories" path = chroot / "etc/apk/repositories"
lines_old: List[str] = [] lines_old: list[str] = []
if path.exists(): if path.exists():
# Read all old lines # Read all old lines
lines_old = [] lines_old = []
@ -118,7 +118,7 @@ def packages_split_to_add_del(packages):
return (to_add, to_del) return (to_add, to_del)
def packages_get_locally_built_apks(packages, arch: Arch) -> List[Path]: def packages_get_locally_built_apks(packages, arch: Arch) -> list[Path]:
""" """
Iterate over packages and if existing, get paths to locally built packages. Iterate over packages and if existing, get paths to locally built packages.
This is used to force apk to upgrade packages to newer local versions, even This is used to force apk to upgrade packages to newer local versions, even
@ -130,12 +130,12 @@ def packages_get_locally_built_apks(packages, arch: Arch) -> List[Path]:
the second is a list of apk file paths that are valid inside the chroots, e.g. the second is a list of apk file paths that are valid inside the chroots, e.g.
["/mnt/pmbootstrap/packages/x86_64/hello-world-1-r6.apk", ...] ["/mnt/pmbootstrap/packages/x86_64/hello-world-1-r6.apk", ...]
""" """
channels: List[str] = pmb.config.pmaports.all_channels() channels: list[str] = pmb.config.pmaports.all_channels()
local: List[Path] = [] local: list[Path] = []
packages = set(packages) packages = set(packages)
walked: Set[str] = set() walked: set[str] = set()
while len(packages): while len(packages):
package = packages.pop() package = packages.pop()
data_repo = pmb.parse.apkindex.package(package, arch, False) data_repo = pmb.parse.apkindex.package(package, arch, False)
@ -163,9 +163,9 @@ def packages_get_locally_built_apks(packages, arch: Arch) -> List[Path]:
return local return local
# FIXME: List[Sequence[PathString]] weirdness # FIXME: list[Sequence[PathString]] weirdness
# mypy: disable-error-code="operator" # mypy: disable-error-code="operator"
def install_run_apk(to_add: List[str], to_add_local: List[Path], to_del: List[str], chroot: Chroot): def install_run_apk(to_add: list[str], to_add_local: list[Path], to_del: list[str], chroot: Chroot):
""" """
Run apk to add packages, and ensure only the desired packages get Run apk to add packages, and ensure only the desired packages get
explicitly marked as installed. explicitly marked as installed.
@ -186,7 +186,7 @@ def install_run_apk(to_add: List[str], to_add_local: List[Path], to_del: List[st
if package.startswith("-"): if package.startswith("-"):
raise ValueError(f"Invalid package name: {package}") raise ValueError(f"Invalid package name: {package}")
commands: List[Sequence[PathString]] = [["add"] + to_add] commands: list[Sequence[PathString]] = [["add"] + to_add]
# Use a virtual package to mark only the explicitly requested packages as # Use a virtual package to mark only the explicitly requested packages as
# explicitly installed, not the ones in to_add_local # explicitly installed, not the ones in to_add_local

View file

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import enum import enum
import filecmp import filecmp
from typing import List
from pmb.meta import Cache from pmb.meta import Cache
from pmb.helpers import logging from pmb.helpers import logging
import os import os
@ -19,7 +18,7 @@ import pmb.helpers.other
from pmb.core import Chroot, ChrootType from pmb.core import Chroot, ChrootType
from pmb.core.context import get_context from pmb.core.context import get_context
cache_chroot_is_outdated: List[str] = [] cache_chroot_is_outdated: list[str] = []
class UsrMerge(enum.Enum): class UsrMerge(enum.Enum):

View file

@ -5,7 +5,6 @@ from pmb.core.pkgrepo import pkgrepo_default_path
from pmb.helpers import logging from pmb.helpers import logging
import os import os
from pathlib import Path from pathlib import Path
from typing import Dict
import pmb.chroot.binfmt import pmb.chroot.binfmt
import pmb.config import pmb.config
import pmb.helpers.run import pmb.helpers.run
@ -120,7 +119,7 @@ def mount(chroot: Chroot):
# Get all mountpoints # Get all mountpoints
arch = chroot.arch arch = chroot.arch
channel = pmb.config.pmaports.read_config(pkgrepo_default_path())["channel"] channel = pmb.config.pmaports.read_config(pkgrepo_default_path())["channel"]
mountpoints: Dict[Path, Path] = {} mountpoints: dict[Path, Path] = {}
for src_template, target_template in pmb.config.chroot_mount_bind.items(): for src_template, target_template in pmb.config.chroot_mount_bind.items():
src_template = src_template.replace("$WORK", os.fspath(get_context().config.work)) src_template = src_template.replace("$WORK", os.fspath(get_context().config.work))
src_template = src_template.replace("$ARCH", str(arch)) src_template = src_template.replace("$ARCH", str(arch))

View file

@ -3,7 +3,7 @@
import os import os
from pathlib import Path, PurePath from pathlib import Path, PurePath
import shutil import shutil
from typing import Sequence from collections.abc import Sequence
import pmb.config import pmb.config
import pmb.chroot import pmb.chroot

View file

@ -3,7 +3,8 @@
from __future__ import annotations from __future__ import annotations
import enum import enum
from typing import Generator, Optional from typing import Optional
from collections.abc import Generator
from pathlib import Path, PosixPath, PurePosixPath from pathlib import Path, PosixPath, PurePosixPath
from pmb.types import PmbArgs from pmb.types import PmbArgs
from pmb.helpers import frontend from pmb.helpers import frontend

View file

@ -4,7 +4,7 @@ import os
from pathlib import Path from pathlib import Path
from pmb.types import AportGenEntry, PathString from pmb.types import AportGenEntry, PathString
import sys import sys
from typing import Dict, List, Sequence from collections.abc import Sequence
# #
# Exported functions # Exported functions
@ -74,7 +74,7 @@ def sudo(cmd: Sequence[PathString]) -> Sequence[PathString]:
return cmd return cmd
defaults: Dict[str, PathString] = { defaults: dict[str, PathString] = {
"cipher": "aes-xts-plain64", "cipher": "aes-xts-plain64",
"config": Path( "config": Path(
(os.environ.get("XDG_CONFIG_HOME") or os.path.expanduser("~/.config")) + "/pmbootstrap.cfg" (os.environ.get("XDG_CONFIG_HOME") or os.path.expanduser("~/.config")) + "/pmbootstrap.cfg"
@ -784,7 +784,7 @@ Fastboot specific: $KERNEL_CMDLINE
Heimdall specific: $PARTITION_INITFS Heimdall specific: $PARTITION_INITFS
uuu specific: $UUU_SCRIPT uuu specific: $UUU_SCRIPT
""" """
flashers: Dict[str, Dict[str, bool | List[str] | Dict[str, List[List[str]]]]] = { flashers: dict[str, dict[str, bool | list[str] | dict[str, list[list[str]]]]] = {
"fastboot": { "fastboot": {
"depends": [], # pmaports.cfg: supported_fastboot_depends "depends": [], # pmaports.cfg: supported_fastboot_depends
"actions": { "actions": {
@ -984,7 +984,7 @@ git_repos = {
# #
# APORTGEN # APORTGEN
# #
aportgen: Dict[str, AportGenEntry] = { aportgen: dict[str, AportGenEntry] = {
"cross": { "cross": {
"prefixes": ["busybox-static", "gcc", "musl", "grub-efi"], "prefixes": ["busybox-static", "gcc", "musl", "grub-efi"],
"confirm_overwrite": False, "confirm_overwrite": False,

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, PosixPath from pathlib import Path, PosixPath
from typing import List
from pmb.helpers import logging from pmb.helpers import logging
import configparser import configparser
import os import os
@ -45,7 +44,7 @@ def load(path: Path) -> Config:
setattr(config, key, Path(cfg["pmbootstrap"][key])) setattr(config, key, Path(cfg["pmbootstrap"][key]))
# Yeah this really sucks and there isn't a better way to do it without external # Yeah this really sucks and there isn't a better way to do it without external
# libraries # libraries
elif isinstance(getattr(Config, key), List) and isinstance( elif isinstance(getattr(Config, key), list) and isinstance(
getattr(Config, key)[0], PosixPath getattr(Config, key)[0], PosixPath
): ):
value = cfg["pmbootstrap"][key] value = cfg["pmbootstrap"][key]
@ -97,7 +96,7 @@ def serialize(config: Config, skip_defaults=True) -> configparser.ConfigParser:
# Convert strings to paths # Convert strings to paths
elif type(getattr(Config, key)) == PosixPath: elif type(getattr(Config, key)) == PosixPath:
cfg["pmbootstrap"][key] = str(getattr(config, key)) cfg["pmbootstrap"][key] = str(getattr(config, key))
elif isinstance(getattr(Config, key), List) and isinstance( elif isinstance(getattr(Config, key), list) and isinstance(
getattr(Config, key)[0], PosixPath getattr(Config, key)[0], PosixPath
): ):
cfg["pmbootstrap"][key] = ",".join(os.fspath(p) for p in getattr(config, key)) cfg["pmbootstrap"][key] = ",".join(os.fspath(p) for p in getattr(config, key))

View file

@ -124,7 +124,7 @@ def ask_for_channel(config: Config):
channels_cfg = pmb.helpers.git.parse_channels_cfg(pkgrepo_default_path()) channels_cfg = pmb.helpers.git.parse_channels_cfg(pkgrepo_default_path())
count = len(channels_cfg["channels"]) count = len(channels_cfg["channels"])
# List channels # list channels
logging.info("Choose the postmarketOS release channel.") logging.info("Choose the postmarketOS release channel.")
logging.info(f"Available ({count}):") logging.info(f"Available ({count}):")
# Only show the first 3 releases. This includes edge, the latest supported # Only show the first 3 releases. This includes edge, the latest supported
@ -377,7 +377,7 @@ def ask_for_device_kernel(config: Config, device: str):
" downstream kernels." " downstream kernels."
) )
# List kernels # list kernels
logging.info(f"Available kernels ({len(kernels)}):") logging.info(f"Available kernels ({len(kernels)}):")
for type in sorted(kernels.keys()): for type in sorted(kernels.keys()):
logging.info(f"* {type}: {kernels[type]}") logging.info(f"* {type}: {kernels[type]}")
@ -554,7 +554,7 @@ def ask_for_mirror():
with open(json_path) as handle: with open(json_path) as handle:
s = handle.read() s = handle.read()
logging.info("List of available mirrors:") logging.info("list of available mirrors:")
mirrors = json.loads(s) mirrors = json.loads(s)
keys = mirrors.keys() keys = mirrors.keys()
i = 1 i = 1

View file

@ -2,7 +2,7 @@
# 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 List, Optional 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
@ -132,7 +132,7 @@ def read_config(aports: Optional[Path] = None):
return ret return ret
def all_channels() -> List[str]: def all_channels() -> list[str]:
"""Get a list of all channels for all pkgrepos.""" """Get a list of all channels for all pkgrepos."""
ret = set() ret = set()
for repo in pkgrepo_paths(): for repo in pkgrepo_paths():
@ -200,7 +200,7 @@ def switch_to_channel_branch(channel_new):
return False return False
aports = pkgrepo_default_path() aports = pkgrepo_default_path()
# List current and new branches/channels # list current and new branches/channels
channels_cfg = pmb.helpers.git.parse_channels_cfg(aports) channels_cfg = pmb.helpers.git.parse_channels_cfg(aports)
branch_new = channels_cfg["channels"][channel_new]["branch_pmaports"] branch_new = channels_cfg["channels"][channel_new]["branch_pmaports"]
branch_current = pmb.helpers.git.rev_parse(aports, extra_args=["--abbrev-ref"]) branch_current = pmb.helpers.git.rev_parse(aports, extra_args=["--abbrev-ref"])

View file

@ -3,7 +3,6 @@
import enum import enum
from pathlib import Path, PosixPath, PurePosixPath from pathlib import Path, PosixPath, PurePosixPath
import platform import platform
from typing import Set
# Initialised at the bottom # Initialised at the bottom
_cached_native_arch: "Arch" _cached_native_arch: "Arch"
@ -69,7 +68,7 @@ class Arch(enum.Enum):
return self == Arch.native() return self == Arch.native()
@staticmethod @staticmethod
def supported() -> Set["Arch"]: def supported() -> set["Arch"]:
"""Officially supported host/target architectures for postmarketOS. Only """Officially supported host/target architectures for postmarketOS. Only
specify architectures supported by Alpine here. For cross-compiling, specify architectures supported by Alpine here. For cross-compiling,
we need to generate the "musl-$ARCH" and "gcc-$ARCH" packages (use we need to generate the "musl-$ARCH" and "gcc-$ARCH" packages (use

View file

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
import enum import enum
from typing import Generator from collections.abc import Generator
from pathlib import Path, PosixPath, PurePosixPath from pathlib import Path, PosixPath, PurePosixPath
import pmb.config import pmb.config
from pmb.core.arch import Arch from pmb.core.arch import Arch

View file

@ -1,7 +1,7 @@
from copy import deepcopy from copy import deepcopy
import enum import enum
import multiprocessing import multiprocessing
from typing import Any, List, Dict, TypedDict from typing import Any, TypedDict
from pathlib import Path from pathlib import Path
import os import os
@ -21,7 +21,7 @@ class SystemdConfig(enum.Enum):
return self.value return self.value
@staticmethod @staticmethod
def choices() -> List[str]: def choices() -> list[str]:
return [e.value for e in SystemdConfig] return [e.value for e in SystemdConfig]
@ -41,7 +41,7 @@ class AutoZapConfig(enum.Enum):
class Config: class Config:
aports: List[Path] = [ aports: list[Path] = [
Path(os.path.expanduser("~") + "/.local/var/pmbootstrap/cache_git/pmaports") Path(os.path.expanduser("~") + "/.local/var/pmbootstrap/cache_git/pmaports")
] ]
boot_size: int = 256 boot_size: int = 256
@ -75,7 +75,7 @@ class Config:
# automatically zap chroots that are for the wrong channel # automatically zap chroots that are for the wrong channel
auto_zap_misconfigured_chroots: AutoZapConfig = AutoZapConfig.NO auto_zap_misconfigured_chroots: AutoZapConfig = AutoZapConfig.NO
providers: Dict[str, str] = {} providers: dict[str, str] = {}
def __init__(self): def __init__(self):
# Make sure we aren't modifying the class defaults # Make sure we aren't modifying the class defaults
@ -83,7 +83,7 @@ class Config:
setattr(self, key, deepcopy(Config.get_default(key))) setattr(self, key, deepcopy(Config.get_default(key)))
@staticmethod @staticmethod
def keys() -> List[str]: def keys() -> list[str]:
keys = list(Config.__annotations__.keys()) keys = list(Config.__annotations__.keys())
keys.remove("mirrors") keys.remove("mirrors")
keys += [f"mirrors.{k}" for k in Mirrors.__annotations__.keys()] keys += [f"mirrors.{k}" for k in Mirrors.__annotations__.keys()]

View file

@ -3,7 +3,6 @@
import enum import enum
from pathlib import Path from pathlib import Path
from typing import List
from pmb.core.chroot import ChrootType from pmb.core.chroot import ChrootType
from pmb.types import PathString from pmb.types import PathString
@ -17,9 +16,9 @@ class CrossToolTarget(enum.Enum):
class CrossTool: class CrossTool:
__target: CrossToolTarget __target: CrossToolTarget
__package: str __package: str
__paths: List[Path] __paths: list[Path]
def __init__(self, target: CrossToolTarget, package: str, paths: List[PathString]): def __init__(self, target: CrossToolTarget, package: str, paths: list[PathString]):
self.__target = target self.__target = target
self.__package = package self.__package = package
self.__paths = list(map(lambda p: Path(p) if isinstance(p, str) else p, paths)) self.__paths = list(map(lambda p: Path(p) if isinstance(p, str) else p, paths))
@ -32,7 +31,7 @@ class CrossTool:
return self.__package return self.__package
@property @property
def paths(self) -> List[Path]: def paths(self) -> list[Path]:
return self.__paths return self.__paths
def should_install(self, target: ChrootType) -> bool: def should_install(self, target: ChrootType) -> bool:

View file

@ -1,7 +1,8 @@
import os import os
import glob import glob
from pathlib import Path from pathlib import Path
from typing import Dict, Generator, List, Optional, Tuple from typing import Optional
from collections.abc import Generator
import pmb.config import pmb.config
from pmb.core.context import get_context from pmb.core.context import get_context
@ -9,7 +10,7 @@ from pmb.meta import Cache
@Cache(skip_extras=False) @Cache(skip_extras=False)
def pkgrepo_paths(skip_extras=False) -> List[Path]: def pkgrepo_paths(skip_extras=False) -> list[Path]:
config = get_context().config config = get_context().config
paths = list(map(lambda x: Path(x), config.aports)) paths = list(map(lambda x: Path(x), config.aports))
if not paths: if not paths:
@ -32,7 +33,7 @@ def pkgrepo_default_path() -> Path:
return pkgrepo_paths(skip_extras=True)[0] return pkgrepo_paths(skip_extras=True)[0]
def pkgrepo_names(skip_exras=False) -> List[str]: def pkgrepo_names(skip_exras=False) -> list[str]:
""" """
Return a list of all the package repository names. Return a list of all the package repository names.
""" """
@ -97,7 +98,7 @@ def pkgrepo_iter_package_dirs(skip_extra_repos=False) -> Generator[Path, None, N
Detect duplicates within the same aports repository but otherwise Detect duplicates within the same aports repository but otherwise
ignore all but the first. This allows for overriding packages. ignore all but the first. This allows for overriding packages.
""" """
seen: Dict[str, List[str]] = dict(map(lambda a: (a, []), pkgrepo_names(skip_extra_repos))) seen: dict[str, list[str]] = dict(map(lambda a: (a, []), pkgrepo_names(skip_extra_repos)))
for repo in pkgrepo_paths(skip_extra_repos): for repo in pkgrepo_paths(skip_extra_repos):
for g in glob.iglob(os.path.join(repo, "**/*/APKBUILD"), recursive=True): for g in glob.iglob(os.path.join(repo, "**/*/APKBUILD"), recursive=True):
pdir = Path(g).parent pdir = Path(g).parent
@ -116,7 +117,7 @@ def pkgrepo_iter_package_dirs(skip_extra_repos=False) -> Generator[Path, None, N
yield pdir yield pdir
def pkgrepo_relative_path(path: Path) -> Tuple[Path, Path]: def pkgrepo_relative_path(path: Path) -> tuple[Path, Path]:
""" """
Return the path relative to the first aports repository. Return the path relative to the first aports repository.
""" """

View file

@ -3,7 +3,6 @@
from pmb.core.context import get_context from pmb.core.context import get_context
from pmb.helpers import logging from pmb.helpers import logging
from pathlib import Path from pathlib import Path
from typing import List
import pmb.build import pmb.build
import pmb.chroot.apk import pmb.chroot.apk
@ -50,7 +49,7 @@ def symlinks(flavor, folder: Path):
chroot_native = Chroot.native() chroot_native = Chroot.native()
path_boot = Chroot(ChrootType.ROOTFS, context.device) / "boot" path_boot = Chroot(ChrootType.ROOTFS, context.device) / "boot"
chroot_buildroot = Chroot.buildroot(arch) chroot_buildroot = Chroot.buildroot(arch)
files: List[Path] = [ files: list[Path] = [
path_boot / f"boot.img{suffix}", path_boot / f"boot.img{suffix}",
path_boot / f"uInitrd{suffix}", path_boot / f"uInitrd{suffix}",
path_boot / f"uImage{suffix}", path_boot / f"uImage{suffix}",

View file

@ -1,7 +1,7 @@
# Copyright 2023 Johannes Marbach, Oliver Smith # Copyright 2023 Johannes Marbach, Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import os import os
from typing import List, Sequence from collections.abc import Sequence
import pmb.chroot import pmb.chroot
import pmb.config.pmaports import pmb.config.pmaports
@ -73,7 +73,7 @@ def apk_with_progress(command: Sequence[PathString]):
:raises RuntimeError: when the apk command fails :raises RuntimeError: when the apk command fails
""" """
fifo, fifo_outside = _prepare_fifo() fifo, fifo_outside = _prepare_fifo()
_command: List[str] = [] _command: list[str] = []
for c in command: for c in command:
if isinstance(c, Arch): if isinstance(c, Arch):
_command.append(str(c)) _command.append(str(c))

View file

@ -6,15 +6,15 @@ from pmb.helpers import logging
import os import os
import re import re
import urllib.parse import urllib.parse
from typing import Dict, Optional from typing import Optional
from pmb.types import PmbArgs from pmb.types import PmbArgs
import pmb.helpers.file import pmb.helpers.file
import pmb.helpers.http import pmb.helpers.http
import pmb.helpers.pmaports import pmb.helpers.pmaports
req_headers: Dict[str, str] = {} req_headers: dict[str, str] = {}
req_headers_github: Dict[str, str] = {} req_headers_github: dict[str, str] = {}
ANITYA_API_BASE = "https://release-monitoring.org/api/v2" ANITYA_API_BASE = "https://release-monitoring.org/api/v2"
GITHUB_API_BASE = "https://api.github.com" GITHUB_API_BASE = "https://api.github.com"

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 json import json
from typing import List, Sequence, Tuple from collections.abc import Sequence
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.helpers import logging from pmb.helpers import logging
import os import os
@ -82,7 +82,7 @@ def _parse_suffix(args: PmbArgs) -> Chroot:
return Chroot(ChrootType.NATIVE) return Chroot(ChrootType.NATIVE)
def _install_ondev_verify_no_rootfs(device: str, ondev_cp: List[Tuple[str, str]]): def _install_ondev_verify_no_rootfs(device: str, ondev_cp: list[tuple[str, str]]):
chroot_dest = "/var/lib/rootfs.img" chroot_dest = "/var/lib/rootfs.img"
dest = Chroot(ChrootType.INSTALLER, device) / chroot_dest dest = Chroot(ChrootType.INSTALLER, device) / chroot_dest
if dest.exists(): if dest.exists():
@ -459,7 +459,7 @@ def kconfig(args: PmbArgs):
raise RuntimeError("kconfig check failed!") raise RuntimeError("kconfig check failed!")
# Default to all kernel packages # Default to all kernel packages
packages: List[str] packages: list[str]
# FIXME (#2324): figure out the args.package vs args.packages situation # FIXME (#2324): figure out the args.package vs args.packages situation
if isinstance(args.package, list): if isinstance(args.package, list):
packages = args.package packages = args.package

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 Dict
from pmb.core.context import get_context from pmb.core.context import get_context
from pmb.core.pkgrepo import pkgrepo_path from pmb.core.pkgrepo import pkgrepo_path
from pmb.helpers import logging from pmb.helpers import logging
@ -143,7 +142,7 @@ def parse_channels_cfg(aports: Path):
) )
# Meta section # Meta section
ret: Dict[str, Dict[str, str | Dict[str, str]]] = {"channels": {}} ret: dict[str, dict[str, str | dict[str, str]]] = {"channels": {}}
ret["meta"] = {"recommended": cfg.get("channels.cfg", "recommended")} ret["meta"] = {"recommended": cfg.get("channels.cfg", "recommended")}
# Channels # Channels

View file

@ -1,6 +1,6 @@
# Copyright 2023 Danct12 <danct12@disroot.org> # Copyright 2023 Danct12 <danct12@disroot.org>
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import Dict, List, Sequence from collections.abc import Sequence
from pmb.core.chroot import Chroot from pmb.core.chroot import Chroot
from pmb.core.pkgrepo import pkgrepo_iter_package_dirs, pkgrepo_names, pkgrepo_relative_path from pmb.core.pkgrepo import pkgrepo_iter_package_dirs, pkgrepo_names, pkgrepo_relative_path
from pmb.helpers import logging from pmb.helpers import logging
@ -31,7 +31,7 @@ def check(pkgnames: Sequence[str]):
# Locate all APKBUILDs and make the paths be relative to the pmaports # Locate all APKBUILDs and make the paths be relative to the pmaports
# root # root
apkbuilds: Dict[str, List[str]] = dict(map(lambda x: (x, []), pkgrepo_names())) apkbuilds: dict[str, list[str]] = dict(map(lambda x: (x, []), pkgrepo_names()))
found_pkgnames = set() found_pkgnames = set()
# If a package exists in multiple aports we will lint all of them # If a package exists in multiple aports we will lint all of them
# since.. well, what else do we do? # since.. well, what else do we do?

View file

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import os import os
from pathlib import Path, PurePath from pathlib import Path, PurePath
from typing import List
import pmb.helpers import pmb.helpers
from pmb.core import Chroot from pmb.core import Chroot
import pmb.helpers.run import pmb.helpers.run
@ -72,7 +71,7 @@ def bind_file(source: Path, destination: Path, create_folders=False):
pmb.helpers.run.root(["mount", "--bind", source, destination]) pmb.helpers.run.root(["mount", "--bind", source, destination])
def umount_all_list(prefix: Path, source: Path = Path("/proc/mounts")) -> List[Path]: def umount_all_list(prefix: Path, source: Path = Path("/proc/mounts")) -> list[Path]:
"""Parse `/proc/mounts` for all folders beginning with a prefix. """Parse `/proc/mounts` for all folders beginning with a prefix.
:source: can be changed for testcases :source: can be changed for testcases

View file

@ -12,7 +12,7 @@ import pmb.config.init
from pmb.types import PmbArgs from pmb.types import PmbArgs
import pmb.helpers.pmaports import pmb.helpers.pmaports
import pmb.helpers.run import pmb.helpers.run
from typing import Dict, Any from typing import Any
def folder_size(path: Path): def folder_size(path: Path):
@ -291,7 +291,7 @@ def lookup(key):
pmb.helpers.other.cache["mycache"][key] = ret pmb.helpers.other.cache["mycache"][key] = ret
return ret return ret
""" """
cache: Dict[str, Any] = { cache: dict[str, Any] = {
"apkindex": {}, "apkindex": {},
"pmb.helpers.repo.update": {"404": [], "offline_msg_shown": False}, "pmb.helpers.repo.update": {"404": [], "offline_msg_shown": False},
} }

View file

@ -10,7 +10,7 @@ See also:
""" """
import copy import copy
from typing import Any, Dict from typing import Any
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
from pmb.helpers import logging from pmb.helpers import logging
@ -50,7 +50,7 @@ def get(pkgname, arch, replace_subpkgnames=False, must_exist=True):
* None if the package was not found * None if the package was not found
""" """
# Find in pmaports # Find in pmaports
ret: Dict[str, Any] = {} ret: dict[str, Any] = {}
pmaport = pmb.helpers.pmaports.get(pkgname, False) pmaport = pmb.helpers.pmaports.get(pkgname, False)
if pmaport: if pmaport:
ret = { ret = {

View file

@ -12,13 +12,14 @@ 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, Sequence, Dict, Tuple from typing import Any, Optional
from collections.abc import Sequence
from pmb.meta import Cache from pmb.meta import Cache
import pmb.parse import pmb.parse
def _find_apkbuilds(skip_extra_repos=False) -> Dict[str, Path]: def _find_apkbuilds(skip_extra_repos=False) -> dict[str, Path]:
# 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)
apkbuilds = pmb.helpers.other.cache.get("pmb.helpers.pmaports.apkbuilds") apkbuilds = pmb.helpers.other.cache.get("pmb.helpers.pmaports.apkbuilds")
@ -215,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[Optional[Path], Optional[dict[str, Any]]]:
"""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.
@ -243,7 +244,7 @@ def get_with_path(
return None, None return None, None
def get(pkgname, must_exist=True, subpackages=True, skip_extra_repos=False) -> Dict[str, Any]: def get(pkgname, must_exist=True, subpackages=True, skip_extra_repos=False) -> dict[str, Any]:
return get_with_path(pkgname, must_exist, subpackages, skip_extra_repos)[1] return get_with_path(pkgname, must_exist, subpackages, skip_extra_repos)[1]

View file

@ -15,7 +15,7 @@ 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 List, Optional from typing import Optional
import pmb.config.pmaports import pmb.config.pmaports
from pmb.meta import Cache from pmb.meta import Cache
@ -54,7 +54,7 @@ def apkindex_hash(url: str, length: int = 8) -> Path:
# FIXME: make config.mirrors a normal dict # FIXME: make config.mirrors a normal dict
# mypy: disable-error-code="literal-required" # mypy: disable-error-code="literal-required"
@Cache("user_repository", "mirrors_exclude") @Cache("user_repository", "mirrors_exclude")
def urls(user_repository=False, mirrors_exclude: List[str] = []): def urls(user_repository=False, mirrors_exclude: list[str] = []):
"""Get a list of repository URLs, as they are in /etc/apk/repositories. """Get a list of repository URLs, as they are in /etc/apk/repositories.
:param user_repository: add /mnt/pmbootstrap/packages :param user_repository: add /mnt/pmbootstrap/packages
@ -62,7 +62,7 @@ def urls(user_repository=False, mirrors_exclude: List[str] = []):
:returns: list of mirror strings, like ["/mnt/pmbootstrap/packages", :returns: list of mirror strings, like ["/mnt/pmbootstrap/packages",
"http://...", ...] "http://...", ...]
""" """
ret: List[str] = [] ret: list[str] = []
config = get_context().config config = get_context().config
# Get mirrordirs from channels.cfg (postmarketOS mirrordir is the same as # Get mirrordirs from channels.cfg (postmarketOS mirrordir is the same as
@ -104,8 +104,8 @@ 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: Optional[Arch] = 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.
:param arch: defaults to native :param arch: defaults to native
@ -158,7 +158,7 @@ def update(arch: Optional[Arch] = None, force=False, existing_only=False):
# outdated: {URL: apkindex_path, ... } # outdated: {URL: apkindex_path, ... }
# outdated_arches: ["armhf", "x86_64", ... ] # outdated_arches: ["armhf", "x86_64", ... ]
outdated = {} outdated = {}
outdated_arches: List[Arch] = [] outdated_arches: list[Arch] = []
for url in urls(False): for url in urls(False):
for arch in architectures: for arch in architectures:
# APKINDEX file name from the URL # APKINDEX file name from the URL

View file

@ -5,7 +5,8 @@ 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, Sequence from typing import Optional
from collections.abc import Sequence
from pmb.types import Env, PathString from pmb.types import Env, PathString

View file

@ -13,7 +13,8 @@ import subprocess
import sys import sys
import threading import threading
import time import time
from typing import Optional, Sequence from typing import Optional
from collections.abc import Sequence
import pmb.helpers.run import pmb.helpers.run
"""For a detailed description of all output modes, read the description of """For a detailed description of all output modes, read the description of

View file

@ -7,7 +7,8 @@ import re
import glob import glob
import shlex import shlex
import sys import sys
from typing import Dict, List, Optional, Sequence from typing import Optional
from collections.abc import Sequence
from pathlib import Path from pathlib import Path
import pmb.build import pmb.build
@ -34,8 +35,8 @@ from pmb.core.context import get_context
# Keep track of the packages we already visited in get_recommends() to avoid # Keep track of the packages we already visited in get_recommends() to avoid
# infinite recursion # infinite recursion
get_recommends_visited: List[str] = [] get_recommends_visited: list[str] = []
get_selected_providers_visited: List[str] = [] get_selected_providers_visited: list[str] = []
def get_subpartitions_size(chroot: Chroot): def get_subpartitions_size(chroot: Chroot):
@ -135,7 +136,7 @@ def copy_files_from_chroot(args: PmbArgs, chroot: Chroot):
pmb.helpers.run.root(["rm", fifo]) pmb.helpers.run.root(["rm", fifo])
# Get all folders inside the device rootfs (except for home) # Get all folders inside the device rootfs (except for home)
folders: List[str] = [] folders: list[str] = []
for path in mountpoint_outside.glob("*"): for path in mountpoint_outside.glob("*"):
if path.name == "home": if path.name == "home":
continue continue
@ -542,7 +543,7 @@ def generate_binary_list(args: PmbArgs, chroot: Chroot, step):
rootfs_{args.device} or installer_{args.device} rootfs_{args.device} or installer_{args.device}
:param step: partition step size in bytes :param step: partition step size in bytes
""" """
binary_ranges: Dict[int, int] = {} binary_ranges: dict[int, int] = {}
binary_list = [] binary_list = []
binaries = pmb.parse.deviceinfo().sd_embed_firmware.split(",") binaries = pmb.parse.deviceinfo().sd_embed_firmware.split(",")
@ -1188,7 +1189,7 @@ def get_recommends(args: PmbArgs, packages) -> Sequence[str]:
""" """
global get_recommends_visited global get_recommends_visited
ret: List[str] = [] ret: list[str] = []
if not args.install_recommends: if not args.install_recommends:
return ret return ret
@ -1229,7 +1230,7 @@ def get_recommends(args: PmbArgs, packages) -> Sequence[str]:
def create_device_rootfs(args: PmbArgs, step, steps): def create_device_rootfs(args: PmbArgs, step, steps):
# List all packages to be installed (including the ones specified by --add) # list all packages to be installed (including the ones specified by --add)
# and upgrade the installed packages/apkindexes # and upgrade the installed packages/apkindexes
context = get_context() context = get_context()
config = context.config config = context.config

View file

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import json import json
from pathlib import Path from pathlib import Path
from typing import List
from pmb.core.context import get_context from pmb.core.context import get_context
from pmb.helpers import logging from pmb.helpers import logging
import time import time
@ -39,7 +38,7 @@ def mount(img_path: Path):
# Mount and return on success # Mount and return on success
init() init()
losetup_cmd: List[PathString] = ["losetup", "-f", img_path] losetup_cmd: list[PathString] = ["losetup", "-f", img_path]
sector_size = pmb.parse.deviceinfo().rootfs_image_sector_size sector_size = pmb.parse.deviceinfo().rootfs_image_sector_size
if sector_size: if sector_size:
losetup_cmd += ["-b", str(int(sector_size))] losetup_cmd += ["-b", str(int(sector_size))]

View file

@ -1,19 +1,18 @@
# Copyright 2023 Dylan Van Assche # Copyright 2023 Dylan Van Assche
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import List
from pmb.helpers import logging from pmb.helpers import logging
from pmb.core import Config from pmb.core import Config
import pmb.helpers.pmaports import pmb.helpers.pmaports
def get_groups(config: Config) -> List[str]: def get_groups(config: Config) -> list[str]:
"""Get all groups to which the user additionally must be added. """Get all groups to which the user additionally must be added.
The list of groups are listed in _pmb_groups of the UI and The list of groups are listed in _pmb_groups of the UI and
UI-extras package. UI-extras package.
:returns: list of groups, e.g. ["feedbackd", "udev"]""" :returns: list of groups, e.g. ["feedbackd", "udev"]"""
ret: List[str] = [] ret: list[str] = []
if config.ui == "none": if config.ui == "none":
return ret return ret

View file

@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import copy import copy
from typing import Callable, Dict, Optional from typing import Callable, Optional
import inspect import inspect
@ -83,7 +83,7 @@ class Cache:
signature = inspect.signature(func) signature = inspect.signature(func)
passed_args: Dict[str, str] = {} passed_args: dict[str, str] = {}
for i, (k, val) in enumerate(signature.parameters.items()): for i, (k, val) in enumerate(signature.parameters.items()):
if k in self.params or k in self.kwargs: if k in self.params or k in self.kwargs:
if i < len(args): if i < len(args):

View file

@ -1,5 +1,3 @@
from typing import List
from . import Cache, Wrapper from . import Cache, Wrapper
@ -30,7 +28,7 @@ def test_cache_hits_basic():
def test_cache_hits_kwargs(): def test_cache_hits_kwargs():
def multiply_2(x: int, y: int = 2, z: List[int] = []) -> int: def multiply_2(x: int, y: int = 2, z: list[int] = []) -> int:
return x * y + sum(z) return x * y + sum(z)
multiply_2_cached = Cache("x", "y", "z")(multiply_2) multiply_2_cached = Cache("x", "y", "z")(multiply_2)
@ -68,7 +66,7 @@ def test_cache_hits_kwargs():
def test_build_key(): def test_build_key():
def multiply_2(x: int, y: int = 2, z: List[int] = []) -> int: def multiply_2(x: int, y: int = 2, z: list[int] = []) -> int:
return x * y + sum(z) return x * y + sum(z)
multiply_2_cached = Cache("x", "y", "z")(multiply_2) multiply_2_cached = Cache("x", "y", "z")(multiply_2)

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 collections import collections
from typing import Any, Dict, List, Optional, Sequence from typing import Any, Optional
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
from pmb.helpers import logging from pmb.helpers import logging
@ -26,7 +27,7 @@ apkindex_map = {
required_apkindex_keys = ["arch", "pkgname", "version"] required_apkindex_keys = ["arch", "pkgname", "version"]
def parse_next_block(path: Path, lines: List[str]): def parse_next_block(path: Path, lines: list[str]):
"""Parse the next block in an APKINDEX. """Parse the next block in an APKINDEX.
:param path: to the APKINDEX.tar.gz :param path: to the APKINDEX.tar.gz
@ -34,7 +35,7 @@ def parse_next_block(path: Path, lines: List[str]):
function. Wrapped into a list, so it can be modified function. Wrapped into a list, so it can be modified
"by reference". Example: [5] "by reference". Example: [5]
:param lines: all lines from the "APKINDEX" file inside the archive :param lines: all lines from the "APKINDEX" file inside the archive
:returns: Dictionary with the following structure: :returns: dictionary with the following structure:
``{ "arch": "noarch", "depends": ["busybox-extras", "lddtree", ... ], ``{ "arch": "noarch", "depends": ["busybox-extras", "lddtree", ... ],
"origin": "postmarketos-mkinitfs", "origin": "postmarketos-mkinitfs",
"pkgname": "postmarketos-mkinitfs", "pkgname": "postmarketos-mkinitfs",
@ -49,7 +50,7 @@ def parse_next_block(path: Path, lines: List[str]):
:returns: None, when there are no more blocks :returns: None, when there are no more blocks
""" """
# Parse until we hit an empty line or end of file # Parse until we hit an empty line or end of file
ret: Dict[str, Any] = {} ret: dict[str, Any] = {}
required_found = 0 # Count the required keys we found required_found = 0 # Count the required keys we found
line = "" line = ""
while len(lines): while len(lines):
@ -207,7 +208,7 @@ def parse(path: Path, multiple_providers=True):
return {} return {}
# Parse the whole APKINDEX file # Parse the whole APKINDEX file
ret: Dict[str, Any] = collections.OrderedDict() ret: dict[str, Any] = collections.OrderedDict()
if lines[-1] == "\n": if lines[-1] == "\n":
lines.pop() # Strip the trailing newline lines.pop() # Strip the trailing newline
while True: while True:
@ -252,7 +253,7 @@ def parse_blocks(path: Path):
lines = handle.read().decode().splitlines() lines = handle.read().decode().splitlines()
# Parse lines into blocks # Parse lines into blocks
ret: List[str] = [] ret: list[str] = []
while True: while True:
block = pmb.parse.apkindex.parse_next_block(path, lines) block = pmb.parse.apkindex.parse_next_block(path, lines)
if not block: if not block:
@ -302,7 +303,7 @@ def providers(package, arch: Optional[Arch] = None, must_exist=True, indexes=Non
package = pmb.helpers.package.remove_operators(package) package = pmb.helpers.package.remove_operators(package)
ret: Dict[str, Any] = collections.OrderedDict() ret: dict[str, Any] = collections.OrderedDict()
for path in indexes: for path in indexes:
# Skip indexes not providing the package # Skip indexes not providing the package
index_packages = parse(path) index_packages = parse(path)

View file

@ -109,7 +109,7 @@ def bootimg(path: Path):
) )
if ( if (
"linux kernel" in file_output.lower() "linux kernel" in file_output.lower()
or "ARM OpenFirmware FORTH Dictionary" in file_output or "ARM OpenFirmware FORTH dictionary" in file_output
): ):
raise RuntimeError( raise RuntimeError(
"File is a Kernel image, you might need the" "File is a Kernel image, you might need the"

View file

@ -2,7 +2,7 @@
# 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 Dict, Optional 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
@ -170,7 +170,7 @@ class Deviceinfo:
keymaps: Optional[str] = "" keymaps: Optional[str] = ""
@staticmethod @staticmethod
def __validate(info: Dict[str, str], path: Path): def __validate(info: dict[str, str], path: Path):
# Resolve path for more readable error messages # Resolve path for more readable error messages
path = path.resolve() path = path.resolve()

View file

@ -1,7 +1,7 @@
# Copyright 2023 Pablo Castellano, Oliver Smith # Copyright 2023 Pablo Castellano, Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import subprocess import subprocess
from typing import Sequence from collections.abc import Sequence
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.core.config import Config from pmb.core.config import Config
from pmb.core.context import get_context from pmb.core.context import get_context

View file

@ -1,7 +1,7 @@
# Copyright 2023 Martijn Braam # Copyright 2023 Martijn Braam
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import os import os
from typing import List, Optional from typing import Optional
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.helpers import logging from pmb.helpers import logging
import shlex import shlex
@ -27,12 +27,12 @@ def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str):
key_name = os.path.basename(key) key_name = os.path.basename(key)
logging.info(f"Copying signing key ({key_name}) to {user}@{host}") logging.info(f"Copying signing key ({key_name}) to {user}@{host}")
command: List[PathString] = ["scp", "-P", port, key, f"{user}@{host}:/tmp"] command: list[PathString] = ["scp", "-P", port, key, f"{user}@{host}:/tmp"]
pmb.helpers.run.user(command, output="interactive") pmb.helpers.run.user(command, output="interactive")
logging.info(f"Installing signing key at {user}@{host}") logging.info(f"Installing signing key at {user}@{host}")
keyname = os.path.join("/tmp", os.path.basename(key)) keyname = os.path.join("/tmp", os.path.basename(key))
remote_cmd_l: List[PathString] = [ remote_cmd_l: list[PathString] = [
"sudo", "sudo",
"-p", "-p",
pmb.config.sideload_sudo_prompt, pmb.config.sideload_sudo_prompt,

View file

@ -3,12 +3,12 @@
from argparse import Namespace from argparse import Namespace
from pathlib import Path from pathlib import Path
from typing import Dict, List, Optional, Tuple, TypedDict, Union from typing import Optional, TypedDict, Union
from pmb.core.arch import Arch from pmb.core.arch import Arch
PathString = Union[Path, str] PathString = Union[Path, str]
Env = Dict[str, PathString] Env = dict[str, PathString]
# These types are not definitive / API, they exist to describe the current # These types are not definitive / API, they exist to describe the current
# state of things so that we can improve our type hinting coverage and make # state of things so that we can improve our type hinting coverage and make
@ -23,7 +23,7 @@ class PartitionLayout(TypedDict):
class AportGenEntry(TypedDict): class AportGenEntry(TypedDict):
prefixes: List[str] prefixes: list[str]
confirm_overwrite: bool confirm_overwrite: bool
@ -108,13 +108,13 @@ class PmbArgs(Namespace):
no_sshd: str no_sshd: str
odin_flashable_tar: str odin_flashable_tar: str
offline: bool offline: bool
ondev_cp: List[Tuple[str, str]] ondev_cp: list[tuple[str, str]]
on_device_installer: str on_device_installer: str
ondev_no_rootfs: str ondev_no_rootfs: str
overview: str overview: str
# FIXME (#2324): figure out the args.package vs args.packages situation # FIXME (#2324): figure out the args.package vs args.packages situation
package: str | List[str] package: str | list[str]
packages: List[str] packages: list[str]
partition: str partition: str
password: str password: str
path: Path path: Path
@ -140,7 +140,7 @@ class PmbArgs(Namespace):
rsync: str rsync: str
scripts: str scripts: str
second_storage: str second_storage: str
selected_providers: Dict[str, str] selected_providers: dict[str, str]
sparse: str sparse: str
split: bool split: bool
src: str src: str