diff --git a/pkgs/clan-cli/clan_cli/flake.py b/pkgs/clan-cli/clan_cli/flake.py index 42f1838a1..25a59dd29 100644 --- a/pkgs/clan-cli/clan_cli/flake.py +++ b/pkgs/clan-cli/clan_cli/flake.py @@ -447,14 +447,14 @@ class Flake: @property def is_local(self) -> bool: if self._is_local is None: - self.prefetch() + self.invalidate_cache() assert isinstance(self._is_local, bool) return self._is_local @property def path(self) -> Path: if self._path is None: - self.prefetch() + self.invalidate_cache() assert isinstance(self._path, Path) return self._path @@ -467,9 +467,11 @@ class Flake: except Exception as e: log.warning(f"Failed load eval cache: {e}. Continue without cache") - def prefetch(self) -> None: + def invalidate_cache(self) -> None: """ - Run prefetch to flush the cache as well as initializing it. + Invalidate the cache and reload it. + + This method is used to refresh the cache by reloading it from the flake. """ cmd = [ "flake", @@ -536,7 +538,7 @@ class Flake: AssertionError: If the cache or flake cache path is not properly initialized. """ if self._cache is None: - self.prefetch() + self.invalidate_cache() assert self._cache is not None if nix_options is None: @@ -590,7 +592,7 @@ class Flake: nix_options (list[str] | None): Optional additional options to pass to the Nix build command. """ if self._cache is None: - self.prefetch() + self.invalidate_cache() assert self._cache is not None assert self.flake_cache_path is not None not_fetched_selectors = [] @@ -614,7 +616,7 @@ class Flake: nix_options (list[str] | None): Optional additional options to pass to the Nix build command. """ if self._cache is None: - self.prefetch() + self.invalidate_cache() assert self._cache is not None assert self.flake_cache_path is not None diff --git a/pkgs/clan-cli/clan_cli/machines/machines.py b/pkgs/clan-cli/clan_cli/machines/machines.py index ac96c217b..6727cb719 100644 --- a/pkgs/clan-cli/clan_cli/machines/machines.py +++ b/pkgs/clan-cli/clan_cli/machines/machines.py @@ -37,7 +37,7 @@ class Machine: return f"{self.flake}#{self.name}" def flush_caches(self) -> None: - self.flake.prefetch() + self.flake.invalidate_cache() def __str__(self) -> str: return f"Machine(name={self.name}, flake={self.flake})" diff --git a/pkgs/clan-cli/clan_cli/templates.py b/pkgs/clan-cli/clan_cli/templates.py index 4f2f0ea84..d3f632ec9 100644 --- a/pkgs/clan-cli/clan_cli/templates.py +++ b/pkgs/clan-cli/clan_cli/templates.py @@ -216,7 +216,7 @@ def realize_nix_path(clan_dir: Flake, nix_path: str) -> None: return flake = Flake(identifier=nix_path, inputs_from=clan_dir.identifier) - flake.prefetch() + flake.invalidate_cache() def get_template( diff --git a/pkgs/clan-cli/clan_cli/tests/test_flake_caching.py b/pkgs/clan-cli/clan_cli/tests/test_flake_caching.py index 79b323282..d50d37160 100644 --- a/pkgs/clan-cli/clan_cli/tests/test_flake_caching.py +++ b/pkgs/clan-cli/clan_cli/tests/test_flake_caching.py @@ -57,8 +57,8 @@ def test_cache_persistance(flake: ClanFlake) -> None: flake1 = Flake(str(flake.path)) flake2 = Flake(str(flake.path)) - flake1.prefetch() - flake2.prefetch() + flake1.invalidate_cache() + flake2.invalidate_cache() assert isinstance(flake1._cache, FlakeCache) # noqa: SLF001 assert isinstance(flake2._cache, FlakeCache) # noqa: SLF001 assert not flake1._cache.is_cached( # noqa: SLF001 @@ -66,7 +66,7 @@ def test_cache_persistance(flake: ClanFlake) -> None: ) flake1.select("nixosConfigurations.*.config.networking.hostName") flake1.select("nixosConfigurations.*.config.networking.{hostName,hostId}") - flake2.prefetch() + flake2.invalidate_cache() assert flake2._cache.is_cached( # noqa: SLF001 "nixosConfigurations.*.config.networking.{hostName,hostId}" ) @@ -80,8 +80,8 @@ def test_conditional_all_selector(flake: ClanFlake) -> None: flake1 = Flake(str(flake.path)) flake2 = Flake(str(flake.path)) - flake1.prefetch() - flake2.prefetch() + flake1.invalidate_cache() + flake2.invalidate_cache() assert isinstance(flake1._cache, FlakeCache) # noqa: SLF001 assert isinstance(flake2._cache, FlakeCache) # noqa: SLF001 log.info("First select") @@ -93,7 +93,7 @@ def test_conditional_all_selector(flake: ClanFlake) -> None: assert res1 == res2 assert res1["clan-core"].get("clan") is not None - flake2.prefetch() + flake2.invalidate_cache() # Test that the caching works