From 413d6269178308ed30570b8d5cce398b31359f70 Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:27:44 -0400 Subject: [PATCH 1/2] Fix various mypy errors in archinstall/lib/ --- archinstall/lib/boot.py | 4 +- archinstall/lib/configuration.py | 18 +++--- archinstall/lib/general.py | 4 +- archinstall/lib/global_menu.py | 14 ++--- archinstall/lib/hardware.py | 2 +- archinstall/lib/installer.py | 58 +++++++++---------- archinstall/lib/interactions/network_menu.py | 2 +- archinstall/lib/locale/locale_menu.py | 2 +- archinstall/lib/luks.py | 14 ++--- archinstall/lib/menu/abstract_menu.py | 26 ++++----- archinstall/lib/menu/menu.py | 8 +-- archinstall/lib/menu/text_input.py | 2 +- archinstall/lib/mirrors.py | 6 +- archinstall/lib/models/audio_configuration.py | 2 +- archinstall/lib/models/gen.py | 2 +- .../lib/models/network_configuration.py | 2 +- archinstall/lib/models/users.py | 4 +- archinstall/lib/networking.py | 12 ++-- archinstall/lib/output.py | 12 ++-- archinstall/lib/pacman/__init__.py | 6 +- archinstall/lib/pacman/config.py | 6 +- archinstall/lib/profile/profile_menu.py | 2 +- archinstall/lib/profile/profiles_handler.py | 14 ++--- archinstall/lib/translationhandler.py | 6 +- archinstall/lib/utils/util.py | 2 +- 25 files changed, 115 insertions(+), 115 deletions(-) diff --git a/archinstall/lib/boot.py b/archinstall/lib/boot.py index 62c50df30e..7b78a7ae32 100644 --- a/archinstall/lib/boot.py +++ b/archinstall/lib/boot.py @@ -94,7 +94,7 @@ def is_alive(self) -> bool: 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 @@ def SysCommand(self, cmd: list, *args, **kwargs) -> SysCommand: 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]) diff --git a/archinstall/lib/configuration.py b/archinstall/lib/configuration.py index 95e237d7f2..8cac7ffaff 100644 --- a/archinstall/lib/configuration.py +++ b/archinstall/lib/configuration.py @@ -36,14 +36,14 @@ def __init__(self, config: Dict): 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 @@ def user_credentials_to_json(self) -> Optional[str]: 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 @@ def _is_valid_path(self, dest_path: Path) -> bool: ) 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 @@ def save(self, dest_path: Optional[Path] = None): 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() diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 5c9096f197..9c83a7bdf3 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -430,7 +430,7 @@ def create_session(self) -> bool: 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) diff --git a/archinstall/lib/global_menu.py b/archinstall/lib/global_menu.py index 1b5e779b15..38a95edc1b 100644 --- a/archinstall/lib/global_menu.py +++ b/archinstall/lib/global_menu.py @@ -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 @@ def setup_selection_menu_options(self): 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 @@ def _is_config_valid(self) -> bool: 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 @@ def _update_uki_display(self, name: Optional[str] = None): 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 @@ def _prev_network_config(self) -> Optional[str]: 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 diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index c8001c19f0..7f82897a5c 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -141,7 +141,7 @@ def gfx_packages(self) -> List[GfxPackage]: return packages class _SysInfo: - def __init__(self): + def __init__(self) -> None: pass @cached_property diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 401667c1d6..1d0b63d0db 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -97,7 +97,7 @@ def __init__( 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 @@ def __exit__(self, exc_type, exc_val, exc_tb): 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 @@ def _verify_service_stop(self): 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 @@ def mount_ordered_layout(self) -> None: # 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 @@ def _mount_partition_layout(self, luks_handlers: Dict[Any, Luks2]): 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 @@ def _prepare_luks_partitions( 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 @@ def _prepare_luks_lvm( 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 @@ def _mount_partition(self, part_mod: disk.PartitionModification): 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 @@ def _mount_lvm_vol(self, volume: disk.LvmVolume): 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 @@ def _mount_luks_partition(self, part_mod: disk.PartitionModification, luks_handl 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 @@ def _mount_btrfs_subvol( 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 @@ def generate_key_files(self) -> None: # 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 @@ def _generate_key_files_partitions(self): 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 @@ def sync_log_to_install_medium(self) -> bool: 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 @@ def add_swapfile(self, size='4G', enable_resume=True, file='/swapfile'): 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 @@ def set_mirrors(self, mirror_config: MirrorConfiguration, on_target: bool = Fals 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 @@ def genfstab(self, flags: str = '-pU'): 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 @@ def arch_chroot(self, cmd: str, run_as: Optional[str] = None) -> SysCommand: 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 @@ def _get_microcode(self) -> Optional[Path]: 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 @@ def _handle_partition_installation(self): 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 @@ def minimal_installation( 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 @@ def _add_systemd_bootloader( 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 @@ def _add_grub_bootloader( 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 @@ def _add_limine_bootloader( 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 @@ def _add_efistub_bootloader( 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 @@ def _config_uki( 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}') @@ -1498,7 +1498,7 @@ def enable_sudo(self, entity: str, group: bool = False): # 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] diff --git a/archinstall/lib/interactions/network_menu.py b/archinstall/lib/interactions/network_menu.py index 14fc578580..ec3a3dd744 100644 --- a/archinstall/lib/interactions/network_menu.py +++ b/archinstall/lib/interactions/network_menu.py @@ -45,7 +45,7 @@ def reformat(self, data: List[Nic]) -> Dict[str, Optional[Nic]]: 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: diff --git a/archinstall/lib/locale/locale_menu.py b/archinstall/lib/locale/locale_menu.py index 39c1b85ee7..92dc2dabc1 100644 --- a/archinstall/lib/locale/locale_menu.py +++ b/archinstall/lib/locale/locale_menu.py @@ -60,7 +60,7 @@ def __init__( 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'), diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index 50e15ceec0..723271f2a5 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -30,14 +30,14 @@ def mapper_dev(self) -> Optional[Path]: 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 @@ def _get_luks_uuid(self) -> str: 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 @@ def unlock(self, key_file: Optional[Path] = None): 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 @@ def lock(self): 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 @@ def create_keyfile(self, target_path: Path, override: bool = False): 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}' diff --git a/archinstall/lib/menu/abstract_menu.py b/archinstall/lib/menu/abstract_menu.py index ee55f5c902..a67d05ed0e 100644 --- a/archinstall/lib/menu/abstract_menu.py +++ b/archinstall/lib/menu/abstract_menu.py @@ -86,10 +86,10 @@ def __init__( 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 @@ def menu_text(self, padding: int = 0) -> str: 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 @@ def is_enabled(self) -> bool: 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 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: 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 @@ def _sync(self, selector_name: str): 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 @@ def post_callback(self, selection_name: Optional[str] = None, value: Any = None) """ 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 @@ def _preview_display(self, selection_name: str) -> Optional[str]: 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]: diff --git a/archinstall/lib/menu/menu.py b/archinstall/lib/menu/menu.py index 38301d3a36..26c44f7728 100644 --- a/archinstall/lib/menu/menu.py +++ b/archinstall/lib/menu/menu.py @@ -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 @@ def _show(self) -> MenuSelection: 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 @@ def run(self) -> MenuSelection: 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) diff --git a/archinstall/lib/menu/text_input.py b/archinstall/lib/menu/text_input.py index 971df5fda1..ba672c8c11 100644 --- a/archinstall/lib/menu/text_input.py +++ b/archinstall/lib/menu/text_input.py @@ -7,7 +7,7 @@ def __init__(self, prompt: str, prefilled_text=''): self._prompt = prompt self._prefilled_text = prefilled_text - def _hook(self): + def _hook(self) -> None: readline.insert_text(self._prefilled_text) readline.redisplay() diff --git a/archinstall/lib/mirrors.py b/archinstall/lib/mirrors.py index 934c306d03..50d8f479af 100644 --- a/archinstall/lib/mirrors.py +++ b/archinstall/lib/mirrors.py @@ -203,7 +203,7 @@ def __init__( 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) \ No newline at end of file + return _parse_mirror_list(mirrorlist) diff --git a/archinstall/lib/models/audio_configuration.py b/archinstall/lib/models/audio_configuration.py index 88cd5d8e21..ff307c3be6 100644 --- a/archinstall/lib/models/audio_configuration.py +++ b/archinstall/lib/models/audio_configuration.py @@ -38,7 +38,7 @@ def parse_arg(arg: Dict[str, Any]) -> 'AudioConfiguration': def install_audio_config( self, installation: Any - ): + ) -> None: info(f'Installing audio server: {self.audio.name}') match self.audio: diff --git a/archinstall/lib/models/gen.py b/archinstall/lib/models/gen.py index fb7e575182..92c93d8a62 100644 --- a/archinstall/lib/models/gen.py +++ b/archinstall/lib/models/gen.py @@ -98,7 +98,7 @@ def pkg_version(self) -> str: 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 diff --git a/archinstall/lib/models/network_configuration.py b/archinstall/lib/models/network_configuration.py index dfd8b8cbbf..cb1c32571c 100644 --- a/archinstall/lib/models/network_configuration.py +++ b/archinstall/lib/models/network_configuration.py @@ -124,7 +124,7 @@ def install_network_config( self, installation: Any, profile_config: Optional[ProfileConfiguration] = None - ): + ) -> None: match self.type: case NicType.ISO: installation.copy_iso_network_config( diff --git a/archinstall/lib/models/users.py b/archinstall/lib/models/users.py index 9ed70eef87..045d9d61e9 100644 --- a/archinstall/lib/models/users.py +++ b/archinstall/lib/models/users.py @@ -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' diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py index cb20337d09..e28e24e788 100644 --- a/archinstall/lib/networking.py +++ b/archinstall/lib/networking.py @@ -19,7 +19,7 @@ class DownloadTimer(): ''' Context manager for timing downloads with timeouts. ''' - def __init__(self, timeout=5): + def __init__(self, timeout: int = 5): ''' Args: timeout: @@ -32,7 +32,7 @@ def __init__(self, timeout=5): self.previous_handler = None self.previous_timer = None - def raise_timeout(self, signl, frame): + def raise_timeout(self, signl, frame) -> None: ''' Raise the DownloadTimeout exception. ''' @@ -46,7 +46,7 @@ def __enter__(self): 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 \ No newline at end of file + return latency diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 94a68e791b..0ce5aa9df2 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -146,7 +146,7 @@ def log(message: str, level: int = logging.DEBUG) -> None: 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() diff --git a/archinstall/lib/pacman/__init__.py b/archinstall/lib/pacman/__init__.py index 6478f0cc6f..a27951e68e 100644 --- a/archinstall/lib/pacman/__init__.py +++ b/archinstall/lib/pacman/__init__.py @@ -44,7 +44,7 @@ def run(args :str, default_cmd :str = 'pacman') -> SysCommand: 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 @@ def ask(self, error_message: str, bail_message: str, func: Callable, *args, **kw continue raise RequirementError(f'{bail_message}: {err}') - def sync(self): + def sync(self) -> None: if self.synced: return self.ask( @@ -67,7 +67,7 @@ def sync(self): ) 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] diff --git a/archinstall/lib/pacman/config.py b/archinstall/lib/pacman/config.py index 6686f4a9bd..2c9df447b6 100644 --- a/archinstall/lib/pacman/config.py +++ b/archinstall/lib/pacman/config.py @@ -12,10 +12,10 @@ def __init__(self, target: Path): 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 @@ def apply(self): else: f.write(line) - def persist(self): + def persist(self) -> None: if self.repos: copy2(self.path, self.chroot_path) diff --git a/archinstall/lib/profile/profile_menu.py b/archinstall/lib/profile/profile_menu.py index aba75a88b4..980165d634 100644 --- a/archinstall/lib/profile/profile_menu.py +++ b/archinstall/lib/profile/profile_menu.py @@ -25,7 +25,7 @@ def __init__( 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), diff --git a/archinstall/lib/profile/profiles_handler.py b/archinstall/lib/profile/profiles_handler.py index 3dac80ebe2..0c487d6250 100644 --- a/archinstall/lib/profile/profiles_handler.py +++ b/archinstall/lib/profile/profiles_handler.py @@ -24,7 +24,7 @@ class ProfileHandler: - def __init__(self): + def __init__(self) -> None: self._profiles_path: Path = storage['PROFILE'] self._profiles = None @@ -138,7 +138,7 @@ def profiles(self) -> List[Profile]: 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 @@ def add_custom_profiles(self, profiles: Union[Profile, List[Profile]]): 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 @@ def get_mac_addr_profiles(self) -> List[Profile]: 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 @@ def install_greeter(self, install_session: 'Installer', greeter: GreeterType): 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 @@ def install_gfx_driver(self, install_session: 'Installer', driver: GfxDriver): 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 @@ def install_profile_config(self, install_session: 'Installer', profile_config: P 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 """ diff --git a/archinstall/lib/translationhandler.py b/archinstall/lib/translationhandler.py index 3ea4c70eef..093faf2e03 100644 --- a/archinstall/lib/translationhandler.py +++ b/archinstall/lib/translationhandler.py @@ -39,7 +39,7 @@ def json(self) -> str: class TranslationHandler: - def __init__(self): + def __init__(self) -> None: self._base_pot = 'base.pot' self._languages = 'languages.json' @@ -145,7 +145,7 @@ def get_language_by_abbr(self, abbr: str) -> Language: 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 @@ def format(self, *args) -> str: return self.message.format(*args) @classmethod - def install(cls): + def install(cls) -> None: import builtins builtins._ = cls # type: ignore diff --git a/archinstall/lib/utils/util.py b/archinstall/lib/utils/util.py index 2e42b3cf18..5440e5f996 100644 --- a/archinstall/lib/utils/util.py +++ b/archinstall/lib/utils/util.py @@ -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_ """ From 1b4014b9afc463dccf532bd14804b6516214221a Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:52:48 -0400 Subject: [PATCH 2/2] Additional mypy fixes in archinstall/lib/ to pass CI checks --- archinstall/lib/installer.py | 2 +- archinstall/lib/networking.py | 8 ++++---- archinstall/lib/profile/profiles_handler.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 1d0b63d0db..b29d27f0ac 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1465,7 +1465,7 @@ def add_bootloader(self, bootloader: Bootloader, uki_enabled: bool = False): 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): diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py index e28e24e788..9d494e6308 100644 --- a/archinstall/lib/networking.py +++ b/archinstall/lib/networking.py @@ -26,11 +26,11 @@ def __init__(self, timeout: int = 5): 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) -> None: ''' @@ -40,7 +40,7 @@ def raise_timeout(self, signl, frame) -> None: 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() diff --git a/archinstall/lib/profile/profiles_handler.py b/archinstall/lib/profile/profiles_handler.py index 0c487d6250..e3a487c3fd 100644 --- a/archinstall/lib/profile/profiles_handler.py +++ b/archinstall/lib/profile/profiles_handler.py @@ -26,7 +26,7 @@ class ProfileHandler: 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