diff --git a/chroot/abstract.py b/chroot/abstract.py index 3c2c49d..f0671e2 100644 --- a/chroot/abstract.py +++ b/chroot/abstract.py @@ -36,7 +36,7 @@ class AbstractChroot(Protocol): copy_base: bool, extra_repos: Mapping[str, RepoInfo], base_packages: list[str], - path_override: str = None, + path_override: Optional[str] = None, ): pass @@ -87,10 +87,10 @@ class Chroot(AbstractChroot): self, name: str, arch: Arch, - copy_base: bool = None, + copy_base: Optional[bool] = None, extra_repos: Mapping[str, RepoInfo] = {}, base_packages: list[str] = ['base', 'base-devel', 'git'], - path_override: str = None, + path_override: Optional[str] = None, ): self.uuid = uuid4() if copy_base is None: @@ -138,7 +138,7 @@ class Chroot(AbstractChroot): absolute_source: str, relative_destination: str, options=['bind'], - fs_type: str = None, + fs_type: Optional[str] = None, fail_if_mounted: bool = True, mkdir: bool = True, strict_cache_consistency: bool = False, @@ -294,7 +294,7 @@ class Chroot(AbstractChroot): root_write_file(makepkg_conf_path, makepkg_cross_conf) return makepkg_conf_path_relative - def write_pacman_conf(self, check_space: Optional[bool] = None, in_chroot: bool = True, absolute_path: str = None): + def write_pacman_conf(self, check_space: Optional[bool] = None, in_chroot: bool = True, absolute_path: Optional[str] = None): user = None group = None if check_space is None: diff --git a/chroot/cli.py b/chroot/cli.py index 5795b4b..0a99f48 100644 --- a/chroot/cli.py +++ b/chroot/cli.py @@ -2,6 +2,8 @@ import click import logging import os +from typing import Optional + from config.state import config from wrapper import enforce_wrap from devices.device import get_profile_device @@ -21,7 +23,7 @@ CHROOT_TYPES = ['base', 'build', 'rootfs'] default=None, ) @click.pass_context -def cmd_chroot(ctx: click.Context, type: str = 'build', name: str = None, enable_crossdirect=True): +def cmd_chroot(ctx: click.Context, type: str = 'build', name: Optional[str] = None, enable_crossdirect=True): """Open a shell in a chroot. For rootfs NAME is a profile name, for others the architecture (e.g. aarch64).""" if type not in CHROOT_TYPES: diff --git a/chroot/device.py b/chroot/device.py index e41e9b2..bd04467 100644 --- a/chroot/device.py +++ b/chroot/device.py @@ -30,7 +30,7 @@ class DeviceChroot(BuildChroot): clss.create_rootfs(self, reset, pacman_conf_target, active_previously) - def mount_rootfs(self, source_path: str, fs_type: str = None, options: list[str] = [], allow_overlay: bool = False): + def mount_rootfs(self, source_path: str, fs_type: Optional[str] = None, options: list[str] = [], allow_overlay: bool = False): if self.active: raise Exception(f'{self.name}: Chroot is marked as active, not mounting a rootfs over it.') if not os.path.exists(source_path): diff --git a/chroot/helpers.py b/chroot/helpers.py index a3dc818..da7b1a1 100644 --- a/chroot/helpers.py +++ b/chroot/helpers.py @@ -61,7 +61,7 @@ def make_abs_path(path: str) -> str: return '/' + path.lstrip('/') -def get_chroot_path(chroot_name, override_basepath: str = None) -> str: +def get_chroot_path(chroot_name, override_basepath: Optional[str] = None) -> str: base_path = config.get_path('chroots') if not override_basepath else override_basepath return os.path.join(base_path, chroot_name) diff --git a/config/profile.py b/config/profile.py index c13a886..5d7db80 100644 --- a/config/profile.py +++ b/config/profile.py @@ -1,6 +1,7 @@ import logging from copy import deepcopy +from typing import Optional from .scheme import Profile, SparseProfile @@ -23,7 +24,7 @@ PROFILE_EMPTY: Profile = {key: None for key in PROFILE_DEFAULTS.keys()} # type: def resolve_profile( name: str, sparse_profiles: dict[str, SparseProfile], - resolved: dict[str, Profile] = None, + resolved: Optional[dict[str, Profile]] = None, _visited=None, ) -> dict[str, Profile]: """ diff --git a/config/state.py b/config/state.py index 4ac5ab6..8e8ff37 100644 --- a/config/state.py +++ b/config/state.py @@ -174,7 +174,7 @@ def parse_file(config_file: str, base: dict = CONFIG_DEFAULTS) -> dict: class ConfigLoadException(Exception): inner = None - def __init__(self, extra_msg='', inner_exception: Exception = None): + def __init__(self, extra_msg='', inner_exception: Optional[Exception] = None): msg: list[str] = ['Config load failed!'] if extra_msg: msg.append(extra_msg) diff --git a/distro/package.py b/distro/package.py index 8d6165e..a2a940e 100644 --- a/distro/package.py +++ b/distro/package.py @@ -22,7 +22,7 @@ class BinaryPackage(PackageInfo): name: str, version: str, filename: str, - resolved_url: str = None, + resolved_url: Optional[str] = None, ): self.name = name self.version = version diff --git a/exec/test_cmd.py b/exec/test_cmd.py index 0316491..a824d46 100644 --- a/exec/test_cmd.py +++ b/exec/test_cmd.py @@ -3,6 +3,8 @@ import os import pwd import subprocess +from typing import Optional + from .cmd import run_cmd, run_root_cmd, generate_cmd_su @@ -10,7 +12,7 @@ def get_username(id: int): return pwd.getpwuid(id).pw_name -def run_func(f, expected_user: str = None, **kwargs): +def run_func(f, expected_user: Optional[str] = None, **kwargs): current_uid = os.getuid() current_username = get_username(current_uid) target_uid = current_uid diff --git a/generator.py b/generator.py index 133e8c4..b96cea3 100644 --- a/generator.py +++ b/generator.py @@ -1,8 +1,10 @@ +from typing import Optional + from constants import Arch, CFLAGS_ARCHES, CFLAGS_GENERAL, COMPILE_ARCHES, GCC_HOSTSPECS from config.state import config -def generate_makepkg_conf(arch: Arch, cross: bool = False, chroot: str = None) -> str: +def generate_makepkg_conf(arch: Arch, cross: bool = False, chroot: Optional[str] = None) -> str: """ Generate a makepkg.conf. For use with crosscompiling, specify `cross=True` and pass as `chroot` the relative path inside the native chroot where the foreign chroot will be mounted. diff --git a/image/image.py b/image/image.py index 7e7fdd0..1cf1887 100644 --- a/image/image.py +++ b/image/image.py @@ -362,11 +362,11 @@ def cmd_image(): is_flag=True, default=False, help='Skip creating image files for the partitions and directly work on the target block device.') -def cmd_build(profile_name: str = None, +def cmd_build(profile_name: Optional[str] = None, local_repos: bool = True, build_pkgs: bool = True, no_download_pkgs=False, - block_target: str = None, + block_target: Optional[str] = None, skip_part_images: bool = False): """ Build a device image. @@ -454,7 +454,7 @@ def cmd_build(profile_name: str = None, @cmd_image.command(name='inspect') @click.option('--shell', '-s', is_flag=True) @click.argument('profile', required=False) -def cmd_inspect(profile: str = None, shell: bool = False): +def cmd_inspect(profile: Optional[str] = None, shell: bool = False): """Open a shell in a device image""" config.enforce_profile_device_set() config.enforce_profile_flavour_set() diff --git a/main.py b/main.py index d3bc9fa..267ed4e 100755 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ from image.cli import cmd_image @verbose_option @config_option @nowrapper_option -def cli(verbose: bool = False, config_file: str = None, wrapper_override: Optional[bool] = None, error_shell: bool = False): +def cli(verbose: bool = False, config_file: Optional[str] = None, wrapper_override: Optional[bool] = None, error_shell: bool = False): setup_logging(verbose) config.runtime.verbose = verbose config.runtime.no_wrap = wrapper_override is False diff --git a/net/ssh.py b/net/ssh.py index ab63b36..2a5ef7f 100644 --- a/net/ssh.py +++ b/net/ssh.py @@ -51,7 +51,7 @@ def run_ssh_command(cmd: list[str] = [], return run_cmd(full_cmd) -def scp_put_files(src: list[str], dst: str, user: str = None, host: str = SSH_DEFAULT_HOST, port: int = SSH_DEFAULT_PORT): +def scp_put_files(src: list[str], dst: str, user: Optional[str] = None, host: str = SSH_DEFAULT_HOST, port: int = SSH_DEFAULT_PORT): check_programs_wrap(['scp']) if not user: user = config.get_profile()['username'] diff --git a/packages/build.py b/packages/build.py index 119046c..858e3ed 100644 --- a/packages/build.py +++ b/packages/build.py @@ -449,7 +449,7 @@ def setup_sources(package: Pkgbuild, lazy: bool = True): def build_package( package: Pkgbuild, arch: Arch, - repo_dir: str = None, + repo_dir: Optional[str] = None, enable_crosscompile: bool = True, enable_crossdirect: bool = True, enable_ccache: bool = True, diff --git a/wrapper/__init__.py b/wrapper/__init__.py index 7bca277..f7ce80a 100644 --- a/wrapper/__init__.py +++ b/wrapper/__init__.py @@ -1,7 +1,7 @@ import click import logging -from typing import Sequence, Union +from typing import Optional, Sequence, Union from config.state import config from constants import Arch @@ -14,21 +14,21 @@ wrapper_impls: dict[str, Wrapper] = { } -def get_wrapper_type(wrapper_type: str = None): +def get_wrapper_type(wrapper_type: Optional[str] = None): return wrapper_type or config.file.wrapper.type -def get_wrapper_impl(wrapper_type: str = None) -> Wrapper: +def get_wrapper_impl(wrapper_type: Optional[str] = None) -> Wrapper: return wrapper_impls[get_wrapper_type(wrapper_type)] -def wrap(wrapper_type: str = None): +def wrap(wrapper_type: Optional[str] = None): wrapper_type = get_wrapper_type(wrapper_type) if wrapper_type != 'none': get_wrapper_impl(wrapper_type).wrap() -def is_wrapped(wrapper_type: str = None): +def is_wrapped(wrapper_type: Optional[str] = None): wrapper_type = get_wrapper_type(wrapper_type) return wrapper_type != 'none' and get_wrapper_impl(wrapper_type).is_wrapped() diff --git a/wrapper/wrapper.py b/wrapper/wrapper.py index dee429a..619c299 100644 --- a/wrapper/wrapper.py +++ b/wrapper/wrapper.py @@ -3,7 +3,7 @@ import os import uuid import pathlib -from typing import Protocol +from typing import Optional, Protocol from config.state import config from config.state import dump_file as dump_config_file @@ -37,7 +37,7 @@ class BaseWrapper(Wrapper): type: str wrapped_config_path: str - def __init__(self, random_id: str = None, name: str = None): + def __init__(self, random_id: Optional[str] = None, name: Optional[str] = None): self.uuid = str(random_id or uuid.uuid4()) self.identifier = name or f'kupferbootstrap-{self.uuid}' @@ -98,7 +98,7 @@ class BaseWrapper(Wrapper): def is_wrapped(self): return os.getenv(WRAPPER_ENV_VAR) == self.type.upper() - def get_bind_mounts_default(self, wrapped_config_path: str = None, ssh_dir: str = None, target_home: str = '/root'): + def get_bind_mounts_default(self, wrapped_config_path: Optional[str] = None, ssh_dir: Optional[str] = None, target_home: str = '/root'): wrapped_config_path = wrapped_config_path or self.wrapped_config_path ssh_dir = ssh_dir or os.path.join(pathlib.Path.home(), '.ssh') assert (wrapped_config_path)