Skip to content

Commit

Permalink
Use list comprehension (#3105)
Browse files Browse the repository at this point in the history
  • Loading branch information
codefiles authored Jan 12, 2025
1 parent 7202d96 commit 3409f84
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 21 deletions.
8 changes: 2 additions & 6 deletions archinstall/lib/disk/disk_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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
Expand Down Expand Up @@ -101,8 +100,7 @@ def _prev_disk_layouts(self, item: MenuItem) -> str | None:
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())
Expand All @@ -116,9 +114,7 @@ def _prev_disk_layouts(self, item: MenuItem) -> str | None:
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'

Expand Down
4 changes: 2 additions & 2 deletions archinstall/lib/disk/encryption_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/disk/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def perform_filesystem_operations(self, show_countdown: bool = True) -> None:
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')
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def _mount_partition_layout(self, luks_handlers: dict[Any, Luks2]) -> None:
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
Expand Down
2 changes: 1 addition & 1 deletion archinstall/lib/interactions/disk_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions archinstall/lib/profile/profiles_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,20 @@ def get_profile_by_name(self, name: str) -> Profile | None:
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 = []
Expand Down Expand Up @@ -296,7 +295,7 @@ def _verify_unique_profile_names(self, profiles: list[Profile]) -> None:
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])
Expand Down
2 changes: 1 addition & 1 deletion archinstall/scripts/minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3409f84

Please sign in to comment.