Skip to content

Commit

Permalink
Upgrade mypy 1.11 (archlinux#2588)
Browse files Browse the repository at this point in the history
* Upgrade mypy 1.11

* Update

* Update

* Remove TProfile type
  • Loading branch information
svartkanin authored Jul 26, 2024
1 parent 494cc29 commit 32bc375
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 36 deletions.
6 changes: 3 additions & 3 deletions archinstall/default_profiles/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)
Expand Down
26 changes: 8 additions & 18 deletions archinstall/default_profiles/profile.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,9 +10,6 @@
_: Any


TProfile = TypeVar('TProfile', bound='Profile')


class ProfileType(Enum):
# top level default_profiles
Server = 'Server'
Expand Down Expand Up @@ -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,
Expand All @@ -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]:
"""
Expand Down Expand Up @@ -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]
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions archinstall/default_profiles/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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
_: Any


class ServerProfile(Profile):
def __init__(self, current_value: List[TProfile] = []):
def __init__(self, current_value: List[Profile] = []):
super().__init__(
'Server',
ProfileType.Server,
Expand All @@ -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
)
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions archinstall/lib/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
10 changes: 5 additions & 5 deletions archinstall/lib/profile/profiles_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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]

Expand All @@ -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]

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down

0 comments on commit 32bc375

Please sign in to comment.