Fix: dynamically import clan_cli in flake methods

This is a temporary workaround to solve cyclic imports all these modules should be moved to clan_lib
soon afterwards
This commit is contained in:
Johannes Kirschbauer
2025-05-16 17:02:16 +02:00
parent fe0507b47c
commit 8ddf0e50d3
3 changed files with 27 additions and 13 deletions

View File

@@ -207,7 +207,8 @@ def complete_secrets(
""" """
Provides completion functionality for clan secrets Provides completion functionality for clan secrets
""" """
from . import Flake from clan_lib.flake.flake import Flake
from .secrets.secrets import list_secrets from .secrets.secrets import list_secrets
flake = clan_dir_result if (clan_dir_result := clan_dir(None)) is not None else "." flake = clan_dir_result if (clan_dir_result := clan_dir(None)) is not None else "."

View File

@@ -7,17 +7,6 @@ from pathlib import Path
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from typing import Any from typing import Any
from clan_cli.cmd import Log, RunOpts, run
from clan_cli.dirs import nixpkgs_source, select_source, user_cache_dir
from clan_cli.nix import (
nix_build,
nix_command,
nix_config,
nix_eval,
nix_metadata,
nix_test_store,
)
from clan_lib.errors import ClanError from clan_lib.errors import ClanError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@@ -625,6 +614,11 @@ class Flake:
""" """
Loads the flake into the store and populates self.store_path and self.hash such that the flake can evaluate locally and offline Loads the flake into the store and populates self.store_path and self.hash such that the flake can evaluate locally and offline
""" """
from clan_cli.cmd import run
from clan_cli.nix import (
nix_command,
)
cmd = [ cmd = [
"flake", "flake",
"prefetch", "prefetch",
@@ -650,6 +644,11 @@ class Flake:
This method is used to refresh the cache by reloading it from the flake. This method is used to refresh the cache by reloading it from the flake.
""" """
from clan_cli.dirs import user_cache_dir
from clan_cli.nix import (
nix_metadata,
)
self.prefetch() self.prefetch()
self._cache = FlakeCache() self._cache = FlakeCache()
@@ -698,6 +697,14 @@ class Flake:
ClanError: If the number of outputs does not match the number of selectors. ClanError: If the number of outputs does not match the number of selectors.
AssertionError: If the cache or flake cache path is not properly initialized. AssertionError: If the cache or flake cache path is not properly initialized.
""" """
from clan_cli.cmd import Log, RunOpts, run
from clan_cli.dirs import nixpkgs_source, select_source
from clan_cli.nix import (
nix_build,
nix_config,
nix_test_store,
)
if self._cache is None: if self._cache is None:
self.invalidate_cache() self.invalidate_cache()
assert self._cache is not None assert self._cache is not None
@@ -787,6 +794,12 @@ class Flake:
> '{ ...JSONSchema... }' > '{ ...JSONSchema... }'
""" """
from clan_cli.cmd import Log, RunOpts, run
from clan_cli.nix import (
nix_eval,
nix_test_store,
)
# Always prefetch, so we don't get any stale information # Always prefetch, so we don't get any stale information
self.prefetch() self.prefetch()

View File

@@ -11,10 +11,10 @@ from tempfile import NamedTemporaryFile
from typing import Any, override from typing import Any, override
from clan_cli.dirs import find_git_repo_root from clan_cli.dirs import find_git_repo_root
from clan_cli.flake import Flake
from clan_cli.machines.machines import Machine from clan_cli.machines.machines import Machine
from clan_cli.nix import nix_config, nix_eval from clan_cli.nix import nix_config, nix_eval
from clan_cli.vars.generate import generate_vars from clan_cli.vars.generate import generate_vars
from clan_lib.flake.flake import Flake
sops_priv_key = ( sops_priv_key = (
"AGE-SECRET-KEY-1PL0M9CWRCG3PZ9DXRTTLMCVD57U6JDFE8K7DNVQ35F4JENZ6G3MQ0RQLRV" "AGE-SECRET-KEY-1PL0M9CWRCG3PZ9DXRTTLMCVD57U6JDFE8K7DNVQ35F4JENZ6G3MQ0RQLRV"