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

View File

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

View File

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