Merge pull request 'CLI: fix @api.register cli typechecks' (#2127) from hsjobeki/clan-core:cli-api-typechecks into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2127
This commit is contained in:
@@ -107,7 +107,9 @@ API.register(open_file)
|
|||||||
self.register(wrapper)
|
self.register(wrapper)
|
||||||
return fn
|
return fn
|
||||||
|
|
||||||
def register(self, fn: Callable[..., T]) -> Callable[..., T]:
|
F = TypeVar("F", bound=Callable[..., Any])
|
||||||
|
|
||||||
|
def register(self, fn: F) -> F:
|
||||||
if fn.__name__ in self._registry:
|
if fn.__name__ in self._registry:
|
||||||
msg = f"Function {fn.__name__} already registered"
|
msg = f"Function {fn.__name__} already registered"
|
||||||
raise ClanError(msg)
|
raise ClanError(msg)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ def create_clan(options: CreateOptions) -> CreateClanResponse:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if options.initial:
|
if options.initial:
|
||||||
init_inventory(options.directory, init=options.initial)
|
init_inventory(str(options.directory), init=options.initial)
|
||||||
|
|
||||||
response = CreateClanResponse(
|
response = CreateClanResponse(
|
||||||
flake_init=flake_init,
|
flake_init=flake_init,
|
||||||
|
|||||||
@@ -35,5 +35,5 @@ Service = dict[str, Any]
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Inventory:
|
class Inventory:
|
||||||
meta: Meta
|
meta: Meta
|
||||||
services: Service
|
|
||||||
machines: dict[str, Machine] = field(default_factory = dict)
|
machines: dict[str, Machine] = field(default_factory = dict)
|
||||||
|
services: dict[str, Service] = field(default_factory = dict)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
jsonSchema=$(nix build .#inventory-schema --print-out-paths)/schema.json
|
jsonSchema=$(nix build .#inventory-schema-abstract --print-out-paths)/schema.json
|
||||||
nix run .#classgen "$jsonSchema" "$PKG_ROOT/clan_cli/inventory/classes.py"
|
nix run .#classgen "$jsonSchema" "$PKG_ROOT/clan_cli/inventory/classes.py"
|
||||||
@@ -198,7 +198,7 @@ def generate_machine_hardware_info(
|
|||||||
f"HW/report: Hardware configuration for {machine_name}",
|
f"HW/report: Hardware configuration for {machine_name}",
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
show_machine_hardware_platform(clan_dir, machine_name)
|
show_machine_hardware_platform(clan_dir.path, machine_name)
|
||||||
except ClanCmdError as e:
|
except ClanCmdError as e:
|
||||||
log.exception("Failed to evaluate hardware-configuration.nix")
|
log.exception("Failed to evaluate hardware-configuration.nix")
|
||||||
# Restore the backup file
|
# Restore the backup file
|
||||||
@@ -235,7 +235,7 @@ def hw_generate_command(args: argparse.Namespace) -> None:
|
|||||||
force=args.force,
|
force=args.force,
|
||||||
)
|
)
|
||||||
hw_info = generate_machine_hardware_info(
|
hw_info = generate_machine_hardware_info(
|
||||||
opts.flake, opts.machine, opts.target_host, opts.password, opts.force
|
opts.flake, opts.machine, opts.target_host, opts.password
|
||||||
)
|
)
|
||||||
print("Successfully generated hardware information.")
|
print("Successfully generated hardware information.")
|
||||||
print(f"Target: {opts.machine} ({opts.target_host})")
|
print(f"Target: {opts.machine} ({opts.target_host})")
|
||||||
|
|||||||
@@ -124,7 +124,7 @@
|
|||||||
classFile = "classes.py";
|
classFile = "classes.py";
|
||||||
};
|
};
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
${self'.packages.classgen}/bin/classgen ${self'.packages.inventory-schema}/schema.json b_classes.py --stop-at "Service"
|
${self'.packages.classgen}/bin/classgen ${self'.packages.inventory-schema-abstract}/schema.json b_classes.py --stop-at "Service"
|
||||||
file1=$classFile
|
file1=$classFile
|
||||||
file2=b_classes.py
|
file2=b_classes.py
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from helpers import cli
|
|||||||
@pytest.mark.with_core
|
@pytest.mark.with_core
|
||||||
def test_list_modules(test_flake_with_core: FlakeForTest) -> None:
|
def test_list_modules(test_flake_with_core: FlakeForTest) -> None:
|
||||||
base_path = test_flake_with_core.path
|
base_path = test_flake_with_core.path
|
||||||
modules_info = list_modules(base_path)
|
modules_info = list_modules(str(base_path))
|
||||||
|
|
||||||
assert len(modules_info.items()) > 1
|
assert len(modules_info.items()) > 1
|
||||||
# Random test for those two modules
|
# Random test for those two modules
|
||||||
|
|||||||
Reference in New Issue
Block a user