From 409f4afcd7179dbe4a1352c12db470d8d56ebaa8 Mon Sep 17 00:00:00 2001 From: ScarletEmanu <117443145+ScarletEmanu@users.noreply.github.com> Date: Sun, 5 Jan 2025 16:43:12 +0100 Subject: [PATCH] sync my fork with original one * disk: move ENC_IDENTIFIER (#3034) * general: remove unspecified exception handling (#3035) * chore(deps): update pre-commit hook pre-commit/mirrors-mypy to v1.14.0 (#3037) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency mypy to v1.14.0 (#3036) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * disk: change from_partition() parameters (#3039) * Rework profiles path (#3040) * Rework mount point argument (#3041) * Use Path.chmod() (#3051) * audio: remove incorrect use of dataclass (#3058) * chore(deps): update pre-commit hook astral-sh/ruff-pre-commit to v0.8.5 (#3063) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update pre-commit hook pre-commit/mirrors-mypy to v1.14.1 (#3062) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency pylint to v3.3.3 (#3046) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(deps): update dependency mypy to v1.14.1 (#3057) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * audio: capitalize enums (#3067) * fix(deps): update dependency ruff to v0.8.5 (#3064) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --------- Co-authored-by: codefiles <11915375+codefiles@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 4 ++-- archinstall/__init__.py | 4 +--- archinstall/lib/args.py | 3 --- archinstall/lib/configuration.py | 5 ++--- archinstall/lib/disk/device_handler.py | 5 +---- archinstall/lib/disk/device_model.py | 22 +++++++++---------- archinstall/lib/general.py | 8 ++----- archinstall/lib/interactions/disk_conf.py | 2 +- archinstall/lib/models/audio_configuration.py | 13 +++++------ archinstall/lib/profile/profiles_handler.py | 5 ++--- archinstall/lib/storage.py | 3 --- archinstall/scripts/guided.py | 2 +- archinstall/scripts/minimal.py | 2 +- archinstall/scripts/only_hd.py | 2 +- archinstall/scripts/swiss.py | 6 ++--- examples/interactive_installation.py | 2 +- examples/minimal_installation.py | 2 +- examples/only_hd_installation.py | 2 +- pyproject.toml | 6 ++--- tests/test_args.py | 2 +- 20 files changed, 41 insertions(+), 59 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34a9226d72..d6368d0ec2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,7 +35,7 @@ repos: args: [--config=.flake8] fail_fast: true - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.13.0 + rev: v1.14.1 hooks: - id: mypy args: [ @@ -47,7 +47,7 @@ repos: - pydantic-settings - pytest - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.4 + rev: v0.8.5 hooks: - id: ruff - repo: local diff --git a/archinstall/__init__.py b/archinstall/__init__.py index 39b935f21a..ac1c8caf3d 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -77,7 +77,7 @@ def define_arguments() -> None: parser.add_argument("--dry-run", "--dry_run", action="store_true", help="Generates a configuration file and then exits instead of performing an installation") parser.add_argument("--script", default="guided", nargs="?", help="Script to run for installation", type=str) - parser.add_argument("--mount-point", "--mount_point", nargs="?", type=str, + parser.add_argument("--mount-point", "--mount_point", default=Path("/mnt/archinstall"), nargs="?", type=Path, help="Define an alternate mount point for installation") parser.add_argument("--skip-ntp", action="store_true", help="Disables NTP checks during installation", default=False) parser.add_argument("--debug", action="store_true", default=False, help="Adds debug info into the log") @@ -266,8 +266,6 @@ def load_config() -> None: def post_process_arguments(args: dict[str, Any]) -> None: storage['arguments'] = args - if mountpoint := args.get('mount_point', None): - storage['MOUNT_POINT'] = Path(mountpoint) if args.get('debug', False): warn(f"Warning: --debug mode will write certain credentials to {storage['LOG_PATH']}/{storage['LOG_FILE']}!") diff --git a/archinstall/lib/args.py b/archinstall/lib/args.py index 77555bdb6a..a627247fc8 100644 --- a/archinstall/lib/args.py +++ b/archinstall/lib/args.py @@ -272,9 +272,6 @@ def _parse_args(self) -> Arguments: if args.config is None: args.silent = False - if args.mount_point is not None: - storage['MOUNT_POINT'] = Path(args.mount_point) - if args.debug: warn(f"Warning: --debug mode will write certain credentials to {storage['LOG_PATH']}/{storage['LOG_FILE']}!") diff --git a/archinstall/lib/configuration.py b/archinstall/lib/configuration.py index c21b1447de..aa04a53369 100644 --- a/archinstall/lib/configuration.py +++ b/archinstall/lib/configuration.py @@ -1,5 +1,4 @@ import json -import os import readline import stat from pathlib import Path @@ -117,14 +116,14 @@ def save_user_config(self, dest_path: Path) -> None: if self._is_valid_path(dest_path): target = dest_path / self._user_config_file target.write_text(self.user_config_to_json()) - os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) + target.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) def save_user_creds(self, dest_path: Path) -> None: if self._is_valid_path(dest_path): if user_creds := self.user_credentials_to_json(): target = dest_path / self._user_creds_file target.write_text(user_creds) - os.chmod(target, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) + target.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) def save(self, dest_path: Path | None = None) -> None: dest_path = dest_path or self._default_save_path diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py index 319fbeb377..4d54314d56 100644 --- a/archinstall/lib/disk/device_handler.py +++ b/archinstall/lib/disk/device_handler.py @@ -109,11 +109,8 @@ def load_devices(self) -> None: partition_infos.append( _PartitionInfo.from_partition( partition, + lsblk_info, fs_type, - lsblk_info.partn, - lsblk_info.partuuid, - lsblk_info.uuid, - lsblk_info.mountpoints, subvol_infos ) ) diff --git a/archinstall/lib/disk/device_model.py b/archinstall/lib/disk/device_model.py index b867c0c3de..6fecbcc9c0 100644 --- a/archinstall/lib/disk/device_model.py +++ b/archinstall/lib/disk/device_model.py @@ -24,6 +24,9 @@ _: Callable[[str], DeferredTranslation] +ENC_IDENTIFIER = 'ainst' + + class DiskLayoutType(Enum): Default = 'default_layout' Manual = 'manual_partitioning' @@ -96,7 +99,7 @@ def parse_arg(cls, disk_config: _DiskLayoutConfigurationSerialization) -> DiskLa mods = device_handler.detect_pre_mounted_mods(path) device_modifications.extend(mods) - storage['MOUNT_POINT'] = path + storage['arguments']['mount_point'] = path config.mountpoint = path @@ -447,11 +450,8 @@ def table_data(self) -> dict[str, str]: def from_partition( cls, partition: Partition, + lsblk_info: LsblkInfo, fs_type: FilesystemType | None, - partn: int | None, - partuuid: str | None, - uuid: str | None, # pylint: disable=redefined-outer-name - mountpoints: list[Path], btrfs_subvol_infos: list[_BtrfsSubvolumeInfo] = [] ) -> _PartitionInfo: partition_type = PartitionType.get_type_from_code(partition.type) @@ -478,11 +478,11 @@ def from_partition( start=start, length=length, flags=flags, - partn=partn, - partuuid=partuuid, - uuid=uuid, + partn=lsblk_info.partn, + partuuid=lsblk_info.partuuid, + uuid=lsblk_info.uuid, disk=partition.disk, - mountpoints=mountpoints, + mountpoints=lsblk_info.mountpoints, btrfs_subvol_infos=btrfs_subvol_infos ) @@ -919,7 +919,7 @@ def is_create_or_modify(self) -> bool: @property def mapper_name(self) -> str | None: if self.dev_path: - return f'{storage.get("ENC_IDENTIFIER", "ai")}{self.dev_path.name}' + return f'{ENC_IDENTIFIER}{self.dev_path.name}' return None def set_flag(self, flag: PartitionFlag) -> None: @@ -1076,7 +1076,7 @@ def obj_id(self) -> str: @property def mapper_name(self) -> str | None: if self.dev_path: - return f'{storage.get("ENC_IDENTIFIER", "ai")}{self.safe_dev_path.name}' + return f'{ENC_IDENTIFIER}{self.safe_dev_path.name}' return None @property diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index c0d136451d..4d01f78741 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -257,7 +257,7 @@ def peak(self, output: str | bytes) -> bool: peek_output_log.write(str(output)) if change_perm: - os.chmod(str(peak_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) + peak_logfile.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) sys.stdout.write(str(output)) sys.stdout.flush() @@ -317,14 +317,10 @@ def execute(self) -> bool: cmd_log.write(f"{time.time()} {self.cmd}\n") if change_perm: - os.chmod(str(history_logfile), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) + history_logfile.chmod(stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP) except (PermissionError, FileNotFoundError): # If history_logfile does not exist, ignore the error pass - except Exception as e: - exception_type = type(e).__name__ - error(f"Unexpected {exception_type} occurred in {self.cmd}: {e}") - raise e if storage.get('arguments', {}).get('debug'): debug(f"Executing: {self.cmd}") diff --git a/archinstall/lib/interactions/disk_conf.py b/archinstall/lib/interactions/disk_conf.py index e9246061c7..05308e95b5 100644 --- a/archinstall/lib/interactions/disk_conf.py +++ b/archinstall/lib/interactions/disk_conf.py @@ -148,7 +148,7 @@ def select_disk_config( mods = disk.device_handler.detect_pre_mounted_mods(path) - storage['MOUNT_POINT'] = path + storage['arguments']['mount_point'] = path return disk.DiskLayoutConfiguration( config_type=disk.DiskLayoutType.Pre_mount, diff --git a/archinstall/lib/models/audio_configuration.py b/archinstall/lib/models/audio_configuration.py index c302574a2a..a0e55ec813 100644 --- a/archinstall/lib/models/audio_configuration.py +++ b/archinstall/lib/models/audio_configuration.py @@ -7,11 +7,10 @@ from ..output import info -@dataclass class Audio(Enum): - NoAudio = 'No audio server' - Pipewire = 'pipewire' - Pulseaudio = 'pulseaudio' + NO_AUDIO = 'No audio server' + PIPEWIRE = 'pipewire' + PULSEAUDIO = 'pulseaudio' @dataclass @@ -36,12 +35,12 @@ def install_audio_config( info(f'Installing audio server: {self.audio.name}') match self.audio: - case Audio.Pipewire: + case Audio.PIPEWIRE: PipewireProfile().install(installation) - case Audio.Pulseaudio: + case Audio.PULSEAUDIO: installation.add_additional_packages("pulseaudio") - if self.audio != Audio.NoAudio: + if self.audio != Audio.NO_AUDIO: if SysInfo.requires_sof_fw(): installation.add_additional_packages('sof-firmware') diff --git a/archinstall/lib/profile/profiles_handler.py b/archinstall/lib/profile/profiles_handler.py index 63d0a87b61..2b0bc3c2fe 100644 --- a/archinstall/lib/profile/profiles_handler.py +++ b/archinstall/lib/profile/profiles_handler.py @@ -14,7 +14,6 @@ from ..hardware import GfxDriver from ..networking import fetch_data_from_url, list_interfaces from ..output import debug, error, info -from ..storage import storage from .profile_model import ProfileConfiguration if TYPE_CHECKING: @@ -29,7 +28,6 @@ class ProfileHandler: def __init__(self) -> None: - self._profiles_path: Path = storage['PROFILE'] self._profiles: list[Profile] | None = None # special variable to keep track of a profile url configuration @@ -346,8 +344,9 @@ def _find_available_profiles(self) -> list[Profile]: """ Search the profile path for profile definitions """ + profiles_path = Path(__file__).parents[2] / 'default_profiles' profiles = [] - for file in self._profiles_path.glob('**/*.py'): + for file in profiles_path.glob('**/*.py'): # ignore the abstract default_profiles class if 'profile.py' in file.name: continue diff --git a/archinstall/lib/storage.py b/archinstall/lib/storage.py index 21500dfa3c..d8474fe10d 100644 --- a/archinstall/lib/storage.py +++ b/archinstall/lib/storage.py @@ -9,9 +9,6 @@ from typing import Any storage: dict[str, Any] = { - 'PROFILE': Path(__file__).parent.parent.joinpath('default_profiles'), 'LOG_PATH': Path('/var/log/archinstall'), 'LOG_FILE': Path('install.log'), - 'MOUNT_POINT': Path('/mnt/archinstall'), - 'ENC_IDENTIFIER': 'ainst', } diff --git a/archinstall/scripts/guided.py b/archinstall/scripts/guided.py index 842df5441c..2938336a8b 100644 --- a/archinstall/scripts/guided.py +++ b/archinstall/scripts/guided.py @@ -180,7 +180,7 @@ def guided() -> None: ) fs_handler.perform_filesystem_operations() - perform_installation(archinstall.storage.get('MOUNT_POINT', Path('/mnt'))) + perform_installation(archinstall.arguments.get('mount_point', Path('/mnt'))) guided() diff --git a/archinstall/scripts/minimal.py b/archinstall/scripts/minimal.py index 06d9312af1..3395b7b0c7 100644 --- a/archinstall/scripts/minimal.py +++ b/archinstall/scripts/minimal.py @@ -107,7 +107,7 @@ def minimal() -> None: ) fs_handler.perform_filesystem_operations() - perform_installation(archinstall.storage.get('MOUNT_POINT', Path('/mnt'))) + perform_installation(archinstall.arguments.get('mount_point', Path('/mnt'))) minimal() diff --git a/archinstall/scripts/only_hd.py b/archinstall/scripts/only_hd.py index b0fbe8915a..3188f5355e 100644 --- a/archinstall/scripts/only_hd.py +++ b/archinstall/scripts/only_hd.py @@ -76,7 +76,7 @@ def only_hd() -> None: ) fs_handler.perform_filesystem_operations() - perform_installation(archinstall.storage.get('MOUNT_POINT', Path('/mnt'))) + perform_installation(archinstall.arguments.get('mount_point', Path('/mnt'))) only_hd() diff --git a/archinstall/scripts/swiss.py b/archinstall/scripts/swiss.py index b321c6d4c2..f5bfbe6375 100644 --- a/archinstall/scripts/swiss.py +++ b/archinstall/scripts/swiss.py @@ -61,7 +61,7 @@ def execute(self) -> None: archinstall.arguments[item.key] = item.action(item.value) perform_installation( - archinstall.storage.get('MOUNT_POINT', Path('/mnt')), + archinstall.arguments.get('mount_point', Path('/mnt')), self._execution_mode ) case ExecutionMode.Only_OS: @@ -87,7 +87,7 @@ def execute(self) -> None: break perform_installation( - archinstall.storage.get('MOUNT_POINT', Path('/mnt')), + archinstall.arguments.get('mount_point', Path('/mnt')), self._execution_mode ) case _: @@ -266,7 +266,7 @@ def swiss() -> None: ) fs_handler.perform_filesystem_operations() - perform_installation(archinstall.storage.get('MOUNT_POINT', Path('/mnt')), mode) + perform_installation(archinstall.arguments.get('mount_point', Path('/mnt')), mode) swiss() diff --git a/examples/interactive_installation.py b/examples/interactive_installation.py index 7603a49384..c2de1725c4 100644 --- a/examples/interactive_installation.py +++ b/examples/interactive_installation.py @@ -180,7 +180,7 @@ def _guided() -> None: ) fs_handler.perform_filesystem_operations() - perform_installation(archinstall.storage.get('MOUNT_POINT', Path('/mnt'))) + perform_installation(archinstall.arguments.get('mount_point', Path('/mnt'))) _guided() diff --git a/examples/minimal_installation.py b/examples/minimal_installation.py index fd5dfcf7b0..eeec2dc37e 100644 --- a/examples/minimal_installation.py +++ b/examples/minimal_installation.py @@ -107,7 +107,7 @@ def _minimal() -> None: ) fs_handler.perform_filesystem_operations() - perform_installation(archinstall.storage.get('MOUNT_POINT', Path('/mnt'))) + perform_installation(archinstall.arguments.get('mount_point', Path('/mnt'))) _minimal() diff --git a/examples/only_hd_installation.py b/examples/only_hd_installation.py index b6de06efa9..7c6e37b61e 100644 --- a/examples/only_hd_installation.py +++ b/examples/only_hd_installation.py @@ -76,7 +76,7 @@ def _only_hd() -> None: ) fs_handler.perform_filesystem_operations() - perform_installation(archinstall.storage.get('MOUNT_POINT', Path('/mnt'))) + perform_installation(archinstall.arguments.get('mount_point', Path('/mnt'))) _only_hd() diff --git a/pyproject.toml b/pyproject.toml index 7ab3a5bd8c..bd9c96ed68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,11 +30,11 @@ Source = "https://github.com/archlinux/archinstall" [project.optional-dependencies] log = ["systemd_python==235"] dev = [ - "mypy==1.13.0", + "mypy==1.14.1", "flake8==7.1.1", "pre-commit==4.0.1", - "ruff==0.8.4", - "pylint==3.3.2", + "ruff==0.8.5", + "pylint==3.3.3", "pylint-pydantic==0.3.4", "pytest==8.3.4", ] diff --git a/tests/test_args.py b/tests/test_args.py index cc66dd9386..b1642f1647 100644 --- a/tests/test_args.py +++ b/tests/test_args.py @@ -161,7 +161,7 @@ def test_config_file_parsing( ), bootloader=Bootloader.Systemd, uki=False, - audio_config=AudioConfiguration(Audio.Pipewire), + audio_config=AudioConfiguration(Audio.PIPEWIRE), hostname='archy', kernels=['linux-zen'], ntp=True,