Refactor skip_boot to use dependency injection (#4200)

This commit is contained in:
codefiles 2026-02-02 19:34:27 -05:00 committed by GitHub
parent b5f710425f
commit 12bd83ca8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 13 deletions

View File

@ -6,7 +6,6 @@ from archinstall.lib.translationhandler import tr
from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup from archinstall.tui.ui.menu_item import MenuItem, MenuItemGroup
from archinstall.tui.ui.result import ResultType from archinstall.tui.ui.result import ResultType
from ..args import arch_config_handler
from ..hardware import SysInfo from ..hardware import SysInfo
from ..menu.abstract_menu import AbstractSubMenu from ..menu.abstract_menu import AbstractSubMenu
from ..models.bootloader import Bootloader, BootloaderConfiguration from ..models.bootloader import Bootloader, BootloaderConfiguration
@ -16,8 +15,10 @@ class BootloaderMenu(AbstractSubMenu[BootloaderConfiguration]):
def __init__( def __init__(
self, self,
bootloader_conf: BootloaderConfiguration, bootloader_conf: BootloaderConfiguration,
skip_boot: bool = False,
): ):
self._bootloader_conf = bootloader_conf self._bootloader_conf = bootloader_conf
self._skip_boot = skip_boot
menu_options = self._define_menu_options() menu_options = self._define_menu_options()
self._item_group = MenuItemGroup(menu_options, sort_items=False, checkmarks=True) self._item_group = MenuItemGroup(menu_options, sort_items=False, checkmarks=True)
@ -91,7 +92,7 @@ class BootloaderMenu(AbstractSubMenu[BootloaderConfiguration]):
return self._bootloader_conf return self._bootloader_conf
def _select_bootloader(self, preset: Bootloader | None) -> Bootloader | None: def _select_bootloader(self, preset: Bootloader | None) -> Bootloader | None:
bootloader = select_bootloader(preset) bootloader = select_bootloader(preset, self._skip_boot)
if bootloader: if bootloader:
# Update UKI option based on bootloader # Update UKI option based on bootloader
@ -177,13 +178,16 @@ class BootloaderMenu(AbstractSubMenu[BootloaderConfiguration]):
raise ValueError('Unhandled result type') raise ValueError('Unhandled result type')
def select_bootloader(preset: Bootloader | None) -> Bootloader | None: def select_bootloader(
preset: Bootloader | None,
skip_boot: bool = False,
) -> Bootloader | None:
options = [] options = []
hidden_options = [] hidden_options = []
default = None default = None
header = tr('Select bootloader to install') header = tr('Select bootloader to install')
if arch_config_handler.args.skip_boot: if skip_boot:
default = Bootloader.NO_BOOTLOADER default = Bootloader.NO_BOOTLOADER
else: else:
hidden_options += [Bootloader.NO_BOOTLOADER] hidden_options += [Bootloader.NO_BOOTLOADER]

View File

@ -41,10 +41,12 @@ class GlobalMenu(AbstractMenu[None]):
self, self,
arch_config: ArchConfig, arch_config: ArchConfig,
mirror_list_handler: MirrorListHandler | None = None, mirror_list_handler: MirrorListHandler | None = None,
skip_boot: bool = False,
title: str | None = None, title: str | None = None,
) -> None: ) -> None:
self._arch_config = arch_config self._arch_config = arch_config
self._mirror_list_handler = mirror_list_handler self._mirror_list_handler = mirror_list_handler
self._skip_boot = skip_boot
menu_options = self._get_menu_options() menu_options = self._get_menu_options()
self._item_group = MenuItemGroup( self._item_group = MenuItemGroup(
@ -92,7 +94,7 @@ class GlobalMenu(AbstractMenu[None]):
), ),
MenuItem( MenuItem(
text=tr('Bootloader'), text=tr('Bootloader'),
value=BootloaderConfiguration.get_default(), value=BootloaderConfiguration.get_default(self._skip_boot),
action=self._select_bootloader_config, action=self._select_bootloader_config,
preview_action=self._prev_bootloader_config, preview_action=self._prev_bootloader_config,
key='bootloader_config', key='bootloader_config',
@ -528,9 +530,9 @@ class GlobalMenu(AbstractMenu[None]):
preset: BootloaderConfiguration | None = None, preset: BootloaderConfiguration | None = None,
) -> BootloaderConfiguration | None: ) -> BootloaderConfiguration | None:
if preset is None: if preset is None:
preset = BootloaderConfiguration.get_default() preset = BootloaderConfiguration.get_default(self._skip_boot)
bootloader_config = BootloaderMenu(preset).run() bootloader_config = BootloaderMenu(preset, self._skip_boot).run()
return bootloader_config return bootloader_config

View File

@ -31,10 +31,8 @@ class Bootloader(Enum):
return self.value return self.value
@classmethod @classmethod
def get_default(cls) -> Self: def get_default(cls, skip_boot: bool = False) -> Self:
from ..args import arch_config_handler if skip_boot:
if arch_config_handler.args.skip_boot:
return cls.NO_BOOTLOADER return cls.NO_BOOTLOADER
elif SysInfo.has_uefi(): elif SysInfo.has_uefi():
return cls.Systemd return cls.Systemd
@ -73,8 +71,8 @@ class BootloaderConfiguration:
return cls(bootloader=bootloader, uki=uki, removable=removable) return cls(bootloader=bootloader, uki=uki, removable=removable)
@classmethod @classmethod
def get_default(cls) -> Self: def get_default(cls, skip_boot: bool = False) -> Self:
bootloader = Bootloader.get_default() bootloader = Bootloader.get_default(skip_boot)
removable = SysInfo.has_uefi() and bootloader.has_removable_support() removable = SysInfo.has_uefi() and bootloader.has_removable_support()
uki = SysInfo.has_uefi() and bootloader.has_uki_support() uki = SysInfo.has_uefi() and bootloader.has_uki_support()
return cls(bootloader=bootloader, uki=uki, removable=removable) return cls(bootloader=bootloader, uki=uki, removable=removable)

View File

@ -37,6 +37,7 @@ def show_menu(mirror_list_handler: MirrorListHandler) -> None:
global_menu = GlobalMenu( global_menu = GlobalMenu(
arch_config_handler.config, arch_config_handler.config,
mirror_list_handler, mirror_list_handler,
arch_config_handler.args.skip_boot,
title=title_text, title=title_text,
) )