Refactor(clan_lib): move nix bound classes out of the cli folder
This commit is contained in:
@@ -5,11 +5,12 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.nix_models.inventory import Inventory
|
||||
|
||||
from clan_cli.cmd import CmdOut, RunOpts, run
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.inventory import Inventory, init_inventory
|
||||
from clan_cli.inventory import init_inventory
|
||||
from clan_cli.nix import nix_command, nix_metadata, nix_shell
|
||||
from clan_cli.templates import (
|
||||
InputPrio,
|
||||
|
||||
@@ -5,11 +5,11 @@ from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.nix_models.inventory import Meta
|
||||
|
||||
from clan_cli.cmd import run
|
||||
from clan_cli.errors import ClanCmdError, ClanError
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.inventory import Meta
|
||||
from clan_cli.nix import nix_eval
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.nix_models.inventory import Inventory, Meta
|
||||
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.inventory import Inventory, Meta, load_inventory_json, set_inventory
|
||||
from clan_cli.inventory import load_inventory_json, set_inventory
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -19,7 +19,8 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from clan_lib.api import API, dataclass_to_dict, from_dict
|
||||
from clan_lib.api import API
|
||||
from clan_lib.nix_models.inventory import Inventory
|
||||
|
||||
from clan_cli.cmd import run
|
||||
from clan_cli.errors import ClanCmdError, ClanError
|
||||
@@ -27,28 +28,6 @@ from clan_cli.flake import Flake
|
||||
from clan_cli.git import commit_file
|
||||
from clan_cli.nix import nix_eval
|
||||
|
||||
from .classes import (
|
||||
Inventory,
|
||||
# Machine classes
|
||||
Machine,
|
||||
MachineDeploy,
|
||||
# General classes
|
||||
Meta,
|
||||
Service,
|
||||
)
|
||||
|
||||
# Re export classes here
|
||||
# This allows to renaming of classes in the generated code
|
||||
__all__ = [
|
||||
"Inventory",
|
||||
"Machine",
|
||||
"MachineDeploy",
|
||||
"Meta",
|
||||
"Service",
|
||||
"dataclass_to_dict",
|
||||
"from_dict",
|
||||
]
|
||||
|
||||
|
||||
def get_inventory_path(flake: Flake) -> Path:
|
||||
"""
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
# DO NOT EDIT THIS FILE MANUALLY. IT IS GENERATED.
|
||||
# This file was generated by running `pkgs/clan-cli/clan_cli/inventory/update.sh`
|
||||
#
|
||||
# ruff: noqa: N815
|
||||
# ruff: noqa: N806
|
||||
# ruff: noqa: F401
|
||||
# fmt: off
|
||||
from typing import Any, Literal, NotRequired, TypedDict
|
||||
|
||||
|
||||
class MachineDeploy(TypedDict):
|
||||
targetHost: NotRequired[str]
|
||||
|
||||
|
||||
class Machine(TypedDict):
|
||||
deploy: NotRequired[MachineDeploy]
|
||||
description: NotRequired[str]
|
||||
icon: NotRequired[str]
|
||||
machineClass: NotRequired[Literal["nixos", "darwin"]]
|
||||
name: NotRequired[str]
|
||||
tags: NotRequired[list[str]]
|
||||
|
||||
|
||||
class Meta(TypedDict):
|
||||
name: str
|
||||
description: NotRequired[str]
|
||||
icon: NotRequired[str]
|
||||
|
||||
Service = dict[str, Any]
|
||||
|
||||
|
||||
class Inventory(TypedDict):
|
||||
machines: NotRequired[dict[str, Machine]]
|
||||
meta: NotRequired[Meta]
|
||||
modules: NotRequired[dict[str, Any]]
|
||||
services: NotRequired[dict[str, Service]]
|
||||
tags: NotRequired[dict[str, Any]]
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
jsonSchema=$(nix build .#schemas.inventory-schema-abstract --print-out-paths)/schema.json
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
cd "$SCRIPT_DIR"
|
||||
nix run .#classgen -- "$jsonSchema" "../../../clan-cli/clan_cli/inventory/classes.py"
|
||||
@@ -5,6 +5,13 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.api.serde import dataclass_to_dict
|
||||
from clan_lib.nix_models.inventory import (
|
||||
Machine as InventoryMachine,
|
||||
)
|
||||
from clan_lib.nix_models.inventory import (
|
||||
MachineDeploy,
|
||||
)
|
||||
|
||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
||||
from clan_cli.dirs import get_clan_flake_toplevel_or_env
|
||||
@@ -12,11 +19,6 @@ from clan_cli.errors import ClanError
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.git import commit_file
|
||||
from clan_cli.inventory import (
|
||||
Machine as InventoryMachine,
|
||||
)
|
||||
from clan_cli.inventory import (
|
||||
MachineDeploy,
|
||||
dataclass_to_dict,
|
||||
patch_inventory_with,
|
||||
)
|
||||
from clan_cli.machines.list import list_nixos_machines
|
||||
|
||||
@@ -11,6 +11,7 @@ from clan_lib.api import API
|
||||
from clan_lib.api.disk import MachineDiskMatter
|
||||
from clan_lib.api.modules import parse_frontmatter
|
||||
from clan_lib.api.serde import dataclass_to_dict
|
||||
from clan_lib.nix_models.inventory import Machine as InventoryMachine
|
||||
|
||||
from clan_cli.cmd import RunOpts, run
|
||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
||||
@@ -21,7 +22,6 @@ from clan_cli.inventory import (
|
||||
load_inventory_eval,
|
||||
patch_inventory_with,
|
||||
)
|
||||
from clan_cli.inventory.classes import Machine as InventoryMachine
|
||||
from clan_cli.machines.hardware import HardwareConfig
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.nix import nix_eval
|
||||
|
||||
@@ -7,11 +7,12 @@ import re
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from clan_lib.nix_models.inventory import Machine as InventoryMachine
|
||||
|
||||
from clan_cli.cmd import Log, RunOpts, run
|
||||
from clan_cli.dirs import get_clan_flake_toplevel_or_env
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.inventory import Machine as InventoryMachine
|
||||
from clan_cli.machines.create import CreateOptions, create_machine
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.nix import nix_build, nix_command
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from clan_cli.inventory.classes import Inventory, Machine, Meta, Service
|
||||
from clan_lib.nix_models.inventory import Inventory, Machine, Meta, Service
|
||||
|
||||
|
||||
def test_make_meta_minimal() -> None:
|
||||
|
||||
@@ -5,15 +5,17 @@ from typing import TYPE_CHECKING
|
||||
import pytest
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.inventory import (
|
||||
Inventory,
|
||||
Machine,
|
||||
MachineDeploy,
|
||||
set_inventory,
|
||||
)
|
||||
from clan_cli.machines.create import CreateOptions, create_machine
|
||||
from clan_cli.nix import nix_eval, run
|
||||
from clan_cli.tests.fixtures_flakes import FlakeForTest
|
||||
from clan_lib.api.modules import list_modules
|
||||
from clan_lib.nix_models.inventory import (
|
||||
Inventory,
|
||||
Machine,
|
||||
MachineDeploy,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .age_keys import KeyPair
|
||||
|
||||
Reference in New Issue
Block a user