diff --git a/archinstall/default_profiles/desktops/plasma.py b/archinstall/default_profiles/desktops/plasma.py index 66a5ae9a69..6f09500631 100644 --- a/archinstall/default_profiles/desktops/plasma.py +++ b/archinstall/default_profiles/desktops/plasma.py @@ -81,8 +81,8 @@ def packages(self) -> list[str]: if flavor_str is not None: flavor = PlasmaFlavor(flavor_str) return flavor.packages() - else: - return PlasmaFlavor.Meta.packages() # use plasma-meta as the recommended default + + return PlasmaFlavor.Meta.packages() # use plasma-meta as the recommended default @property @override diff --git a/archinstall/default_profiles/desktops/utils.py b/archinstall/default_profiles/desktops/utils.py index c52782a960..235e6d0a0b 100644 --- a/archinstall/default_profiles/desktops/utils.py +++ b/archinstall/default_profiles/desktops/utils.py @@ -57,5 +57,5 @@ async def select_seat_access(profile_name: str, default: str | None) -> SeatAcce if result.type_ == ResultType.Selection: return result.get_value() - else: - raise ValueError('Unexpected result type from seat access selection') + + raise ValueError('Unexpected result type from seat access selection') diff --git a/archinstall/default_profiles/profile.py b/archinstall/default_profiles/profile.py index d473840ca2..963e0ec6bb 100644 --- a/archinstall/default_profiles/profile.py +++ b/archinstall/default_profiles/profile.py @@ -175,10 +175,11 @@ def is_custom_type_profile(self) -> bool: def is_graphic_driver_supported(self) -> bool: if not self.current_selection: return self._support_gfx_driver - else: - if any(p._support_gfx_driver for p in self.current_selection): - return True - return False + + if any(p._support_gfx_driver for p in self.current_selection): + return True + + return False def is_greeter_supported(self) -> bool: return self._support_greeter diff --git a/archinstall/lib/args.py b/archinstall/lib/args.py index feeaa8431e..3e6fe8700e 100644 --- a/archinstall/lib/args.py +++ b/archinstall/lib/args.py @@ -461,9 +461,7 @@ def as_summary(self) -> str: if summary: cfg[config_type.text()] = summary - simple_summary = as_key_value_pair(cfg, ignore_empty=True) - - return simple_summary + return as_key_value_pair(cfg, ignore_empty=True) class ArchConfigHandler: @@ -701,9 +699,7 @@ def _parse_config(self) -> dict[str, Any]: if json_data is not None: config.update(json_data) - config = self._cleanup_config(config) - - return config + return self._cleanup_config(config) def _process_creds_data(self, creds_data: str) -> dict[str, Any] | None: if creds_data.startswith('$'): # encrypted data diff --git a/archinstall/lib/authentication/authentication_menu.py b/archinstall/lib/authentication/authentication_menu.py index 0b90487a9a..18628b1d29 100644 --- a/archinstall/lib/authentication/authentication_menu.py +++ b/archinstall/lib/authentication/authentication_menu.py @@ -58,8 +58,7 @@ def _define_menu_options(self) -> list[MenuItem]: async def _create_user_account(self, preset: list[User] | None = None) -> list[User]: preset = [] if preset is None else preset - users = await select_users(preset=preset) - return users + return await select_users(preset=preset) def _prev_users(self, item: MenuItem) -> str | None: users: list[User] | None = item.value @@ -100,8 +99,7 @@ def _prev_u2f_login(self, item: MenuItem) -> str | None: async def select_root_password() -> Password | None: - password = await get_password(header=tr('Enter root password'), allow_skip=True) - return password + return await get_password(header=tr('Enter root password'), allow_skip=True) async def select_u2f_login(preset: U2FLoginConfiguration | None) -> U2FLoginConfiguration | None: diff --git a/archinstall/lib/bootloader/bootloader_menu.py b/archinstall/lib/bootloader/bootloader_menu.py index c7d0429a49..607a09ee19 100644 --- a/archinstall/lib/bootloader/bootloader_menu.py +++ b/archinstall/lib/bootloader/bootloader_menu.py @@ -84,8 +84,8 @@ def _prev_uki(self, item: MenuItem) -> str | None: uki_text = f'{tr("Unified kernel images")}' if item.value: return f'{uki_text}: {tr("Enabled")}' - else: - return f'{uki_text}: {tr("Disabled")}' + + return f'{uki_text}: {tr("Disabled")}' def _prev_removable(self, item: MenuItem) -> str | None: if item.value: diff --git a/archinstall/lib/command.py b/archinstall/lib/command.py index 4ebcc09e85..177febfbbe 100644 --- a/archinstall/lib/command.py +++ b/archinstall/lib/command.py @@ -259,13 +259,14 @@ def __iter__(self, *args: list[Any], **kwargs: dict[str, Any]) -> Iterator[bytes def __getitem__(self, key: slice) -> bytes: if not self.session: raise KeyError('SysCommand() does not have an active session.') - elif type(key) is slice: + + if type(key) is slice: start = key.start or 0 end = key.stop or len(self.session._trace_log) return self.session._trace_log[start:end] - else: - raise ValueError("SysCommand() doesn't have key & value pairs, only slices, SysCommand('ls')[:10] as an example.") + + raise ValueError("SysCommand() doesn't have key & value pairs, only slices, SysCommand('ls')[:10] as an example.") @override def __repr__(self, *args: list[Any], **kwargs: dict[str, Any]) -> str: @@ -321,8 +322,8 @@ def output(self, remove_cr: bool = True) -> bytes: def exit_code(self) -> int | None: if self.session: return self.session.exit_code - else: - return None + + return None @property def trace_log(self) -> bytes | None: diff --git a/archinstall/lib/crypt.py b/archinstall/lib/crypt.py index b7ad4edf49..cdc4f6a529 100644 --- a/archinstall/lib/crypt.py +++ b/archinstall/lib/crypt.py @@ -28,8 +28,7 @@ def _search_login_defs(key: str) -> str | None: continue if line.startswith(key): - value = line.split(' ')[1] - return value + return line.split(' ')[1] return None diff --git a/archinstall/lib/disk/default_layouts.py b/archinstall/lib/disk/default_layouts.py index c88c4f77f0..2df92982fb 100644 --- a/archinstall/lib/disk/default_layouts.py +++ b/archinstall/lib/disk/default_layouts.py @@ -38,11 +38,11 @@ async def get_default_partition_layout( filesystem_type=filesystem_type, ) return [device_modification] - else: - return await suggest_multi_disk_layout( - devices, - filesystem_type=filesystem_type, - ) + + return await suggest_multi_disk_layout( + devices, + filesystem_type=filesystem_type, + ) def _boot_partition(sector_size: SectorSize, using_gpt: bool) -> PartitionModification: @@ -118,13 +118,14 @@ def process_root_partition_size(total_size: Size, sector_size: SectorSize) -> Si if total_device_size.value > 500: # maximum size return Size(value=50, unit=Unit.GiB, sector_size=sector_size) - elif total_device_size.value < 320: + + if total_device_size.value < 320: # minimum size return Size(value=32, unit=Unit.GiB, sector_size=sector_size) - else: - # 10% of total size - length = total_device_size.value // 10 - return Size(value=length, unit=Unit.GiB, sector_size=sector_size) + + # 10% of total size + length = total_device_size.value // 10 + return Size(value=length, unit=Unit.GiB, sector_size=sector_size) def get_default_btrfs_subvols() -> list[SubvolumeModification]: diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py index 35202909e8..88e08653e8 100644 --- a/archinstall/lib/disk/device_handler.py +++ b/archinstall/lib/disk/device_handler.py @@ -152,7 +152,7 @@ def _determine_fs_type( if partition.fileSystem.type == FilesystemType.LINUX_SWAP.parted_value: return FilesystemType.LINUX_SWAP return FilesystemType(partition.fileSystem.type) - elif lsblk_info is not None: + if lsblk_info is not None: return FilesystemType(lsblk_info.fstype) if lsblk_info.fstype else None return None except ValueError: diff --git a/archinstall/lib/disk/disk_menu.py b/archinstall/lib/disk/disk_menu.py index 76deb9b169..d0dd518086 100644 --- a/archinstall/lib/disk/disk_menu.py +++ b/archinstall/lib/disk/disk_menu.py @@ -144,9 +144,7 @@ async def _select_disk_encryption(self, preset: DiskEncryption | None) -> DiskEn if not DiskEncryption.validate_enc(modifications, lvm_config): return None - disk_encryption = await DiskEncryptionMenu(modifications, lvm_config=lvm_config, preset=preset).show() - - return disk_encryption + return await DiskEncryptionMenu(modifications, lvm_config=lvm_config, preset=preset).show() async def _select_disk_layout_config(self, preset: DiskLayoutConfiguration | None) -> DiskLayoutConfiguration | None: disk_config = await select_disk_config(preset) diff --git a/archinstall/lib/disk/encryption_menu.py b/archinstall/lib/disk/encryption_menu.py index a36c0cdcf4..cdb61b8683 100644 --- a/archinstall/lib/disk/encryption_menu.py +++ b/archinstall/lib/disk/encryption_menu.py @@ -271,13 +271,11 @@ async def select_encryption_type( async def select_encrypted_password() -> Password | None: header = tr('Enter disk encryption password (leave blank for no encryption)') + '\n' - password = await get_password( + return await get_password( header=header, allow_skip=True, ) - return password - async def select_hsm(preset: Fido2Device | None = None) -> Fido2Device | None: header = tr('Select a FIDO2 device to use for HSM') + '\n' @@ -337,8 +335,7 @@ async def select_partitions_to_encrypt( case ResultType.Skip: return preset case ResultType.Selection: - partitions = result.get_values() - return partitions + return result.get_values() return [] @@ -366,8 +363,7 @@ async def select_lvm_vols_to_encrypt( case ResultType.Skip: return preset case ResultType.Selection: - volumes = result.get_values() - return volumes + return result.get_values() return [] diff --git a/archinstall/lib/disk/luks.py b/archinstall/lib/disk/luks.py index 8c3c1a4fb9..9aa9d353c3 100644 --- a/archinstall/lib/disk/luks.py +++ b/archinstall/lib/disk/luks.py @@ -53,8 +53,8 @@ def _password_bytes(self) -> bytes: if isinstance(self.password, bytes): return self.password - else: - return bytes(self.password.plaintext, 'UTF-8') + + return bytes(self.password.plaintext, 'UTF-8') def _get_passphrase_args( self, @@ -195,8 +195,8 @@ def create_keyfile(self, target_path: Path, override: bool = False) -> None: if not override: info(f'Key file {key_file} already exists, keeping existing') return - else: - info(f'Key file {key_file} already exists, overriding') + + info(f'Key file {key_file} already exists, overriding') key_file.parent.mkdir(parents=True, exist_ok=True) diff --git a/archinstall/lib/disk/partitioning_menu.py b/archinstall/lib/disk/partitioning_menu.py index 4ddfacdb44..d4d7c4bcdc 100644 --- a/archinstall/lib/disk/partitioning_menu.py +++ b/archinstall/lib/disk/partitioning_menu.py @@ -212,7 +212,7 @@ def selected_action_display(self, selection: DiskSegment) -> str: if isinstance(selection.segment, PartitionModification): if selection.segment.status == ModificationStatus.CREATE: return tr('Partition - New') - elif selection.segment.is_delete() and selection.segment.dev_path: + if selection.segment.is_delete() and selection.segment.dev_path: title = tr('Partition') + '\n\n' title += 'status: delete\n' title += f'device: {selection.segment.dev_path}\n' @@ -394,7 +394,8 @@ async def _prompt_formatting(self, partition: PartitionModification) -> None: if partition.is_modify(): partition.status = ModificationStatus.EXIST return - elif partition.exists(): + + if partition.exists(): partition.status = ModificationStatus.MODIFY # If we mark a partition for formatting, but the format is CRYPTO LUKS, there's no point in formatting it really @@ -461,7 +462,8 @@ def _validate_value( if size.format_highest() == max_size.format_highest(): return max_size - elif size > max_size or size < self._buffer: + + if size > max_size or size < self._buffer: return None return size diff --git a/archinstall/lib/global_menu.py b/archinstall/lib/global_menu.py index 87352786b4..ebc2610617 100644 --- a/archinstall/lib/global_menu.py +++ b/archinstall/lib/global_menu.py @@ -61,7 +61,7 @@ def __init__( super().__init__(self._item_group, config=arch_config, title=title) def _get_menu_options(self) -> list[MenuItem]: - menu_options = [ + return [ MenuItem( text=tr('Archinstall language'), action=self._select_archinstall_language, @@ -191,8 +191,6 @@ def _get_menu_options(self) -> list[MenuItem]: ), ] - return menu_options - async def _safe_config(self) -> None: # data: dict[str, Any] = {} # for item in self._item_group.items: @@ -264,12 +262,10 @@ def _prev_archinstall_language(self, item: MenuItem) -> str | None: return f'{tr("Language")}: {lang.display_name}' async def _select_applications(self, preset: ApplicationConfiguration | None) -> ApplicationConfiguration | None: - app_config = await ApplicationMenu(preset).show() - return app_config + return await ApplicationMenu(preset).show() async def _select_authentication(self, preset: AuthenticationConfiguration | None) -> AuthenticationConfiguration | None: - auth_config = await AuthenticationMenu(preset).show() - return auth_config + return await AuthenticationMenu(preset).show() def _update_lang_text(self) -> None: """ @@ -285,8 +281,7 @@ def _update_lang_text(self) -> None: tui.translate_bindings() async def _locale_selection(self, preset: LocaleConfiguration) -> LocaleConfiguration | None: - locale_config = await LocaleMenu(preset).show() - return locale_config + return await LocaleMenu(preset).show() def _prev_locale(self, item: MenuItem) -> str | None: if not item.value: @@ -308,8 +303,7 @@ def _prev_network_config(self, item: MenuItem) -> str | None: def _prev_additional_pkgs(self, item: MenuItem) -> str | None: if item.value: - output = '\n'.join(sorted(item.value)) - return output + return '\n'.join(sorted(item.value)) return None def _prev_authentication(self, item: MenuItem) -> str | None: @@ -560,8 +554,7 @@ async def _select_disk_config( self, preset: DiskLayoutConfiguration | None = None, ) -> DiskLayoutConfiguration | None: - disk_config = await DiskLayoutConfigurationMenu(preset).show() - return disk_config + return await DiskLayoutConfigurationMenu(preset).show() async def _select_bootloader_config( self, @@ -570,15 +563,12 @@ async def _select_bootloader_config( if preset is None: preset = BootloaderConfiguration.get_default(self._uefi, self._skip_boot) - bootloader_config = await BootloaderMenu(preset, self._uefi, self._skip_boot).show() - - return bootloader_config + return await BootloaderMenu(preset, self._uefi, self._skip_boot).show() async def _select_profile(self, current_profile: ProfileConfiguration | None) -> ProfileConfiguration | None: from archinstall.lib.profile.profile_menu import ProfileMenu - profile_config = await ProfileMenu(preset=current_profile).show() - return profile_config + return await ProfileMenu(preset=current_profile).show() async def _select_additional_packages(self, preset: list[str]) -> list[str]: config: MirrorConfiguration | None = self._item_group.find_by_key('mirror_config').value @@ -587,13 +577,11 @@ async def _select_additional_packages(self, preset: list[str]) -> list[str]: if config: repositories = set(config.optional_repositories) - packages = await select_additional_packages( + return await select_additional_packages( preset, repositories=repositories, ) - return packages - async def _mirror_configuration(self, preset: MirrorConfiguration | None = None) -> MirrorConfiguration | None: if self._mirror_list_handler is None: self._mirror_list_handler = MirrorListHandler() diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index fc3be4f76b..70d45b3374 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -166,17 +166,17 @@ def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseExceptio log(msg, fg='green') self.sync_log_to_install_medium() return True - else: - warn('Some required steps were not successfully installed/configured before leaving the installer:') - for step in missing_steps: - warn(f' - {step}') + warn('Some required steps were not successfully installed/configured before leaving the installer:') - warn(f'Detailed error logs can be found at: {logger.directory}') - warn('Submit this zip file as an issue to https://github.com/archlinux/archinstall/issues') + for step in missing_steps: + warn(f' - {step}') - self.sync_log_to_install_medium() - return False + warn(f'Detailed error logs can be found at: {logger.directory}') + warn('Submit this zip file as an issue to https://github.com/archlinux/archinstall/issues') + + self.sync_log_to_install_medium() + return False def remove_mod(self, mod: str) -> None: if mod in self._modules: @@ -691,9 +691,7 @@ def set_timezone(self, zone: str) -> bool: self.arch_chroot(f'ln -s /usr/share/zoneinfo/{zone} /etc/localtime') return True - else: - warn(f'Time zone {zone} does not exist, continuing with system default') - + warn(f'Time zone {zone} does not exist, continuing with system default') return False def activate_time_synchronization(self) -> None: @@ -1047,10 +1045,11 @@ def _get_boot_partition(self) -> PartitionModification | None: def _get_root(self) -> PartitionModification | LvmVolume | None: if self._disk_config.lvm_config: return self._disk_config.lvm_config.get_root_volume() - else: - for mod in self._disk_config.device_modifications: - if root := mod.get_root_partition(): - return root + + for mod in self._disk_config.device_modifications: + if root := mod.get_root_partition(): + return root + return None def _configure_grub_btrfsd(self, snapshot_type: SnapshotType) -> None: @@ -1244,7 +1243,8 @@ def _add_systemd_bootloader( if not efi_partition: raise ValueError('Could not detect EFI system partition') - elif not efi_partition.mountpoint: + + if not efi_partition.mountpoint: raise ValueError('EFI system partition is not mounted') # TODO: Ideally we would want to check if another config @@ -1455,7 +1455,8 @@ def _add_limine_bootloader( if not efi_partition: raise ValueError('Could not detect efi partition') - elif not efi_partition.mountpoint: + + if not efi_partition.mountpoint: raise ValueError('EFI partition is not mounted') # Safety net for programmatic callers that bypass GlobalMenu and @@ -1671,7 +1672,8 @@ def _add_refind_bootloader( if not efi_partition: raise ValueError('Could not detect EFI system partition') - elif not efi_partition.mountpoint: + + if not efi_partition.mountpoint: raise ValueError('EFI system partition is not mounted') info(f'rEFInd EFI partition: {efi_partition.dev_path}') diff --git a/archinstall/lib/menu/abstract_menu.py b/archinstall/lib/menu/abstract_menu.py index 2b51f58ede..7ad3b8387f 100644 --- a/archinstall/lib/menu/abstract_menu.py +++ b/archinstall/lib/menu/abstract_menu.py @@ -55,7 +55,7 @@ def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseExceptio print('Please submit this issue (and file) to https://github.com/archlinux/archinstall/issues') # Return None to propagate the exception - return None + return self.sync_all_to_config() @@ -130,12 +130,10 @@ async def show(self) -> ValueT | None: if not self.is_config_valid(): continue break - elif item.key == SpecialMenuKey.ABORT.value: + if item.key == SpecialMenuKey.ABORT.value: return None - else: - break - else: - item.value = await item.action(item.value) + break + item.value = await item.action(item.value) case ResultType.Reset: return None case _: diff --git a/archinstall/lib/menu/helpers.py b/archinstall/lib/menu/helpers.py index 3bdc37cad6..c3d2ff5473 100644 --- a/archinstall/lib/menu/helpers.py +++ b/archinstall/lib/menu/helpers.py @@ -189,17 +189,16 @@ def __init__( async def show(self) -> Result[ValueT]: if self._data_callback: - result = await LoadingScreen[ValueT]( + return await LoadingScreen[ValueT]( header=self._header, data_callback=self._data_callback, ).run() - return result - else: - _ = await LoadingScreen( - timer=self._timer, - header=self._header, - ).run() - return Result.true() + + _ = await LoadingScreen( + timer=self._timer, + header=self._header, + ).run() + return Result.true() class Table[ValueT]: diff --git a/archinstall/lib/menu/list_manager.py b/archinstall/lib/menu/list_manager.py index a5223abd45..eef7158d7c 100644 --- a/archinstall/lib/menu/list_manager.py +++ b/archinstall/lib/menu/list_manager.py @@ -93,8 +93,8 @@ async def _run(self) -> list[ValueT] | None: if result.get_value() == self._cancel_action: return None - else: - return self._data + + return self._data async def _run_actions_on_entry(self, entry: ValueT) -> None: options = self.filter_options(entry, self._sub_menu_actions) + [self._cancel_action] diff --git a/archinstall/lib/menu/menu_helper.py b/archinstall/lib/menu/menu_helper.py index b08c31eefc..61745c65db 100644 --- a/archinstall/lib/menu/menu_helper.py +++ b/archinstall/lib/menu/menu_helper.py @@ -27,9 +27,7 @@ def create_menu_group(self) -> MenuItemGroup: items.append(item) - group = MenuItemGroup(items, sort_items=False) - - return group + return MenuItemGroup(items, sort_items=False) def _table_to_data_mapping(self, data: list[ValueT]) -> dict[str, ValueT | str | None]: display_data: dict[str, ValueT | str | None] = {} diff --git a/archinstall/lib/menu/util.py b/archinstall/lib/menu/util.py index 6e227a7fc8..53d34859b7 100644 --- a/archinstall/lib/menu/util.py +++ b/archinstall/lib/menu/util.py @@ -41,14 +41,13 @@ def password_hint(value: str) -> InputInfo | None: if result.type_ == ResultType.Skip: if allow_skip: return None - else: - continue - elif result.type_ == ResultType.Selection: + continue + + if result.type_ == ResultType.Selection: if not result.get_value(): if allow_skip: return None - else: - continue + continue password = Password(plaintext=result.get_value()) break diff --git a/archinstall/lib/mirror/mirror_menu.py b/archinstall/lib/mirror/mirror_menu.py index b2a5c9fa63..c31e7aba86 100644 --- a/archinstall/lib/mirror/mirror_menu.py +++ b/archinstall/lib/mirror/mirror_menu.py @@ -333,8 +333,7 @@ async def select_mirror_regions( case ResultType.Reset: return [] case ResultType.Selection: - selected_mirrors = result.get_values() - return selected_mirrors + return result.get_values() async def add_custom_mirror_servers(preset: list[CustomServer] | None = None) -> list[CustomServer]: diff --git a/archinstall/lib/models/bootloader.py b/archinstall/lib/models/bootloader.py index a4900e5bb6..ea2144531d 100644 --- a/archinstall/lib/models/bootloader.py +++ b/archinstall/lib/models/bootloader.py @@ -40,10 +40,11 @@ def json(self) -> str: def get_default(uefi: bool, skip_boot: bool = False) -> Bootloader: if skip_boot: return Bootloader.NO_BOOTLOADER - elif uefi: + + if uefi: return Bootloader.Systemd - else: - return Bootloader.Grub + + return Bootloader.Grub @classmethod def from_arg(cls, bootloader: str, skip_boot: bool) -> Self: diff --git a/archinstall/lib/models/device.py b/archinstall/lib/models/device.py index 626fee5f47..124fd85677 100644 --- a/archinstall/lib/models/device.py +++ b/archinstall/lib/models/device.py @@ -71,22 +71,22 @@ def json(self) -> _DiskLayoutConfigurationSerialization: 'config_type': self.config_type.value, 'mountpoint': str(self.mountpoint), } - else: - config: _DiskLayoutConfigurationSerialization = { - 'config_type': self.config_type.value, - 'device_modifications': [mod.json() for mod in self.device_modifications], - } - if self.lvm_config: - config['lvm_config'] = self.lvm_config.json() + config: _DiskLayoutConfigurationSerialization = { + 'config_type': self.config_type.value, + 'device_modifications': [mod.json() for mod in self.device_modifications], + } - if self.disk_encryption: - config['disk_encryption'] = self.disk_encryption.json() + if self.lvm_config: + config['lvm_config'] = self.lvm_config.json() - if self.btrfs_options: - config['btrfs_options'] = self.btrfs_options.json() + if self.disk_encryption: + config['disk_encryption'] = self.disk_encryption.json() - return config + if self.btrfs_options: + config['btrfs_options'] = self.btrfs_options.json() + + return config @override def summary(self) -> list[str]: @@ -375,17 +375,18 @@ def convert( if self.unit == target_unit: return self - elif self.unit == Unit.sectors: + + if self.unit == Unit.sectors: norm = self._normalize() return Size(norm, Unit.B, self.sector_size).convert(target_unit, sector_size) - else: - if target_unit == Unit.sectors and sector_size is not None: - norm = self._normalize() - sectors = math.ceil(norm / sector_size.value) - return Size(sectors, Unit.sectors, sector_size) - else: - value = int(self._normalize() / target_unit.value) - return Size(value, target_unit, self.sector_size) + + if target_unit == Unit.sectors and sector_size is not None: + norm = self._normalize() + sectors = math.ceil(norm / sector_size.value) + return Size(sectors, Unit.sectors, sector_size) + + value = int(self._normalize() / target_unit.value) + return Size(value, target_unit, self.sector_size) def as_text(self) -> str: return self.format_size( @@ -445,8 +446,8 @@ def si_unit_highest(self, include_unit: bool = True) -> str: def format_highest(self, include_unit: bool = True, units: Units = Units.BINARY) -> str: if units == Units.BINARY: return self.binary_unit_highest(include_unit) - else: - return self.si_unit_highest(include_unit) + + return self.si_unit_highest(include_unit) def is_valid_start(self) -> bool: return self >= Size(1, Unit.MiB, self.sector_size) @@ -762,9 +763,9 @@ class PartitionType(StrEnum): def get_type_from_code(code: int) -> PartitionType: if code == parted.PARTITION_NORMAL: return PartitionType.PRIMARY - else: - debug(f'Partition code not supported: {code}') - return PartitionType._UNKNOWN + + debug(f'Partition code not supported: {code}') + return PartitionType._UNKNOWN def get_partition_code(self) -> int: if self == PartitionType.BOOT: @@ -982,10 +983,10 @@ def is_boot(self) -> bool: def is_root(self) -> bool: if self.mountpoint is not None: return self.mountpoint == Path('/') - else: - for subvol in self.btrfs_subvols: - if subvol.is_root(): - return True + + for subvol in self.btrfs_subvols: + if subvol.is_root(): + return True return False @@ -1233,7 +1234,7 @@ def json(self) -> _LvmVolumeSerialization: } def table_data(self) -> dict[str, str]: - part_mod = { + return { 'Type': self.status.value, 'Name': self.name, 'Size': self.length.format_highest(), @@ -1242,7 +1243,6 @@ def table_data(self) -> dict[str, str]: 'Mount options': ', '.join(self.mount_options), 'Btrfs': '{} {}'.format(str(len(self.btrfs_subvols)), 'vol'), } - return part_mod def is_modify(self) -> bool: return self.status == ModificationStatus.MODIFY @@ -1256,10 +1256,10 @@ def is_exists_or_modify(self) -> bool: def is_root(self) -> bool: if self.mountpoint is not None: return Path('/') == self.mountpoint - else: - for subvol in self.btrfs_subvols: - if subvol.is_root(): - return True + + for subvol in self.btrfs_subvols: + if subvol.is_root(): + return True return False @@ -1490,8 +1490,8 @@ def __post_init__(self) -> None: def should_generate_encryption_file(self, dev: PartitionModification | LvmVolume) -> bool: if isinstance(dev, PartitionModification): return dev in self.partitions and dev.mountpoint != Path('/') - else: - return dev in self.lvm_volumes and dev.mountpoint != Path('/') + + return dev in self.lvm_volumes and dev.mountpoint != Path('/') def json(self) -> _DiskEncryptionSerialization: obj: _DiskEncryptionSerialization = { diff --git a/archinstall/lib/models/network.py b/archinstall/lib/models/network.py index da22862be7..6c1ce1c941 100644 --- a/archinstall/lib/models/network.py +++ b/archinstall/lib/models/network.py @@ -252,6 +252,4 @@ def from_wpa_cli_output(cls, list_networks: str) -> list[Self]: def _extract_flags(flag_string: str) -> list[str]: pattern = r'\[([^\]]+)\]' - extracted_values = re.findall(pattern, flag_string) - - return extracted_values + return re.findall(pattern, flag_string) diff --git a/archinstall/lib/models/users.py b/archinstall/lib/models/users.py index 6d463a5575..6ce856e566 100644 --- a/archinstall/lib/models/users.py +++ b/archinstall/lib/models/users.py @@ -147,8 +147,8 @@ def __eq__(self, other: object) -> bool: def hidden(self) -> str: if self._plaintext: return '*' * len(self._plaintext) - else: - return '*' * 8 + + return '*' * 8 @dataclass diff --git a/archinstall/lib/network/network_menu.py b/archinstall/lib/network/network_menu.py index ca61b45834..f12cc815e1 100644 --- a/archinstall/lib/network/network_menu.py +++ b/archinstall/lib/network/network_menu.py @@ -161,9 +161,9 @@ async def _edit_iface(self, edit_nic: Nic) -> Nic: dns = dns_servers.split(' ') return Nic(iface=iface_name, ip=ip, gateway=gateway, dns=dns, dhcp=False) - else: - # this will contain network iface names - return Nic(iface=iface_name) + + # this will contain network iface names + return Nic(iface=iface_name) async def select_network(preset: NetworkConfiguration | None) -> NetworkConfiguration | None: diff --git a/archinstall/lib/network/wifi_handler.py b/archinstall/lib/network/wifi_handler.py index 7acef9fab2..4ff820b99c 100644 --- a/archinstall/lib/network/wifi_handler.py +++ b/archinstall/lib/network/wifi_handler.py @@ -52,8 +52,7 @@ async def run(self) -> bool | None: case ResultType.Skip | ResultType.Reset: return False - setup_result = await self._setup_wifi(wifi_iface) - return setup_result + return await self._setup_wifi(wifi_iface) async def _enable_supplicant(self, wifi_iface: str) -> bool: self._wpa_config.load_config() @@ -81,9 +80,9 @@ async def _enable_supplicant(self, wifi_iface: str) -> bool: if result.success: debug('successfully enabled wpa_supplicant') return True - else: - debug(f'failed to enable wpa_supplicant: {result.error}') - return False + + debug(f'failed to enable wpa_supplicant: {result.error}') + return False def _find_wifi_interface(self) -> str | None: for iface in SYS_NET.iterdir(): @@ -264,6 +263,4 @@ def _get_scan_results(self, iface: str) -> list[WifiNetwork]: debug('No wifi networks found') return [] - networks = WifiNetwork.from_wpa(result.response) - - return networks + return WifiNetwork.from_wpa(result.response) diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py index 863c191caa..9c5595e3f9 100644 --- a/archinstall/lib/networking.py +++ b/archinstall/lib/networking.py @@ -147,9 +147,7 @@ def calc_checksum(icmp_packet: bytes) -> int: checksum += (icmp_packet[i] << 8) + (struct.unpack('B', icmp_packet[i + 1 : i + 2])[0] if len(icmp_packet[i + 1 : i + 2]) else 0) checksum = (checksum >> 16) + (checksum & 0xFFFF) - checksum = ~checksum & 0xFFFF - - return checksum + return ~checksum & 0xFFFF def build_icmp(payload: bytes) -> bytes: diff --git a/archinstall/lib/packages/packages.py b/archinstall/lib/packages/packages.py index 865aa846a3..6a98f11a1b 100644 --- a/archinstall/lib/packages/packages.py +++ b/archinstall/lib/packages/packages.py @@ -40,8 +40,7 @@ def package_group_info(package: str) -> PackageGroup | None: package_info: list[str] = [] for line in Pacman.run(f'-Sg {package}'): package_info.append(line.decode().strip()) - group = PackageGroup.from_package_group_output(package_info) - return group + return PackageGroup.from_package_group_output(package_info) except SysCallError: debug(f'Failed to get package info: {package}') diff --git a/archinstall/lib/translationhandler.py b/archinstall/lib/translationhandler.py index 015f96204f..73687003dc 100644 --- a/archinstall/lib/translationhandler.py +++ b/archinstall/lib/translationhandler.py @@ -30,8 +30,10 @@ def display_name(self) -> str: def is_match(self, lang_or_translated_lang: str) -> bool: if self.name_en == lang_or_translated_lang: return True - elif self.translated_lang == lang_or_translated_lang: + + if self.translated_lang == lang_or_translated_lang: return True + return False def json(self) -> str: diff --git a/archinstall/lib/utils/format.py b/archinstall/lib/utils/format.py index ef6c5e048f..35a855c01d 100644 --- a/archinstall/lib/utils/format.py +++ b/archinstall/lib/utils/format.py @@ -64,20 +64,24 @@ def _get_values( # A method of an instance does not make sense if callable(class_formatter): return class_formatter(o, filter_list) + # if is invoked by name we restrict it to a method of the class. No need to mess more - elif hasattr(o, class_formatter) and callable(getattr(o, class_formatter)): + if hasattr(o, class_formatter) and callable(getattr(o, class_formatter)): func = getattr(o, class_formatter) return func(filter_list) raise ValueError('Unsupported formatting call') - elif hasattr(o, 'table_data'): + + if hasattr(o, 'table_data'): return o.table_data() - elif hasattr(o, 'json'): + + if hasattr(o, 'json'): return o.json() - elif is_dataclass(o): + + if is_dataclass(o): return asdict(o) - else: - return o.__dict__ # type: ignore[unreachable] + + return o.__dict__ # type: ignore[unreachable] def table_components( diff --git a/archinstall/scripts/guided.py b/archinstall/scripts/guided.py index 9e04d27e61..e80afb4545 100644 --- a/archinstall/scripts/guided.py +++ b/archinstall/scripts/guided.py @@ -222,10 +222,10 @@ def main(arch_config_handler: ArchConfigHandler | None = None) -> None: arch_config_handler.config.disk_config, ): error(failure.description) - return + return None if arch_config_handler.args.dry_run: - return + return None if not arch_config_handler.args.silent: aborted = False @@ -253,6 +253,8 @@ def main(arch_config_handler: ArchConfigHandler | None = None) -> None: ApplicationHandler(), ) + return None + if __name__ == '__main__': main() diff --git a/archinstall/scripts/minimal.py b/archinstall/scripts/minimal.py index 0ab6da83e5..f257d4d4a5 100644 --- a/archinstall/scripts/minimal.py +++ b/archinstall/scripts/minimal.py @@ -72,7 +72,7 @@ async def main(arch_config_handler: ArchConfigHandler | None = None) -> None: arch_config_handler.config.save() if arch_config_handler.args.dry_run: - return + return None if not arch_config_handler.args.silent: aborted = False @@ -95,6 +95,8 @@ async def main(arch_config_handler: ArchConfigHandler | None = None) -> None: perform_installation(arch_config_handler) + return None + if __name__ == '__main__': tui.run(main) diff --git a/archinstall/scripts/only_hd.py b/archinstall/scripts/only_hd.py index 6a2374dfe9..793a53a418 100644 --- a/archinstall/scripts/only_hd.py +++ b/archinstall/scripts/only_hd.py @@ -73,7 +73,7 @@ def main(arch_config_handler: ArchConfigHandler | None = None) -> None: arch_config_handler.config.save() if arch_config_handler.args.dry_run: - return + return None if not arch_config_handler.args.silent: aborted = False @@ -96,6 +96,8 @@ def main(arch_config_handler: ArchConfigHandler | None = None) -> None: perform_installation(arch_config_handler) + return None + if __name__ == '__main__': main() diff --git a/archinstall/tui/menu_item.py b/archinstall/tui/menu_item.py index 401154bb77..8818ad6021 100644 --- a/archinstall/tui/menu_item.py +++ b/archinstall/tui/menu_item.py @@ -93,12 +93,14 @@ def is_empty(self) -> bool: def has_value(self) -> bool: if self.value is None: return False - elif isinstance(self.value, list) and len(self.value) == 0: + + if isinstance(self.value, list) and len(self.value) == 0: return False - elif isinstance(self.value, dict) and len(self.value) == 0: + + if isinstance(self.value, dict) and len(self.value) == 0: return False - else: - return True + + return True def get_display_value(self) -> str | None: if self.display_action is not None: @@ -250,8 +252,7 @@ def set_action_for_all(self, action: Callable[[Any], Any]) -> None: def items(self) -> list[MenuItem]: pattern = self._filter_pattern.lower() items = filter(lambda item: item.is_empty() or pattern in item.text.lower(), self._menu_items) - l_items = sorted(items, key=self._items_score) - return l_items + return sorted(items, key=self._items_score) def _items_score(self, item: MenuItem) -> int: pattern = self._filter_pattern.lower() @@ -339,7 +340,7 @@ def max_item_width(self) -> int: def _is_selectable(self, item: MenuItem) -> bool: if item.is_empty(): return False - elif item.read_only: + if item.read_only: return False return self.is_enabled(item) diff --git a/archinstall/tui/rich.py b/archinstall/tui/rich.py index 055ec22ce8..af843eb8f5 100644 --- a/archinstall/tui/rich.py +++ b/archinstall/tui/rich.py @@ -20,6 +20,4 @@ def stringify(self) -> str: buf.print(self) _ = string_io.seek(0) - output = string_io.read() - - return output + return string_io.read() diff --git a/pyproject.toml b/pyproject.toml index b6c246f473..edea6be282 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -208,6 +208,7 @@ select = [ "PLE", # Pylint errors "PLW", # Pylint warnings "PYI", # flake8-pyi + "RET", # flake8-return "RSE", # flake8-raise "RUF", # Ruff-specific rules "SLOT", # flake8-slot