From 1adcada568d7c3b30e6a60f6d094b51eb2df6602 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 16 May 2025 17:02:16 +0200 Subject: [PATCH] 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 --- pkgs/clan-cli/clan_cli/completions.py | 3 +- pkgs/clan-cli/clan_lib/flake/flake.py | 35 +++++++++++++------ .../generate_test_vars/cli.py | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/completions.py b/pkgs/clan-cli/clan_cli/completions.py index d14783091..495ff5757 100644 --- a/pkgs/clan-cli/clan_cli/completions.py +++ b/pkgs/clan-cli/clan_cli/completions.py @@ -207,7 +207,8 @@ def complete_secrets( """ Provides completion functionality for clan secrets """ - from . import Flake + from clan_lib.flake.flake import Flake + from .secrets.secrets import list_secrets flake = clan_dir_result if (clan_dir_result := clan_dir(None)) is not None else "." diff --git a/pkgs/clan-cli/clan_lib/flake/flake.py b/pkgs/clan-cli/clan_lib/flake/flake.py index 8158399a1..5d7e9b54d 100644 --- a/pkgs/clan-cli/clan_lib/flake/flake.py +++ b/pkgs/clan-cli/clan_lib/flake/flake.py @@ -7,17 +7,6 @@ from pathlib import Path from tempfile import NamedTemporaryFile 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 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 """ + from clan_cli.cmd import run + from clan_cli.nix import ( + nix_command, + ) + cmd = [ "flake", "prefetch", @@ -650,6 +644,11 @@ class 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._cache = FlakeCache() @@ -698,6 +697,14 @@ class Flake: 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. """ + 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: self.invalidate_cache() assert self._cache is not None @@ -787,6 +794,12 @@ class Flake: > '{ ...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 self.prefetch() diff --git a/pkgs/generate-test-vars/generate_test_vars/cli.py b/pkgs/generate-test-vars/generate_test_vars/cli.py index e4b42d64a..68a2509ba 100755 --- a/pkgs/generate-test-vars/generate_test_vars/cli.py +++ b/pkgs/generate-test-vars/generate_test_vars/cli.py @@ -11,10 +11,10 @@ from tempfile import NamedTemporaryFile from typing import Any, override 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.nix import nix_config, nix_eval from clan_cli.vars.generate import generate_vars +from clan_lib.flake.flake import Flake sops_priv_key = ( "AGE-SECRET-KEY-1PL0M9CWRCG3PZ9DXRTTLMCVD57U6JDFE8K7DNVQ35F4JENZ6G3MQ0RQLRV"