From 6d4db71ea3a2765af366e85a5b7913f0b5705d34 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 6 May 2025 17:12:52 +0200 Subject: [PATCH] Refactor(machine/class): use frozen dataclass for class 'machine' --- pkgs/clan-cli/clan_cli/machines/hardware.py | 13 ++++++------- pkgs/clan-cli/clan_cli/machines/machines.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index f441e615d..ac31f98d7 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -96,13 +96,12 @@ def generate_machine_hardware_info(opts: HardwareGenerateOptions) -> HardwareCon and place the resulting *.nix file in the machine's directory. """ - machine = Machine(opts.machine, flake=opts.flake) - - if opts.keyfile is not None: - machine.private_key = Path(opts.keyfile) - - if opts.target_host is not None: - machine.override_target_host = opts.target_host + machine = Machine( + opts.machine, + flake=opts.flake, + private_key=Path(opts.keyfile) if opts.keyfile else None, + override_target_host=opts.target_host, + ) hw_file = opts.backend.config_path(opts.flake.path, opts.machine) hw_file.parent.mkdir(parents=True, exist_ok=True) diff --git a/pkgs/clan-cli/clan_cli/machines/machines.py b/pkgs/clan-cli/clan_cli/machines/machines.py index e681d07d6..7dd9ca7f0 100644 --- a/pkgs/clan-cli/clan_cli/machines/machines.py +++ b/pkgs/clan-cli/clan_cli/machines/machines.py @@ -26,7 +26,7 @@ if TYPE_CHECKING: from clan_cli.vars.generate import Generator -@dataclass +@dataclass(frozen=True) class Machine: name: str flake: Flake