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 pathlib import Path
|
||||||
|
|
||||||
from clan_lib.api import API
|
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.cmd import CmdOut, RunOpts, run
|
||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.flake import Flake
|
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.nix import nix_command, nix_metadata, nix_shell
|
||||||
from clan_cli.templates import (
|
from clan_cli.templates import (
|
||||||
InputPrio,
|
InputPrio,
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ from pathlib import Path
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from clan_lib.api import API
|
from clan_lib.api import API
|
||||||
|
from clan_lib.nix_models.inventory import Meta
|
||||||
|
|
||||||
from clan_cli.cmd import run
|
from clan_cli.cmd import run
|
||||||
from clan_cli.errors import ClanCmdError, ClanError
|
from clan_cli.errors import ClanCmdError, ClanError
|
||||||
from clan_cli.flake import Flake
|
from clan_cli.flake import Flake
|
||||||
from clan_cli.inventory import Meta
|
|
||||||
from clan_cli.nix import nix_eval
|
from clan_cli.nix import nix_eval
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from clan_lib.api import API
|
from clan_lib.api import API
|
||||||
|
from clan_lib.nix_models.inventory import Inventory, Meta
|
||||||
|
|
||||||
from clan_cli.flake import Flake
|
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
|
@dataclass
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ from dataclasses import dataclass
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
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.cmd import run
|
||||||
from clan_cli.errors import ClanCmdError, ClanError
|
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.git import commit_file
|
||||||
from clan_cli.nix import nix_eval
|
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:
|
def get_inventory_path(flake: Flake) -> Path:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ from dataclasses import dataclass
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_lib.api import API
|
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.completions import add_dynamic_completer, complete_tags
|
||||||
from clan_cli.dirs import get_clan_flake_toplevel_or_env
|
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.flake import Flake
|
||||||
from clan_cli.git import commit_file
|
from clan_cli.git import commit_file
|
||||||
from clan_cli.inventory import (
|
from clan_cli.inventory import (
|
||||||
Machine as InventoryMachine,
|
|
||||||
)
|
|
||||||
from clan_cli.inventory import (
|
|
||||||
MachineDeploy,
|
|
||||||
dataclass_to_dict,
|
|
||||||
patch_inventory_with,
|
patch_inventory_with,
|
||||||
)
|
)
|
||||||
from clan_cli.machines.list import list_nixos_machines
|
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.disk import MachineDiskMatter
|
||||||
from clan_lib.api.modules import parse_frontmatter
|
from clan_lib.api.modules import parse_frontmatter
|
||||||
from clan_lib.api.serde import dataclass_to_dict
|
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.cmd import RunOpts, run
|
||||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
from clan_cli.completions import add_dynamic_completer, complete_tags
|
||||||
@@ -21,7 +22,6 @@ from clan_cli.inventory import (
|
|||||||
load_inventory_eval,
|
load_inventory_eval,
|
||||||
patch_inventory_with,
|
patch_inventory_with,
|
||||||
)
|
)
|
||||||
from clan_cli.inventory.classes import Machine as InventoryMachine
|
|
||||||
from clan_cli.machines.hardware import HardwareConfig
|
from clan_cli.machines.hardware import HardwareConfig
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
from clan_cli.nix import nix_eval
|
from clan_cli.nix import nix_eval
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ import re
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
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.cmd import Log, RunOpts, run
|
||||||
from clan_cli.dirs import get_clan_flake_toplevel_or_env
|
from clan_cli.dirs import get_clan_flake_toplevel_or_env
|
||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.flake import Flake
|
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.create import CreateOptions, create_machine
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
from clan_cli.nix import nix_build, nix_command
|
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:
|
def test_make_meta_minimal() -> None:
|
||||||
|
|||||||
@@ -5,15 +5,17 @@ from typing import TYPE_CHECKING
|
|||||||
import pytest
|
import pytest
|
||||||
from clan_cli.flake import Flake
|
from clan_cli.flake import Flake
|
||||||
from clan_cli.inventory import (
|
from clan_cli.inventory import (
|
||||||
Inventory,
|
|
||||||
Machine,
|
|
||||||
MachineDeploy,
|
|
||||||
set_inventory,
|
set_inventory,
|
||||||
)
|
)
|
||||||
from clan_cli.machines.create import CreateOptions, create_machine
|
from clan_cli.machines.create import CreateOptions, create_machine
|
||||||
from clan_cli.nix import nix_eval, run
|
from clan_cli.nix import nix_eval, run
|
||||||
from clan_cli.tests.fixtures_flakes import FlakeForTest
|
from clan_cli.tests.fixtures_flakes import FlakeForTest
|
||||||
from clan_lib.api.modules import list_modules
|
from clan_lib.api.modules import list_modules
|
||||||
|
from clan_lib.nix_models.inventory import (
|
||||||
|
Inventory,
|
||||||
|
Machine,
|
||||||
|
MachineDeploy,
|
||||||
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .age_keys import KeyPair
|
from .age_keys import KeyPair
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ set -euo pipefail
|
|||||||
jsonSchema=$(nix build .#schemas.inventory-schema-abstract --print-out-paths)/schema.json
|
jsonSchema=$(nix build .#schemas.inventory-schema-abstract --print-out-paths)/schema.json
|
||||||
SCRIPT_DIR=$(dirname "$0")
|
SCRIPT_DIR=$(dirname "$0")
|
||||||
cd "$SCRIPT_DIR"
|
cd "$SCRIPT_DIR"
|
||||||
nix run .#classgen -- "$jsonSchema" "../../../clan-cli/clan_cli/inventory/classes.py"
|
nix run .#classgen -- "$jsonSchema" "./inventory.py"
|
||||||
@@ -13,8 +13,6 @@ from clan_cli.dirs import specific_machine_dir
|
|||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.flake import Flake
|
from clan_cli.flake import Flake
|
||||||
from clan_cli.inventory import patch_inventory_with
|
from clan_cli.inventory import patch_inventory_with
|
||||||
from clan_cli.inventory.classes import Machine as InventoryMachine
|
|
||||||
from clan_cli.inventory.classes import MachineDeploy
|
|
||||||
from clan_cli.machines.create import CreateOptions as ClanCreateOptions
|
from clan_cli.machines.create import CreateOptions as ClanCreateOptions
|
||||||
from clan_cli.machines.create import create_machine
|
from clan_cli.machines.create import create_machine
|
||||||
from clan_cli.machines.list import check_machine_online
|
from clan_cli.machines.list import check_machine_online
|
||||||
@@ -28,6 +26,8 @@ from clan_cli.ssh.host_key import HostKeyCheck
|
|||||||
from clan_cli.vars.generate import generate_vars_for_machine, get_generators_closure
|
from clan_cli.vars.generate import generate_vars_for_machine, get_generators_closure
|
||||||
|
|
||||||
from clan_lib.api.disk import hw_main_disk_options, set_machine_disk_schema
|
from clan_lib.api.disk import hw_main_disk_options, set_machine_disk_schema
|
||||||
|
from clan_lib.nix_models.inventory import Machine as InventoryMachine
|
||||||
|
from clan_lib.nix_models.inventory import MachineDeploy
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,10 @@
|
|||||||
checks = self'.packages.clan-cli.tests // {
|
checks = self'.packages.clan-cli.tests // {
|
||||||
inventory-classes-up-to-date = pkgs.stdenv.mkDerivation {
|
inventory-classes-up-to-date = pkgs.stdenv.mkDerivation {
|
||||||
name = "inventory-classes-up-to-date";
|
name = "inventory-classes-up-to-date";
|
||||||
src = ./clan_cli/inventory;
|
src = ./clan_lib/nix_models;
|
||||||
|
|
||||||
env = {
|
env = {
|
||||||
classFile = "classes.py";
|
classFile = "inventory.py";
|
||||||
};
|
};
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.inventory-schema-abstract}/schema.json b_classes.py
|
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.inventory-schema-abstract}/schema.json b_classes.py
|
||||||
|
|||||||
@@ -48,6 +48,6 @@ mkShell {
|
|||||||
|
|
||||||
# Generate classes.py from inventory schema
|
# Generate classes.py from inventory schema
|
||||||
# This file is in .gitignore
|
# This file is in .gitignore
|
||||||
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.inventory-schema-abstract}/schema.json $PKG_ROOT/clan_cli/inventory/classes.py
|
${self'.packages.classgen}/bin/classgen ${self'.legacyPackages.schemas.inventory-schema-abstract}/schema.json $PKG_ROOT/clan_lib/nix_models/inventory.py
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user