Chore(specific_machine_dir): use protocol to avoid direct dependency on machine class
This commit is contained in:
@@ -4,17 +4,24 @@ import sys
|
||||
import urllib.parse
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Protocol
|
||||
|
||||
from clan_lib.errors import ClanError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.machines.machines import Machine
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MachineSpecProtocol(Protocol):
|
||||
@property
|
||||
def flake(self) -> "Flake": ...
|
||||
|
||||
@property
|
||||
def name(self) -> str: ...
|
||||
|
||||
|
||||
def get_clan_flake_toplevel_or_env() -> Path | None:
|
||||
if clan_dir := os.environ.get("CLAN_DIR"):
|
||||
return Path(clan_dir)
|
||||
@@ -145,7 +152,7 @@ def machines_dir(flake: "Flake") -> Path:
|
||||
return Path(store_path) / "machines"
|
||||
|
||||
|
||||
def specific_machine_dir(machine: "Machine") -> Path:
|
||||
def specific_machine_dir(machine: "MachineSpecProtocol") -> Path:
|
||||
return machines_dir(machine.flake) / machine.name
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user