diff --git a/archinstall/default_profiles/desktop.py b/archinstall/default_profiles/desktop.py index 417d86d659..30f00618b1 100644 --- a/archinstall/default_profiles/desktop.py +++ b/archinstall/default_profiles/desktop.py @@ -55,7 +55,7 @@ def _do_on_select_profiles(self): def do_on_select(self) -> SelectResult: choice = profile_handler.select_profile( profile_handler.get_desktop_profiles(), - self._current_selection, + self.current_selection, title=str(_('Select your desired desktop environment')), multi=True ) @@ -71,14 +71,14 @@ def do_on_select(self) -> SelectResult: return SelectResult.ResetCurrent def post_install(self, install_session: 'Installer'): - for profile in self._current_selection: + for profile in self.current_selection: profile.post_install(install_session) def install(self, install_session: 'Installer'): # Install common packages for all desktop environments install_session.add_additional_packages(self.packages) - for profile in self._current_selection: + for profile in self.current_selection: info(f'Installing profile {profile.name}...') install_session.add_additional_packages(profile.packages) diff --git a/archinstall/default_profiles/profile.py b/archinstall/default_profiles/profile.py index 4c85b0c7db..cab15c81b7 100644 --- a/archinstall/default_profiles/profile.py +++ b/archinstall/default_profiles/profile.py @@ -1,7 +1,7 @@ from __future__ import annotations from enum import Enum, auto -from typing import List, Optional, Any, Dict, TYPE_CHECKING, TypeVar +from typing import List, Optional, Any, Dict, TYPE_CHECKING from archinstall.lib.utils.util import format_cols @@ -10,9 +10,6 @@ _: Any -TProfile = TypeVar('TProfile', bound='Profile') - - class ProfileType(Enum): # top level default_profiles Server = 'Server' @@ -50,7 +47,7 @@ def __init__( name: str, profile_type: ProfileType, description: str = '', - current_selection: List[TProfile] = [], + current_selection: List[Profile] = [], packages: List[str] = [], services: List[str] = [], support_gfx_driver: bool = False, @@ -66,17 +63,13 @@ def __init__( # self.gfx_driver: Optional[str] = None - self._current_selection = current_selection + self.current_selection = current_selection self._packages = packages self._services = services # Only used for custom default_profiles self.custom_enabled = False - @property - def current_selection(self) -> List[TProfile]: - return self._current_selection - @property def packages(self) -> List[str]: """ @@ -133,15 +126,12 @@ def set_custom_settings(self, settings: Dict[str, Any]): self.custom_settings = settings def current_selection_names(self) -> List[str]: - if self._current_selection: - return [s.name for s in self._current_selection] + if self.current_selection: + return [s.name for s in self.current_selection] return [] def reset(self): - self.set_current_selection([]) - - def set_current_selection(self, current_selection: List[TProfile]): - self._current_selection = current_selection + self.current_selection = [] def is_top_level_profile(self) -> bool: top_levels = [ProfileType.Desktop, ProfileType.Server, ProfileType.Xorg, ProfileType.Minimal, ProfileType.Custom] @@ -166,10 +156,10 @@ def is_custom_type_profile(self) -> bool: return self.profile_type == ProfileType.CustomType def is_graphic_driver_supported(self) -> bool: - if not self._current_selection: + if not self.current_selection: return self._support_gfx_driver else: - if any([p._support_gfx_driver for p in self._current_selection]): + if any([p._support_gfx_driver for p in self.current_selection]): return True return False diff --git a/archinstall/default_profiles/server.py b/archinstall/default_profiles/server.py index ab758975a5..8b2f0698aa 100644 --- a/archinstall/default_profiles/server.py +++ b/archinstall/default_profiles/server.py @@ -3,7 +3,7 @@ from archinstall.lib.output import info from archinstall.lib.menu import MenuSelectionType from archinstall.lib.profile.profiles_handler import profile_handler -from archinstall.default_profiles.profile import ProfileType, Profile, SelectResult, TProfile +from archinstall.default_profiles.profile import ProfileType, Profile, SelectResult if TYPE_CHECKING: from archinstall.lib.installer import Installer @@ -11,7 +11,7 @@ class ServerProfile(Profile): - def __init__(self, current_value: List[TProfile] = []): + def __init__(self, current_value: List[Profile] = []): super().__init__( 'Server', ProfileType.Server, @@ -24,7 +24,7 @@ def do_on_select(self) -> SelectResult: choice = profile_handler.select_profile( available_servers, - self._current_selection, + self.current_selection, title=str(_('Choose which servers to install, if none then a minimal installation will be done')), multi=True ) @@ -38,16 +38,16 @@ def do_on_select(self) -> SelectResult: case MenuSelectionType.Reset: return SelectResult.ResetCurrent - def post_install(self, install_session: 'Installer'): - for profile in self._current_selection: + def post_install(self, install_session: 'Installer') -> None: + for profile in self.current_selection: profile.post_install(install_session) - def install(self, install_session: 'Installer'): + def install(self, install_session: 'Installer') -> None: server_info = self.current_selection_names() details = ', '.join(server_info) info(f'Now installing the selected servers: {details}') - for server in self._current_selection: + for server in self.current_selection: info(f'Installing {server.name}...') install_session.add_additional_packages(server.packages) install_session.enable_service(server.services) diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 62a1ba2738..94a68e791b 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -5,18 +5,20 @@ from enum import Enum from pathlib import Path -from typing import Dict, Union, List, Any, Callable, Optional +from typing import Dict, Union, List, Any, Callable, Optional, TYPE_CHECKING from dataclasses import asdict, is_dataclass from .storage import storage +if TYPE_CHECKING: + from _typeshed import DataclassInstance class FormattedOutput: @classmethod def _get_values( cls, - o: Any, + o: 'DataclassInstance', class_formatter: Optional[Union[str, Callable]] = None, filter_list: List[str] = [] ) -> Dict[str, Any]: diff --git a/archinstall/lib/profile/profiles_handler.py b/archinstall/lib/profile/profiles_handler.py index b9acb4fe89..77483f5da0 100644 --- a/archinstall/lib/profile/profiles_handler.py +++ b/archinstall/lib/profile/profiles_handler.py @@ -10,7 +10,7 @@ from types import ModuleType from typing import List, TYPE_CHECKING, Any, Optional, Dict, Union -from archinstall.default_profiles.profile import Profile, TProfile, GreeterType +from archinstall.default_profiles.profile import Profile, GreeterType from .profile_model import ProfileConfiguration from ..hardware import GfxDriver from ..menu import MenuSelectionType, Menu, MenuSelection @@ -122,7 +122,7 @@ def parse_profile_config(self, profile_config: Dict[str, Any]) -> Optional[Profi custom_settings = profile_config.get('custom_settings', {}) profile.set_custom_settings(custom_settings) - profile.set_current_selection(valid_sub_profiles) + profile.current_selection = valid_sub_profiles return profile @@ -138,7 +138,7 @@ def profiles(self) -> List[Profile]: def _local_mac_addresses(self) -> List[str]: return list(list_interfaces()) - def add_custom_profiles(self, profiles: Union[TProfile, List[TProfile]]): + def add_custom_profiles(self, profiles: Union[Profile, List[Profile]]): if not isinstance(profiles, list): profiles = [profiles] @@ -147,7 +147,7 @@ def add_custom_profiles(self, profiles: Union[TProfile, List[TProfile]]): self._verify_unique_profile_names(self.profiles) - def remove_custom_profiles(self, profiles: Union[TProfile, List[TProfile]]): + def remove_custom_profiles(self, profiles: Union[Profile, List[Profile]]): if not isinstance(profiles, list): profiles = [profiles] @@ -359,7 +359,7 @@ def reset_top_level_profiles(self, exclude: List[Profile] = []): def select_profile( self, selectable_profiles: List[Profile], - current_profile: Optional[Union[TProfile, List[TProfile]]] = None, + current_profile: Optional[Union[Profile, List[Profile]]] = None, title: str = '', allow_reset: bool = True, multi: bool = False, diff --git a/pyproject.toml b/pyproject.toml index 9bca3f60cf..6102cecdb4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ Source = "https://github.com/archlinux/archinstall" [project.optional-dependencies] log = ["systemd_python==235"] dev = [ - "mypy==1.10.1", + "mypy==1.11.0", "flake8==7.1.0", "pre-commit==3.7.1", ]