Fix various mypy errors in archinstall/lib/ (#2640)

* Fix various mypy errors in archinstall/lib/

* Additional mypy fixes in archinstall/lib/ to pass CI checks
This commit is contained in:
correctmost 2024-08-27 15:43:54 -04:00 committed by GitHub
parent 63b4184f70
commit c7aeead7d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 121 additions and 121 deletions

View File

@ -94,7 +94,7 @@ class Boot:
return self.session.is_alive()
def SysCommand(self, cmd: list, *args, **kwargs) -> SysCommand:
def SysCommand(self, cmd: list[str], *args, **kwargs) -> SysCommand:
if cmd[0][0] != '/' and cmd[0][:2] != './':
# This check is also done in SysCommand & SysCommandWorker.
# However, that check is done for `machinectl` and not for our chroot command.
@ -104,7 +104,7 @@ class Boot:
return SysCommand(["systemd-run", f"--machine={self.container_name}", "--pty", *cmd], *args, **kwargs)
def SysCommandWorker(self, cmd: list, *args, **kwargs) -> SysCommandWorker:
def SysCommandWorker(self, cmd: list[str], *args, **kwargs) -> SysCommandWorker:
if cmd[0][0] != '/' and cmd[0][:2] != './':
cmd[0] = locate_binary(cmd[0])

View File

@ -36,14 +36,14 @@ class ConfigurationOutput:
self._process_config()
@property
def user_credentials_file(self):
def user_credentials_file(self) -> str:
return self._user_creds_file
@property
def user_configuration_file(self):
def user_configuration_file(self) -> str:
return self._user_config_file
def _process_config(self):
def _process_config(self) -> None:
for key, value in self._config.items():
if key in self._sensitive:
self._user_credentials[key] = value
@ -68,7 +68,7 @@ class ConfigurationOutput:
return json.dumps(self._user_credentials, indent=4, sort_keys=True, cls=UNSAFE_JSON)
return None
def show(self):
def show(self) -> None:
print(_('\nThis is your chosen configuration:'))
debug(" -- Chosen configuration --")
@ -84,20 +84,20 @@ class ConfigurationOutput:
)
return dest_path_ok
def save_user_config(self, dest_path: Path):
def save_user_config(self, dest_path: Path) -> None:
if self._is_valid_path(dest_path):
target = dest_path / self._user_config_file
target.write_text(self.user_config_to_json())
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
def save_user_creds(self, dest_path: Path):
def save_user_creds(self, dest_path: Path) -> None:
if self._is_valid_path(dest_path):
if user_creds := self.user_credentials_to_json():
target = dest_path / self._user_creds_file
target.write_text(user_creds)
os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP)
def save(self, dest_path: Optional[Path] = None):
def save(self, dest_path: Optional[Path] = None) -> None:
dest_path = dest_path or self._default_save_path
if self._is_valid_path(dest_path):
@ -105,8 +105,8 @@ class ConfigurationOutput:
self.save_user_creds(dest_path)
def save_config(config: Dict):
def preview(selection: str):
def save_config(config: Dict) -> None:
def preview(selection: str) -> Optional[str]:
match options[selection]:
case "user_config":
serialized = config_output.user_config_to_json()

View File

@ -430,7 +430,7 @@ class SysCommand:
return True
def decode(self, encoding: str = 'utf-8', errors='backslashreplace', strip: bool = True) -> str:
def decode(self, encoding: str = 'utf-8', errors: str = 'backslashreplace', strip: bool = True) -> str:
if not self.session:
raise ValueError('No session available to decode')
@ -520,6 +520,6 @@ def json_stream_to_structure(configuration_identifier : str, stream :str, target
return True
def secret(x :str):
def secret(x :str) -> str:
""" return * with len equal to to the input string """
return '*' * len(x)

View File

@ -38,7 +38,7 @@ class GlobalMenu(AbstractMenu):
def __init__(self, data_store: Dict[str, Any]):
super().__init__(data_store=data_store, auto_cursor=True, preview_size=0.3)
def setup_selection_menu_options(self):
def setup_selection_menu_options(self) -> None:
# archinstall.Language will not use preset values
self._menu_options['archinstall-language'] = \
Selector(
@ -181,7 +181,7 @@ class GlobalMenu(AbstractMenu):
self._menu_options['abort'] = Selector(_('Abort'), exec_func=lambda n,v:exit(1))
def _missing_configs(self) -> List[str]:
def check(s) -> bool:
def check(s: str) -> bool:
obj = self._menu_options.get(s)
if obj and obj.has_selection():
return True
@ -216,7 +216,7 @@ class GlobalMenu(AbstractMenu):
return False
return self._validate_bootloader() is None
def _update_uki_display(self, name: Optional[str] = None):
def _update_uki_display(self, name: Optional[str] = None) -> None:
if bootloader := self._menu_options['bootloader'].current_selection:
if not SysInfo.has_uefi() or not bootloader.has_uki_support():
self._menu_options['uki'].set_current_selection(False)
@ -224,15 +224,15 @@ class GlobalMenu(AbstractMenu):
elif name and name == 'bootloader':
self._menu_options['uki'].set_enabled(True)
def _update_install_text(self, name: Optional[str] = None, value: Any = None):
def _update_install_text(self, name: Optional[str] = None, value: Any = None) -> None:
text = self._install_text()
self._menu_options['install'].update_description(text)
def post_callback(self, name: Optional[str] = None, value: Any = None):
def post_callback(self, name: Optional[str] = None, value: Any = None) -> None:
self._update_uki_display(name)
self._update_install_text(name, value)
def _install_text(self):
def _install_text(self) -> str:
missing = len(self._missing_configs())
if missing > 0:
return _('Install ({} config(s) missing)').format(missing)
@ -281,7 +281,7 @@ class GlobalMenu(AbstractMenu):
return output
return None
def _prev_additional_pkgs(self):
def _prev_additional_pkgs(self) -> Optional[str]:
selector = self._menu_options['packages']
if selector.current_selection:
packages: List[str] = selector.current_selection

View File

@ -141,7 +141,7 @@ class GfxDriver(Enum):
return packages
class _SysInfo:
def __init__(self):
def __init__(self) -> None:
pass
@cached_property

View File

@ -97,7 +97,7 @@ class Installer:
def __enter__(self) -> 'Installer':
return self
def __exit__(self, exc_type, exc_val, exc_tb):
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
if exc_type is not None:
error(exc_val)
@ -126,15 +126,15 @@ class Installer:
self.sync_log_to_install_medium()
return False
def remove_mod(self, mod: str):
def remove_mod(self, mod: str) -> None:
if mod in self._modules:
self._modules.remove(mod)
def append_mod(self, mod: str):
def append_mod(self, mod: str) -> None:
if mod not in self._modules:
self._modules.append(mod)
def _verify_service_stop(self):
def _verify_service_stop(self) -> None:
"""
Certain services might be running that affects the system during installation.
One such service is "reflector.service" which updates /etc/pacman.d/mirrorlist
@ -177,7 +177,7 @@ class Installer:
while self._service_state('archlinux-keyring-wkd-sync.service') not in ('dead', 'failed', 'exited'):
time.sleep(1)
def _verify_boot_part(self):
def _verify_boot_part(self) -> None:
"""
Check that mounted /boot device has at minimum size for installation
The reason this check is here is to catch pre-mounted device configuration and potentially
@ -221,7 +221,7 @@ class Installer:
# mount all regular partitions
self._mount_partition_layout(luks_handlers)
def _mount_partition_layout(self, luks_handlers: Dict[Any, Luks2]):
def _mount_partition_layout(self, luks_handlers: Dict[Any, Luks2]) -> None:
debug('Mounting partition layout')
# do not mount any PVs part of the LVM configuration
@ -252,7 +252,7 @@ class Installer:
else:
self._mount_partition(part_mod)
def _mount_lvm_layout(self, luks_handlers: Dict[Any, Luks2] = {}):
def _mount_lvm_layout(self, luks_handlers: Dict[Any, Luks2] = {}) -> None:
lvm_config = self._disk_config.lvm_config
if not lvm_config:
@ -284,7 +284,7 @@ class Installer:
if part_mod.mapper_name and part_mod.dev_path
}
def _import_lvm(self):
def _import_lvm(self) -> None:
lvm_config = self._disk_config.lvm_config
if not lvm_config:
@ -311,7 +311,7 @@ class Installer:
if vol.mapper_name and vol.dev_path
}
def _mount_partition(self, part_mod: disk.PartitionModification):
def _mount_partition(self, part_mod: disk.PartitionModification) -> None:
# it would be none if it's btrfs as the subvolumes will have the mountpoints defined
if part_mod.mountpoint and part_mod.dev_path:
target = self.target / part_mod.relative_mountpoint
@ -324,7 +324,7 @@ class Installer:
part_mod.mount_options
)
def _mount_lvm_vol(self, volume: disk.LvmVolume):
def _mount_lvm_vol(self, volume: disk.LvmVolume) -> None:
if volume.fs_type != disk.FilesystemType.Btrfs:
if volume.mountpoint and volume.dev_path:
target = self.target / volume.relative_mountpoint
@ -333,7 +333,7 @@ class Installer:
if volume.fs_type == disk.FilesystemType.Btrfs and volume.dev_path:
self._mount_btrfs_subvol(volume.dev_path, volume.btrfs_subvols, volume.mount_options)
def _mount_luks_partition(self, part_mod: disk.PartitionModification, luks_handler: Luks2):
def _mount_luks_partition(self, part_mod: disk.PartitionModification, luks_handler: Luks2) -> None:
if part_mod.fs_type != disk.FilesystemType.Btrfs:
if part_mod.mountpoint and luks_handler.mapper_dev:
target = self.target / part_mod.relative_mountpoint
@ -342,7 +342,7 @@ class Installer:
if part_mod.fs_type == disk.FilesystemType.Btrfs and luks_handler.mapper_dev:
self._mount_btrfs_subvol(luks_handler.mapper_dev, part_mod.btrfs_subvols, part_mod.mount_options)
def _mount_luks_volume(self, volume: disk.LvmVolume, luks_handler: Luks2):
def _mount_luks_volume(self, volume: disk.LvmVolume, luks_handler: Luks2) -> None:
if volume.fs_type != disk.FilesystemType.Btrfs:
if volume.mountpoint and luks_handler.mapper_dev:
target = self.target / volume.relative_mountpoint
@ -356,7 +356,7 @@ class Installer:
dev_path: Path,
subvolumes: List[disk.SubvolumeModification],
mount_options: List[str] = []
):
) -> None:
for subvol in subvolumes:
mountpoint = self.target / subvol.relative_mountpoint
mount_options = mount_options + [f'subvol={subvol.name}']
@ -374,7 +374,7 @@ class Installer:
# so we won't need any keyfile generation atm
pass
def _generate_key_files_partitions(self):
def _generate_key_files_partitions(self) -> None:
for part_mod in self._disk_encryption.partitions:
gen_enc_file = self._disk_encryption.should_generate_encryption_file(part_mod)
@ -396,7 +396,7 @@ class Installer:
self._disk_encryption.encryption_password
)
def _generate_key_file_lvm_volumes(self):
def _generate_key_file_lvm_volumes(self) -> None:
for vol in self._disk_encryption.lvm_volumes:
gen_enc_file = self._disk_encryption.should_generate_encryption_file(vol)
@ -432,7 +432,7 @@ class Installer:
return True
def add_swapfile(self, size='4G', enable_resume=True, file='/swapfile'):
def add_swapfile(self, size: str = '4G', enable_resume: bool = True, file: str = '/swapfile') -> None:
if file[:1] != '/':
file = f"/{file}"
if len(file.strip()) <= 0 or file == '/':
@ -457,7 +457,7 @@ class Installer:
def post_install_check(self, *args: str, **kwargs: str) -> List[str]:
return [step for step, flag in self.helper_flags.items() if flag is False]
def set_mirrors(self, mirror_config: MirrorConfiguration, on_target: bool = False):
def set_mirrors(self, mirror_config: MirrorConfiguration, on_target: bool = False) -> None:
"""
Set the mirror configuration for the installation.
@ -496,7 +496,7 @@ class Installer:
with local_mirrorlist_conf.open('w') as fp:
fp.write(mirrorlist_config)
def genfstab(self, flags: str = '-pU'):
def genfstab(self, flags: str = '-pU') -> None:
fstab_path = self.target / "etc" / "fstab"
info(f"Updating {fstab_path}")
@ -521,7 +521,7 @@ class Installer:
for entry in self._fstab_entries:
fp.write(f'{entry}\n')
def set_hostname(self, hostname: str):
def set_hostname(self, hostname: str) -> None:
with open(f'{self.target}/etc/hostname', 'w') as fh:
fh.write(hostname + '\n')
@ -634,7 +634,7 @@ class Installer:
def drop_to_shell(self) -> None:
subprocess.check_call(f"/usr/bin/arch-chroot {self.target}", shell=True)
def configure_nic(self, nic: Nic):
def configure_nic(self, nic: Nic) -> None:
conf = nic.as_systemd_config()
for plugin in plugins.values():
@ -739,7 +739,7 @@ class Installer:
return vendor.get_ucode()
return None
def _handle_partition_installation(self):
def _handle_partition_installation(self) -> None:
pvs = []
if self._disk_config.lvm_config:
pvs = self._disk_config.lvm_config.get_all_pvs()
@ -776,7 +776,7 @@ class Installer:
if 'encrypt' not in self._hooks:
self._hooks.insert(self._hooks.index('filesystems'), 'encrypt')
def _handle_lvm_installation(self):
def _handle_lvm_installation(self) -> None:
if not self._disk_config.lvm_config:
return
@ -891,7 +891,7 @@ class Installer:
if hasattr(plugin, 'on_install'):
plugin.on_install(self)
def setup_swap(self, kind: str = 'zram'):
def setup_swap(self, kind: str = 'zram') -> None:
if kind == 'zram':
info(f"Setting up swap on zram")
self.pacman.strap('zram-generator')
@ -1053,7 +1053,7 @@ class Installer:
root: disk.PartitionModification | disk.LvmVolume,
efi_partition: Optional[disk.PartitionModification],
uki_enabled: bool = False
):
) -> None:
debug('Installing systemd bootloader')
self.pacman.strap('efibootmgr')
@ -1151,7 +1151,7 @@ class Installer:
boot_partition: disk.PartitionModification,
root: disk.PartitionModification | disk.LvmVolume,
efi_partition: Optional[disk.PartitionModification]
):
) -> None:
debug('Installing grub bootloader')
self.pacman.strap('grub') # no need?
@ -1236,7 +1236,7 @@ class Installer:
boot_partition: disk.PartitionModification,
efi_partition: Optional[disk.PartitionModification],
root: disk.PartitionModification | disk.LvmVolume
):
) -> None:
debug('Installing limine bootloader')
self.pacman.strap('limine')
@ -1326,7 +1326,7 @@ Exec = /bin/sh -c "{hook_command}"
boot_partition: disk.PartitionModification,
root: disk.PartitionModification | disk.LvmVolume,
uki_enabled: bool = False
):
) -> None:
debug('Installing efistub bootloader')
self.pacman.strap('efibootmgr')
@ -1375,7 +1375,7 @@ Exec = /bin/sh -c "{hook_command}"
self,
root: disk.PartitionModification | disk.LvmVolume,
efi_partition: Optional[disk.PartitionModification]
):
) -> None:
if not efi_partition or not efi_partition.mountpoint:
raise ValueError(f'Could not detect ESP at mountpoint {self.target}')
@ -1465,7 +1465,7 @@ Exec = /bin/sh -c "{hook_command}"
case Bootloader.Limine:
self._add_limine_bootloader(boot_partition, efi_partition, root)
def add_additional_packages(self, packages: Union[str, List[str]]) -> bool:
def add_additional_packages(self, packages: Union[str, List[str]]) -> None:
return self.pacman.strap(packages)
def enable_sudo(self, entity: str, group: bool = False):
@ -1498,7 +1498,7 @@ Exec = /bin/sh -c "{hook_command}"
# Guarantees sudoer conf file recommended perms
os.chmod(Path(rule_file_name), 0o440)
def create_users(self, users: Union[User, List[User]]):
def create_users(self, users: Union[User, List[User]]) -> None:
if not isinstance(users, list):
users = [users]

View File

@ -45,7 +45,7 @@ class ManualNetworkConfig(ListManager):
def selected_action_display(self, nic: Nic) -> str:
return nic.iface if nic.iface else ''
def handle_action(self, action: str, entry: Optional[Nic], data: List[Nic]):
def handle_action(self, action: str, entry: Optional[Nic], data: List[Nic]) -> list[Nic]:
if action == self._actions[0]: # add
iface = self._select_iface(data)
if iface:

View File

@ -60,7 +60,7 @@ class LocaleMenu(AbstractSubMenu):
self._preset = locale_conf
super().__init__(data_store=data_store)
def setup_selection_menu_options(self):
def setup_selection_menu_options(self) -> None:
self._menu_options['keyboard-layout'] = \
Selector(
_('Keyboard layout'),

View File

@ -30,14 +30,14 @@ class Luks2:
return Path(f'/dev/mapper/{self.mapper_name}')
return None
def __post_init__(self):
def __post_init__(self) -> None:
if self.luks_dev_path is None:
raise ValueError('Partition must have a path set')
def __enter__(self):
def __enter__(self) -> None:
self.unlock(self.key_file)
def __exit__(self, *args: str, **kwargs: str):
def __exit__(self, *args: str, **kwargs: str) -> None:
if self.auto_unmount:
self.lock()
@ -130,7 +130,7 @@ class Luks2:
def is_unlocked(self) -> bool:
return self.mapper_name is not None and Path(f'/dev/mapper/{self.mapper_name}').exists()
def unlock(self, key_file: Optional[Path] = None):
def unlock(self, key_file: Optional[Path] = None) -> None:
"""
Unlocks the luks device, an optional key file location for unlocking can be specified,
otherwise a default location for the key file will be used.
@ -171,7 +171,7 @@ class Luks2:
if not self.mapper_dev or not self.mapper_dev.is_symlink():
raise DiskError(f'Failed to open luks2 device: {self.luks_dev_path}')
def lock(self):
def lock(self) -> None:
disk.device_handler.umount(self.luks_dev_path)
# Get crypt-information about the device by doing a reverse lookup starting with the partition path
@ -191,7 +191,7 @@ class Luks2:
self._mapper_dev = None
def create_keyfile(self, target_path: Path, override: bool = False):
def create_keyfile(self, target_path: Path, override: bool = False) -> None:
"""
Routine to create keyfiles, so it can be moved elsewhere
"""
@ -221,7 +221,7 @@ class Luks2:
self._add_key(key_file)
self._crypttab(crypttab_path, kf_path, options=["luks", "key-slot=1"])
def _add_key(self, key_file: Path):
def _add_key(self, key_file: Path) -> None:
debug(f'Adding additional key-file {key_file}')
command = f'/usr/bin/cryptsetup -q -v luksAddKey {self.luks_dev_path} {key_file}'

View File

@ -86,10 +86,10 @@ class Selector:
def do_store(self) -> bool:
return self._no_store is False
def set_enabled(self, status: bool = True):
def set_enabled(self, status: bool = True) -> None:
self.enabled = status
def update_description(self, description: str):
def update_description(self, description: str) -> None:
self.description = description
def menu_text(self, padding: int = 0) -> str:
@ -114,7 +114,7 @@ class Selector:
return f'{description} {current}'
def set_current_selection(self, current: Optional[Any]):
def set_current_selection(self, current: Optional[Any]) -> None:
self.current_selection = current
def has_selection(self) -> bool:
@ -138,7 +138,7 @@ class Selector:
def is_mandatory(self) -> bool:
return self.mandatory
def set_mandatory(self, value: bool):
def set_mandatory(self, value: bool) -> None:
self.mandatory = value
@ -204,16 +204,16 @@ class AbstractMenu:
def translation_handler(self) -> TranslationHandler:
return self._translation_handler
def _populate_default_values(self):
def _populate_default_values(self) -> None:
for config_key, selector in self._menu_options.items():
if selector.default is not None and config_key not in self._data_store:
self._data_store[config_key] = selector.default
def _sync_all(self):
def _sync_all(self) -> None:
for key in self._menu_options.keys():
self._sync(key)
def _sync(self, selector_name: str):
def _sync(self, selector_name: str) -> None:
value = self._data_store.get(selector_name, None)
selector = self._menu_options.get(selector_name, None)
@ -222,13 +222,13 @@ class AbstractMenu:
elif selector is not None and selector.has_selection():
self._data_store[selector_name] = selector.current_selection
def setup_selection_menu_options(self):
def setup_selection_menu_options(self) -> None:
""" Define the menu options.
Menu options can be defined here in a subclass or done per program calling self.set_option()
"""
return
def pre_callback(self, selector_name):
def pre_callback(self, selector_name) -> None:
""" will be called before each action in the menu """
return
@ -236,14 +236,14 @@ class AbstractMenu:
""" will be called after each action in the menu """
return True
def exit_callback(self):
def exit_callback(self) -> None:
""" will be called at the end of the processing of the menu """
return
def _update_enabled_order(self, selector_name: str):
def _update_enabled_order(self, selector_name: str) -> None:
self._enabled_order.append(selector_name)
def enable(self, selector_name: str, mandatory: bool = False):
def enable(self, selector_name: str, mandatory: bool = False) -> None:
""" activates menu options """
if self._menu_options.get(selector_name, None):
self._menu_options[selector_name].set_enabled(True)
@ -259,7 +259,7 @@ class AbstractMenu:
return preview()
return None
def _get_menu_text_padding(self, entries: List[Selector]):
def _get_menu_text_padding(self, entries: List[Selector]) -> int:
return max([len(str(selection.description)) for selection in entries])
def _find_selection(self, selection_name: str) -> Tuple[str, Selector]:

View File

@ -26,7 +26,7 @@ class MenuSelection:
@property
def single_value(self) -> Any:
return self.value # type: ignore
return self.value
@property
def multi_value(self) -> List[Any]:
@ -251,7 +251,7 @@ class Menu(TerminalMenu):
except KeyboardInterrupt:
return MenuSelection(type_=MenuSelectionType.Reset)
def check_default(elem):
def check_default(elem) -> str:
if self._default_option is not None and self._default_menu_value in elem:
return self._default_option
else:
@ -294,13 +294,13 @@ class Menu(TerminalMenu):
return selection
def set_cursor_pos(self,pos :int):
def set_cursor_pos(self,pos :int) -> None:
if pos and 0 < pos < len(self._menu_entries):
self._view.active_menu_index = pos
else:
self._view.active_menu_index = 0 # we define a default
def set_cursor_pos_entry(self,value :str):
def set_cursor_pos_entry(self,value :str) -> None:
pos = self._menu_entries.index(value)
self.set_cursor_pos(pos)

View File

@ -7,7 +7,7 @@ class TextInput:
self._prompt = prompt
self._prefilled_text = prefilled_text
def _hook(self):
def _hook(self) -> None:
readline.insert_text(self._prefilled_text)
readline.redisplay()

View File

@ -203,7 +203,7 @@ class MirrorMenu(AbstractSubMenu):
super().__init__(data_store=data_store)
def setup_selection_menu_options(self):
def setup_selection_menu_options(self) -> None:
self._menu_options['mirror_regions'] = \
Selector(
_('Mirror region'),
@ -281,7 +281,7 @@ def select_mirror_regions(preset_values: Dict[str, List[str]] = {}) -> Dict[str,
return {}
def select_custom_mirror(prompt: str = '', preset: List[CustomMirror] = []):
def select_custom_mirror(prompt: str = '', preset: List[CustomMirror] = []) -> list[CustomMirror]:
custom_mirrors = CustomMirrorList(prompt, preset).run()
return custom_mirrors
@ -337,4 +337,4 @@ def list_mirrors() -> Dict[str, List[MirrorStatusEntryV3]]:
warn(f'Could not fetch an active mirror-list: {err}')
return regions
return _parse_mirror_list(mirrorlist)
return _parse_mirror_list(mirrorlist)

View File

@ -38,7 +38,7 @@ class AudioConfiguration:
def install_audio_config(
self,
installation: Any
):
) -> None:
info(f'Installing audio server: {self.audio.name}')
match self.audio:

View File

@ -98,7 +98,7 @@ class PackageSearchResult:
def __eq__(self, other) -> bool:
return self.pkg_version == other.pkg_version
def __lt__(self, other) -> bool:
def __lt__(self, other: 'PackageSearchResult') -> bool:
return self.pkg_version < other.pkg_version

View File

@ -124,7 +124,7 @@ class NetworkConfiguration:
self,
installation: Any,
profile_config: Optional[ProfileConfiguration] = None
):
) -> None:
match self.type:
case NicType.ISO:
installation.copy_iso_network_config(

View File

@ -13,14 +13,14 @@ class PasswordStrength(Enum):
STRONG = 'strong'
@property
def value(self):
def value(self) -> str:
match self:
case PasswordStrength.VERY_WEAK: return str(_('very weak'))
case PasswordStrength.WEAK: return str(_('weak'))
case PasswordStrength.MODERATE: return str(_('moderate'))
case PasswordStrength.STRONG: return str(_('strong'))
def color(self):
def color(self) -> str:
match self:
case PasswordStrength.VERY_WEAK: return 'red'
case PasswordStrength.WEAK: return 'red'

View File

@ -19,20 +19,20 @@ class DownloadTimer():
'''
Context manager for timing downloads with timeouts.
'''
def __init__(self, timeout=5):
def __init__(self, timeout: int = 5):
'''
Args:
timeout:
The download timeout in seconds. The DownloadTimeout exception
will be raised in the context after this many seconds.
'''
self.time = None
self.start_time = None
self.time: Optional[float] = None
self.start_time: Optional[float] = None
self.timeout = timeout
self.previous_handler = None
self.previous_timer = None
self.previous_timer: Optional[int] = None
def raise_timeout(self, signl, frame):
def raise_timeout(self, signl, frame) -> None:
'''
Raise the DownloadTimeout exception.
'''
@ -40,13 +40,13 @@ class DownloadTimer():
def __enter__(self):
if self.timeout > 0:
self.previous_handler = signal.signal(signal.SIGALRM, self.raise_timeout)
self.previous_handler = signal.signal(signal.SIGALRM, self.raise_timeout) # type: ignore[assignment]
self.previous_timer = signal.alarm(self.timeout)
self.start_time = time.time()
return self
def __exit__(self, typ, value, traceback):
def __exit__(self, typ, value, traceback) -> None:
if self.start_time:
time_delta = time.time() - self.start_time
signal.alarm(0)
@ -136,7 +136,7 @@ def fetch_data_from_url(url: str, params: Optional[Dict] = None) -> str:
raise ValueError(f'Unable to fetch data from url: {url}')
def calc_checksum(icmp_packet):
def calc_checksum(icmp_packet) -> int:
# Calculate the ICMP checksum
checksum = 0
for i in range(0, len(icmp_packet), 2):
@ -158,7 +158,7 @@ def build_icmp(payload):
return struct.pack('!BBHHH', 8, 0, checksum, 0, 1) + payload
def ping(hostname, timeout=5):
def ping(hostname, timeout=5) -> int:
watchdog = select.epoll()
started = time.time()
random_identifier = f'archinstall-{random.randint(1000, 9999)}'.encode()
@ -190,4 +190,4 @@ def ping(hostname, timeout=5):
break
icmp_socket.close()
return latency
return latency

View File

@ -146,7 +146,7 @@ class Journald:
log_adapter.log(level, message)
def _check_log_permissions():
def _check_log_permissions() -> None:
filename = storage.get('LOG_FILE', None)
log_dir = storage.get('LOG_PATH', Path('./'))
@ -258,7 +258,7 @@ def info(
bg: Optional[str] = None,
reset: bool = False,
font: List[Font] = []
):
) -> None:
log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
@ -269,7 +269,7 @@ def debug(
bg: Optional[str] = None,
reset: bool = False,
font: List[Font] = []
):
) -> None:
log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
@ -280,7 +280,7 @@ def error(
bg: Optional[str] = None,
reset: bool = False,
font: List[Font] = []
):
) -> None:
log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
@ -291,7 +291,7 @@ def warn(
bg: Optional[str] = None,
reset: bool = False,
font: List[Font] = []
):
) -> None:
log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font)
@ -302,7 +302,7 @@ def log(
bg: Optional[str] = None,
reset: bool = False,
font: List[Font] = []
):
) -> None:
# leave this check here as we need to setup the logging
# right from the beginning when the modules are loaded
_check_log_permissions()

View File

@ -44,7 +44,7 @@ class Pacman:
return SysCommand(f'{default_cmd} {args}')
def ask(self, error_message: str, bail_message: str, func: Callable, *args, **kwargs):
def ask(self, error_message: str, bail_message: str, func: Callable, *args, **kwargs) -> None:
while True:
try:
func(*args, **kwargs)
@ -55,7 +55,7 @@ class Pacman:
continue
raise RequirementError(f'{bail_message}: {err}')
def sync(self):
def sync(self) -> None:
if self.synced:
return
self.ask(
@ -67,7 +67,7 @@ class Pacman:
)
self.synced = True
def strap(self, packages: Union[str, List[str]]):
def strap(self, packages: Union[str, List[str]]) -> None:
self.sync()
if isinstance(packages, str):
packages = [packages]

View File

@ -12,10 +12,10 @@ class Config:
self.chroot_path = target / "etc" / "pacman.conf"
self.repos: List[Repo] = []
def enable(self, repo: Repo):
def enable(self, repo: Repo) -> None:
self.repos.append(repo)
def apply(self):
def apply(self) -> None:
if not self.repos:
return
@ -39,6 +39,6 @@ class Config:
else:
f.write(line)
def persist(self):
def persist(self) -> None:
if self.repos:
copy2(self.path, self.chroot_path)

View File

@ -25,7 +25,7 @@ class ProfileMenu(AbstractSubMenu):
super().__init__(data_store=data_store)
def setup_selection_menu_options(self):
def setup_selection_menu_options(self) -> None:
self._menu_options['profile'] = Selector(
_('Type'),
lambda x: self._select_profile(x),

View File

@ -24,9 +24,9 @@ if TYPE_CHECKING:
class ProfileHandler:
def __init__(self):
def __init__(self) -> None:
self._profiles_path: Path = storage['PROFILE']
self._profiles = None
self._profiles: Optional[list[Profile]] = None
# special variable to keep track of a profile url configuration
# it is merely used to be able to export the path again when a user
@ -138,7 +138,7 @@ class ProfileHandler:
def _local_mac_addresses(self) -> List[str]:
return list(list_interfaces())
def add_custom_profiles(self, profiles: Union[Profile, List[Profile]]):
def add_custom_profiles(self, profiles: Union[Profile, List[Profile]]) -> None:
if not isinstance(profiles, list):
profiles = [profiles]
@ -147,7 +147,7 @@ class ProfileHandler:
self._verify_unique_profile_names(self.profiles)
def remove_custom_profiles(self, profiles: Union[Profile, List[Profile]]):
def remove_custom_profiles(self, profiles: Union[Profile, List[Profile]]) -> None:
if not isinstance(profiles, list):
profiles = [profiles]
@ -174,7 +174,7 @@ class ProfileHandler:
match_mac_addr_profiles = list(filter(lambda x: x.name in self._local_mac_addresses, tailored))
return match_mac_addr_profiles
def install_greeter(self, install_session: 'Installer', greeter: GreeterType):
def install_greeter(self, install_session: 'Installer', greeter: GreeterType) -> None:
packages = []
service = None
@ -213,7 +213,7 @@ class ProfileHandler:
with open(path, 'w') as file:
file.write(filedata)
def install_gfx_driver(self, install_session: 'Installer', driver: GfxDriver):
def install_gfx_driver(self, install_session: 'Installer', driver: GfxDriver) -> None:
debug(f'Installing GFX driver: {driver.value}')
if driver in [GfxDriver.NvidiaOpenKernel, GfxDriver.NvidiaProprietary]:
@ -232,7 +232,7 @@ class ProfileHandler:
pkg_names = [p.value for p in driver_pkgs]
install_session.add_additional_packages(pkg_names)
def install_profile_config(self, install_session: 'Installer', profile_config: ProfileConfiguration):
def install_profile_config(self, install_session: 'Installer', profile_config: ProfileConfiguration) -> None:
profile = profile_config.profile
if not profile:
@ -246,7 +246,7 @@ class ProfileHandler:
if profile_config.greeter:
self.install_greeter(install_session, profile_config.greeter)
def _import_profile_from_url(self, url: str):
def _import_profile_from_url(self, url: str) -> None:
"""
Import default_profiles from a url path
"""

View File

@ -39,7 +39,7 @@ class Language:
class TranslationHandler:
def __init__(self):
def __init__(self) -> None:
self._base_pot = 'base.pot'
self._languages = 'languages.json'
@ -145,7 +145,7 @@ class TranslationHandler:
except Exception:
raise ValueError(f'No language with abbreviation "{abbr}" found')
def activate(self, language: Language):
def activate(self, language: Language) -> None:
"""
Set the provided language as the current translation
"""
@ -204,6 +204,6 @@ class DeferredTranslation:
return self.message.format(*args)
@classmethod
def install(cls):
def install(cls) -> None:
import builtins
builtins._ = cls # type: ignore

View File

@ -20,7 +20,7 @@ def prompt_dir(text: str, header: Optional[str] = None) -> Path:
info(_('Not a valid directory: {}').format(dest_path))
def is_subpath(first: Path, second: Path):
def is_subpath(first: Path, second: Path) -> bool:
"""
Check if _first_ a subpath of _second_
"""