clan-vm-manager: Fix regression
This commit is contained in:
@@ -44,14 +44,14 @@ except ImportError:
|
||||
def flake_path(arg: str) -> FlakeId:
|
||||
flake_dir = Path(arg).resolve()
|
||||
if flake_dir.exists() and flake_dir.is_dir():
|
||||
return FlakeId(flake_dir)
|
||||
return FlakeId(str(flake_dir))
|
||||
return FlakeId(arg)
|
||||
|
||||
|
||||
def default_flake() -> FlakeId | None:
|
||||
val = get_clan_flake_toplevel_or_env()
|
||||
if val:
|
||||
return FlakeId(val)
|
||||
return FlakeId(str(val))
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ class FlakeConfig:
|
||||
def __post_init__(self) -> None:
|
||||
if isinstance(self.vm, dict):
|
||||
self.vm = VmConfig(**self.vm)
|
||||
if isinstance(self.flake_url, dict):
|
||||
self.flake_url = FlakeId(**self.flake_url)
|
||||
|
||||
|
||||
def run_cmd(cmd: list[str]) -> str:
|
||||
@@ -46,7 +48,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
|
||||
f"Machine {machine_name} not found in {flake_url}. Available machines: {', '.join(machines)}"
|
||||
)
|
||||
|
||||
machine = Machine(machine_name, FlakeId(flake_url))
|
||||
machine = Machine(machine_name, FlakeId(str(flake_url)))
|
||||
vm = inspect_vm(machine)
|
||||
|
||||
# Make symlink to gcroots from vm.machine_icon
|
||||
@@ -89,7 +91,7 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
|
||||
meta = nix_metadata(flake_url)
|
||||
return FlakeConfig(
|
||||
vm=vm,
|
||||
flake_url=FlakeId(flake_url),
|
||||
flake_url=FlakeId(str(flake_url)),
|
||||
clan_name=clan_name,
|
||||
flake_attr=machine_name,
|
||||
nar_hash=meta["locked"]["narHash"],
|
||||
@@ -109,7 +111,7 @@ class InspectOptions:
|
||||
def inspect_command(args: argparse.Namespace) -> None:
|
||||
inspect_options = InspectOptions(
|
||||
machine=args.machine,
|
||||
flake=args.flake or FlakeId(Path.cwd()),
|
||||
flake=args.flake or FlakeId(str(Path.cwd())),
|
||||
)
|
||||
res = inspect_flake(
|
||||
flake_url=str(inspect_options.flake), machine_name=inspect_options.machine
|
||||
|
||||
@@ -9,16 +9,19 @@ from .errors import ClanError
|
||||
|
||||
@dataclass
|
||||
class FlakeId:
|
||||
loc: str | Path
|
||||
loc: str
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
assert isinstance(
|
||||
self.loc, str | Path
|
||||
self.loc, str
|
||||
), f"Flake {self.loc} has an invalid format: {type(self.loc)}"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return str(self.loc)
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash(str(self.loc))
|
||||
|
||||
@property
|
||||
def path(self) -> Path:
|
||||
assert self.is_local(), f"Flake {self.loc} is not a local path"
|
||||
@@ -87,20 +90,11 @@ class ClanURI:
|
||||
self.machine_name = components.fragment
|
||||
|
||||
def _parse_url(self, comps: urllib.parse.ParseResult) -> FlakeId:
|
||||
comb = (
|
||||
comps.scheme,
|
||||
comps.netloc,
|
||||
comps.path,
|
||||
comps.params,
|
||||
comps.query,
|
||||
comps.fragment,
|
||||
)
|
||||
match comb:
|
||||
case ("file", "", path, "", "", _) | ("", "", path, "", "", _): # type: ignore
|
||||
flake_id = FlakeId(Path(path).expanduser().resolve())
|
||||
case _:
|
||||
flake_id = FlakeId(comps.geturl())
|
||||
|
||||
if comps.scheme == "" or "file" in comps.scheme:
|
||||
res_p = Path(comps.path).expanduser().resolve()
|
||||
flake_id = FlakeId(str(res_p))
|
||||
else:
|
||||
flake_id = FlakeId(comps.geturl())
|
||||
return flake_id
|
||||
|
||||
def get_url(self) -> str:
|
||||
|
||||
@@ -62,7 +62,6 @@ def list_history() -> list[HistoryEntry]:
|
||||
|
||||
def new_history_entry(url: str, machine: str) -> HistoryEntry:
|
||||
flake = inspect_flake(url, machine)
|
||||
flake.flake_url = flake.flake_url
|
||||
return HistoryEntry(
|
||||
flake=flake,
|
||||
last_used=datetime.datetime.now().isoformat(),
|
||||
|
||||
@@ -32,6 +32,8 @@ class VmConfig:
|
||||
self.flake_url = FlakeId(self.flake_url)
|
||||
if isinstance(self.waypipe, dict):
|
||||
self.waypipe = WaypipeConfig(**self.waypipe)
|
||||
if isinstance(self.flake_url, dict):
|
||||
self.flake_url = FlakeId(**self.flake_url)
|
||||
|
||||
|
||||
def inspect_vm(machine: Machine) -> VmConfig:
|
||||
@@ -48,7 +50,7 @@ class InspectOptions:
|
||||
def inspect_command(args: argparse.Namespace) -> None:
|
||||
inspect_options = InspectOptions(
|
||||
machine=args.machine,
|
||||
flake=args.flake or FlakeId(Path.cwd()),
|
||||
flake=args.flake or FlakeId(str(Path.cwd())),
|
||||
)
|
||||
|
||||
machine = Machine(inspect_options.machine, inspect_options.flake)
|
||||
|
||||
Reference in New Issue
Block a user