Extend the mypy checks (#2120)
* Extend the mypy checks * Update * Update * Update --------- Co-authored-by: Daniel Girtler <girtler.daniel@gmail.com>
This commit is contained in:
parent
5c903df55f
commit
edbc135903
|
|
@ -225,8 +225,8 @@ def load_config():
|
||||||
if arguments.get('servers', None) is not None:
|
if arguments.get('servers', None) is not None:
|
||||||
storage['_selected_servers'] = arguments.get('servers', None)
|
storage['_selected_servers'] = arguments.get('servers', None)
|
||||||
|
|
||||||
if arguments.get('network_config', None) is not None:
|
if (net_config := arguments.get('network_config', None)) is not None:
|
||||||
config = NetworkConfiguration.parse_arg(arguments.get('network_config'))
|
config = NetworkConfiguration.parse_arg(net_config)
|
||||||
arguments['network_config'] = config
|
arguments['network_config'] = config
|
||||||
|
|
||||||
if arguments.get('!users', None) is not None or arguments.get('!superusers', None) is not None:
|
if arguments.get('!users', None) is not None or arguments.get('!superusers', None) is not None:
|
||||||
|
|
|
||||||
|
|
@ -308,9 +308,9 @@ class _PartitionInfo:
|
||||||
start: Size
|
start: Size
|
||||||
length: Size
|
length: Size
|
||||||
flags: List[PartitionFlag]
|
flags: List[PartitionFlag]
|
||||||
partn: int
|
partn: Optional[int]
|
||||||
partuuid: str
|
partuuid: Optional[str]
|
||||||
uuid: str
|
uuid: Optional[str]
|
||||||
disk: Disk
|
disk: Disk
|
||||||
mountpoints: List[Path]
|
mountpoints: List[Path]
|
||||||
btrfs_subvol_infos: List[_BtrfsSubvolumeInfo] = field(default_factory=list)
|
btrfs_subvol_infos: List[_BtrfsSubvolumeInfo] = field(default_factory=list)
|
||||||
|
|
@ -344,9 +344,9 @@ class _PartitionInfo:
|
||||||
cls,
|
cls,
|
||||||
partition: Partition,
|
partition: Partition,
|
||||||
fs_type: Optional[FilesystemType],
|
fs_type: Optional[FilesystemType],
|
||||||
partn: int,
|
partn: Optional[int],
|
||||||
partuuid: str,
|
partuuid: Optional[str],
|
||||||
uuid: str,
|
uuid: Optional[str],
|
||||||
mountpoints: List[Path],
|
mountpoints: List[Path],
|
||||||
btrfs_subvol_infos: List[_BtrfsSubvolumeInfo] = []
|
btrfs_subvol_infos: List[_BtrfsSubvolumeInfo] = []
|
||||||
) -> _PartitionInfo:
|
) -> _PartitionInfo:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ from typing import Dict, Optional, Any, TYPE_CHECKING, List
|
||||||
|
|
||||||
from ..disk import (
|
from ..disk import (
|
||||||
DeviceModification,
|
DeviceModification,
|
||||||
|
DiskLayoutConfiguration,
|
||||||
PartitionModification,
|
PartitionModification,
|
||||||
DiskEncryption,
|
DiskEncryption,
|
||||||
EncryptionType
|
EncryptionType
|
||||||
|
|
@ -26,7 +27,7 @@ if TYPE_CHECKING:
|
||||||
class DiskEncryptionMenu(AbstractSubMenu):
|
class DiskEncryptionMenu(AbstractSubMenu):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
mods: List[DeviceModification],
|
disk_config: DiskLayoutConfiguration,
|
||||||
data_store: Dict[str, Any],
|
data_store: Dict[str, Any],
|
||||||
preset: Optional[DiskEncryption] = None
|
preset: Optional[DiskEncryption] = None
|
||||||
):
|
):
|
||||||
|
|
@ -35,7 +36,7 @@ class DiskEncryptionMenu(AbstractSubMenu):
|
||||||
else:
|
else:
|
||||||
self._preset = DiskEncryption()
|
self._preset = DiskEncryption()
|
||||||
|
|
||||||
self._modifications = mods
|
self._disk_config = disk_config
|
||||||
super().__init__(data_store=data_store)
|
super().__init__(data_store=data_store)
|
||||||
|
|
||||||
def setup_selection_menu_options(self):
|
def setup_selection_menu_options(self):
|
||||||
|
|
@ -59,7 +60,7 @@ class DiskEncryptionMenu(AbstractSubMenu):
|
||||||
self._menu_options['partitions'] = \
|
self._menu_options['partitions'] = \
|
||||||
Selector(
|
Selector(
|
||||||
_('Partitions'),
|
_('Partitions'),
|
||||||
func=lambda preset: select_partitions_to_encrypt(self._modifications.device_modifications, preset),
|
func=lambda preset: select_partitions_to_encrypt(self._disk_config.device_modifications, preset),
|
||||||
display_func=lambda x: f'{len(x)} {_("Partitions")}' if x else None,
|
display_func=lambda x: f'{len(x)} {_("Partitions")}' if x else None,
|
||||||
dependencies=['encryption_password'],
|
dependencies=['encryption_password'],
|
||||||
default=self._preset.partitions,
|
default=self._preset.partitions,
|
||||||
|
|
|
||||||
|
|
@ -176,8 +176,11 @@ class GlobalMenu(AbstractMenu):
|
||||||
self._menu_options['abort'] = Selector(_('Abort'), exec_func=lambda n,v:exit(1))
|
self._menu_options['abort'] = Selector(_('Abort'), exec_func=lambda n,v:exit(1))
|
||||||
|
|
||||||
def _missing_configs(self) -> List[str]:
|
def _missing_configs(self) -> List[str]:
|
||||||
def check(s):
|
def check(s) -> bool:
|
||||||
return self._menu_options.get(s).has_selection()
|
obj = self._menu_options.get(s)
|
||||||
|
if obj and obj.has_selection():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def has_superuser() -> bool:
|
def has_superuser() -> bool:
|
||||||
sel = self._menu_options['!users']
|
sel = self._menu_options['!users']
|
||||||
|
|
@ -228,7 +231,7 @@ class GlobalMenu(AbstractMenu):
|
||||||
return config.type.display_msg()
|
return config.type.display_msg()
|
||||||
|
|
||||||
def _disk_encryption(self, preset: Optional[disk.DiskEncryption]) -> Optional[disk.DiskEncryption]:
|
def _disk_encryption(self, preset: Optional[disk.DiskEncryption]) -> Optional[disk.DiskEncryption]:
|
||||||
mods: Optional[List[disk.DeviceModification]] = self._menu_options['disk_config'].current_selection
|
mods: Optional[disk.DiskLayoutConfiguration] = self._menu_options['disk_config'].current_selection
|
||||||
|
|
||||||
if not mods:
|
if not mods:
|
||||||
# this should not happen as the encryption menu has the disk_config as dependency
|
# this should not happen as the encryption menu has the disk_config as dependency
|
||||||
|
|
@ -263,7 +266,7 @@ class GlobalMenu(AbstractMenu):
|
||||||
|
|
||||||
def _prev_additional_pkgs(self):
|
def _prev_additional_pkgs(self):
|
||||||
selector = self._menu_options['packages']
|
selector = self._menu_options['packages']
|
||||||
if selector.has_selection():
|
if selector.current_selection:
|
||||||
packages: List[str] = selector.current_selection
|
packages: List[str] = selector.current_selection
|
||||||
return format_cols(packages, None)
|
return format_cols(packages, None)
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,11 @@ class Installer:
|
||||||
We need to wait for it before we continue since we opted in to use a custom mirror/region.
|
We need to wait for it before we continue since we opted in to use a custom mirror/region.
|
||||||
"""
|
"""
|
||||||
info('Waiting for time sync (systemd-timesyncd.service) to complete.')
|
info('Waiting for time sync (systemd-timesyncd.service) to complete.')
|
||||||
while SysCommand('timedatectl show --property=NTPSynchronized --value').decode() != 'yes':
|
|
||||||
|
while True:
|
||||||
|
time_val = SysCommand('timedatectl show --property=NTPSynchronized --value').decode()
|
||||||
|
if time_val and time_val.strip() == 'yes':
|
||||||
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
info('Waiting for automatic mirror selection (reflector) to complete.')
|
info('Waiting for automatic mirror selection (reflector) to complete.')
|
||||||
|
|
@ -237,7 +241,7 @@ class Installer:
|
||||||
gen_enc_file = self._disk_encryption.should_generate_encryption_file(part_mod)
|
gen_enc_file = self._disk_encryption.should_generate_encryption_file(part_mod)
|
||||||
|
|
||||||
luks_handler = Luks2(
|
luks_handler = Luks2(
|
||||||
part_mod.dev_path,
|
part_mod.safe_dev_path,
|
||||||
mapper_name=part_mod.mapper_name,
|
mapper_name=part_mod.mapper_name,
|
||||||
password=self._disk_encryption.encryption_password
|
password=self._disk_encryption.encryption_password
|
||||||
)
|
)
|
||||||
|
|
@ -281,8 +285,10 @@ class Installer:
|
||||||
self._fstab_entries.append(f'{file} none swap defaults 0 0')
|
self._fstab_entries.append(f'{file} none swap defaults 0 0')
|
||||||
|
|
||||||
if enable_resume:
|
if enable_resume:
|
||||||
resume_uuid = SysCommand(f'findmnt -no UUID -T {self.target}{file}').decode('UTF-8').strip()
|
resume_uuid = SysCommand(f'findmnt -no UUID -T {self.target}{file}').decode()
|
||||||
resume_offset = SysCommand(f'/usr/bin/filefrag -v {self.target}{file}').decode().split('0:', 1)[1].split(":", 1)[1].split("..", 1)[0].strip()
|
resume_offset = SysCommand(
|
||||||
|
f'/usr/bin/filefrag -v {self.target}{file}'
|
||||||
|
).decode().split('0:', 1)[1].split(":", 1)[1].split("..", 1)[0].strip()
|
||||||
|
|
||||||
self._hooks.append('resume')
|
self._hooks.append('resume')
|
||||||
self._kernel_params.append(f'resume=UUID={resume_uuid}')
|
self._kernel_params.append(f'resume=UUID={resume_uuid}')
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class Selector:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
description: str,
|
description: str,
|
||||||
func: Optional[Callable[[str], Any]] = None,
|
func: Optional[Callable[[Any], Any]] = None,
|
||||||
display_func: Optional[Callable] = None,
|
display_func: Optional[Callable] = None,
|
||||||
default: Optional[Any] = None,
|
default: Optional[Any] = None,
|
||||||
enabled: bool = False,
|
enabled: bool = False,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, List
|
from typing import Optional, List, Dict, Any
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
@ -87,6 +87,10 @@ class PackageSearchResult:
|
||||||
makedepends: List[str]
|
makedepends: List[str]
|
||||||
checkdepends: List[str]
|
checkdepends: List[str]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_json(data: Dict[str, Any]) -> 'PackageSearchResult':
|
||||||
|
return PackageSearchResult(**data)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pkg_version(self) -> str:
|
def pkg_version(self) -> str:
|
||||||
return self.pkgver
|
return self.pkgver
|
||||||
|
|
@ -107,8 +111,18 @@ class PackageSearch:
|
||||||
page: int
|
page: int
|
||||||
results: List[PackageSearchResult]
|
results: List[PackageSearchResult]
|
||||||
|
|
||||||
def __post_init__(self):
|
@staticmethod
|
||||||
self.results = [PackageSearchResult(**x) for x in self.results]
|
def from_json(data: Dict[str, Any]) -> 'PackageSearch':
|
||||||
|
results = [PackageSearchResult.from_json(r) for r in data['results']]
|
||||||
|
|
||||||
|
return PackageSearch(
|
||||||
|
version=data['version'],
|
||||||
|
limit=data['limit'],
|
||||||
|
valid=data['valid'],
|
||||||
|
num_pages=data['num_pages'],
|
||||||
|
page=data['page'],
|
||||||
|
results=results
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ def package_search(package :str) -> PackageSearch:
|
||||||
raise PackageError(f"Could not locate package: [{response.code}] {response}")
|
raise PackageError(f"Could not locate package: [{response.code}] {response}")
|
||||||
|
|
||||||
data = response.read().decode('UTF-8')
|
data = response.read().decode('UTF-8')
|
||||||
|
json_data = json.loads(data)
|
||||||
return PackageSearch(**json.loads(data))
|
return PackageSearch.from_json(json_data)
|
||||||
|
|
||||||
|
|
||||||
def find_package(package :str) -> List[PackageSearchResult]:
|
def find_package(package :str) -> List[PackageSearchResult]:
|
||||||
|
|
|
||||||
|
|
@ -138,16 +138,16 @@ class ProfileHandler:
|
||||||
profiles = [profiles]
|
profiles = [profiles]
|
||||||
|
|
||||||
for profile in profiles:
|
for profile in profiles:
|
||||||
self._profiles.append(profile)
|
self.profiles.append(profile)
|
||||||
|
|
||||||
self._verify_unique_profile_names(self._profiles)
|
self._verify_unique_profile_names(self.profiles)
|
||||||
|
|
||||||
def remove_custom_profiles(self, profiles: Union[TProfile, List[TProfile]]):
|
def remove_custom_profiles(self, profiles: Union[TProfile, List[TProfile]]):
|
||||||
if not isinstance(profiles, list):
|
if not isinstance(profiles, list):
|
||||||
profiles = [profiles]
|
profiles = [profiles]
|
||||||
|
|
||||||
remove_names = [p.name for p in profiles]
|
remove_names = [p.name for p in profiles]
|
||||||
self._profiles = [p for p in self._profiles if p.name not in remove_names]
|
self._profiles = [p for p in self.profiles if p.name not in remove_names]
|
||||||
|
|
||||||
def get_profile_by_name(self, name: str) -> Optional[Profile]:
|
def get_profile_by_name(self, name: str) -> Optional[Profile]:
|
||||||
return next(filter(lambda x: x.name == name, self.profiles), None) # type: ignore
|
return next(filter(lambda x: x.name == name, self.profiles), None) # type: ignore
|
||||||
|
|
|
||||||
|
|
@ -206,4 +206,4 @@ class DeferredTranslation:
|
||||||
@classmethod
|
@classmethod
|
||||||
def install(cls):
|
def install(cls):
|
||||||
import builtins
|
import builtins
|
||||||
builtins._ = cls
|
builtins._ = cls # type: ignore
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ packages = ["archinstall"]
|
||||||
python_version = "3.11"
|
python_version = "3.11"
|
||||||
files = "archinstall/"
|
files = "archinstall/"
|
||||||
exclude = "tests"
|
exclude = "tests"
|
||||||
#check_untyped_defs=true
|
check_untyped_defs=true
|
||||||
|
|
||||||
[tool.bandit]
|
[tool.bandit]
|
||||||
targets = ["archinstall"]
|
targets = ["archinstall"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue