Use list comprehension (#3105)

This commit is contained in:
codefiles 2025-01-11 19:30:27 -05:00 committed by GitHub
parent 7202d964dd
commit 3409f84e79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 16 additions and 21 deletions

View File

@ -2,7 +2,6 @@ from typing import TYPE_CHECKING, Any, override
from archinstall.tui import MenuItem, MenuItemGroup
from ..disk import DeviceModification
from ..interactions import select_disk_config
from ..interactions.disk_conf import select_lvm_config
from ..menu import AbstractSubMenu
@ -101,8 +100,7 @@ class DiskLayoutConfigurationMenu(AbstractSubMenu):
msg += str(_('Mountpoint')) + ': ' + str(disk_layout_conf.mountpoint)
return msg
device_mods: list[DeviceModification] = \
list(filter(lambda x: len(x.partitions) > 0, disk_layout_conf.device_modifications))
device_mods = [d for d in disk_layout_conf.device_modifications if d.partitions]
if device_mods:
output_partition = '{}: {}\n'.format(str(_('Configuration')), disk_layout_conf.config_type.display_msg())
@ -116,9 +114,7 @@ class DiskLayoutConfigurationMenu(AbstractSubMenu):
output_partition += partition_table + '\n'
# create btrfs table
btrfs_partitions = list(
filter(lambda p: len(p.btrfs_subvols) > 0, mod.partitions)
)
btrfs_partitions = [p for p in mod.partitions if p.btrfs_subvols]
for partition in btrfs_partitions:
output_btrfs += FormattedOutput.as_table(partition.btrfs_subvols) + '\n'

View File

@ -284,10 +284,10 @@ def select_partitions_to_encrypt(
# do not allow encrypting the boot partition
for mod in modification:
partitions += list(filter(lambda x: x.mountpoint != Path('/boot'), mod.partitions))
partitions += [p for p in mod.partitions if p.mountpoint != Path('/boot')]
# do not allow encrypting existing partitions that are not marked as wipe
avail_partitions = list(filter(lambda x: not x.exists(), partitions))
avail_partitions = [p for p in partitions if not p.exists()]
if avail_partitions:
group, header = MenuHelper.create_table(data=avail_partitions)

View File

@ -49,7 +49,7 @@ class FilesystemHandler:
debug('Disk layout configuration is set to pre-mount, not performing any operations')
return
device_mods = list(filter(lambda x: len(x.partitions) > 0, self._disk_config.device_modifications))
device_mods = [d for d in self._disk_config.device_modifications if d.partitions]
if not device_mods:
debug('No modifications required')

View File

@ -242,7 +242,7 @@ class Installer:
break
for mod in sorted_device_mods:
not_pv_part_mods = list(filter(lambda x: x not in pvs, mod.partitions))
not_pv_part_mods = [p for p in mod.partitions if p not in pvs]
# partitions have to mounted in the right order on btrfs the mountpoint will
# be empty as the actual subvolumes are getting mounted instead so we'll use

View File

@ -462,7 +462,7 @@ def suggest_multi_disk_layout(
filesystem_type = select_main_filesystem_format(advanced_options)
# find proper disk for /home
possible_devices = list(filter(lambda x: x.device_info.total_size >= min_home_partition_size, devices))
possible_devices = [d for d in devices if d.device_info.total_size >= min_home_partition_size]
home_device = max(possible_devices, key=lambda d: d.device_info.total_size) if possible_devices else None
# find proper device for /root

View File

@ -164,21 +164,20 @@ class ProfileHandler:
return next(filter(lambda x: x.name == name, self.profiles), None) # type: ignore
def get_top_level_profiles(self) -> list[Profile]:
return list(filter(lambda x: x.is_top_level_profile(), self.profiles))
return [p for p in self.profiles if p.is_top_level_profile()]
def get_server_profiles(self) -> list[Profile]:
return list(filter(lambda x: x.is_server_type_profile(), self.profiles))
return [p for p in self.profiles if p.is_server_type_profile()]
def get_desktop_profiles(self) -> list[Profile]:
return list(filter(lambda x: x.is_desktop_type_profile(), self.profiles))
return [p for p in self.profiles if p.is_desktop_type_profile()]
def get_custom_profiles(self) -> list[Profile]:
return list(filter(lambda x: x.is_custom_type_profile(), self.profiles))
return [p for p in self.profiles if p.is_custom_type_profile()]
def get_mac_addr_profiles(self) -> list[Profile]:
tailored = list(filter(lambda x: x.is_tailored(), self.profiles))
match_mac_addr_profiles = list(filter(lambda x: x.name in self._local_mac_addresses, tailored))
return match_mac_addr_profiles
tailored = [p for p in self.profiles if p.is_tailored()]
return [t for t in tailored if t.name in self._local_mac_addresses]
def install_greeter(self, install_session: 'Installer', greeter: GreeterType) -> None:
packages = []
@ -296,7 +295,7 @@ class ProfileHandler:
that the provided list contains only default_profiles with unique names
"""
counter = Counter([p.name for p in profiles])
duplicates = list(filter(lambda x: x[1] != 1, counter.items()))
duplicates = [x for x in counter.items() if x[1] != 1]
if len(duplicates) > 0:
err = str(_('Profiles must have unique name, but profile definitions with duplicate name found: {}')).format(duplicates[0][0])

View File

@ -74,7 +74,7 @@ def parse_disk_encryption() -> None:
# encrypt all partitions except the /boot
for mod in modification:
partitions += list(filter(lambda x: x.mountpoint != Path('/boot'), mod.partitions))
partitions += [p for p in mod.partitions if p.mountpoint != Path('/boot')]
archinstall.arguments['disk_encryption'] = disk.DiskEncryption(
encryption_type=disk.EncryptionType.Luks,

View File

@ -74,7 +74,7 @@ def parse_disk_encryption() -> None:
# encrypt all partitions except the /boot
for mod in modification:
partitions += list(filter(lambda x: x.mountpoint != Path('/boot'), mod.partitions))
partitions += [p for p in mod.partitions if p.mountpoint != Path('/boot')]
archinstall.arguments['disk_encryption'] = disk.DiskEncryption(
encryption_type=disk.EncryptionType.Luks,