Merge pull request 'chore(select/cache): rename 'prefetch' to 'invalidate_cache'' (#3364) from hsjobeki/clan-core:vars-fixing into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3364
This commit is contained in:
@@ -447,14 +447,14 @@ class Flake:
|
|||||||
@property
|
@property
|
||||||
def is_local(self) -> bool:
|
def is_local(self) -> bool:
|
||||||
if self._is_local is None:
|
if self._is_local is None:
|
||||||
self.prefetch()
|
self.invalidate_cache()
|
||||||
assert isinstance(self._is_local, bool)
|
assert isinstance(self._is_local, bool)
|
||||||
return self._is_local
|
return self._is_local
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self) -> Path:
|
def path(self) -> Path:
|
||||||
if self._path is None:
|
if self._path is None:
|
||||||
self.prefetch()
|
self.invalidate_cache()
|
||||||
assert isinstance(self._path, Path)
|
assert isinstance(self._path, Path)
|
||||||
return self._path
|
return self._path
|
||||||
|
|
||||||
@@ -467,9 +467,11 @@ class Flake:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(f"Failed load eval cache: {e}. Continue without cache")
|
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 = [
|
cmd = [
|
||||||
"flake",
|
"flake",
|
||||||
@@ -536,7 +538,7 @@ class Flake:
|
|||||||
AssertionError: If the cache or flake cache path is not properly initialized.
|
AssertionError: If the cache or flake cache path is not properly initialized.
|
||||||
"""
|
"""
|
||||||
if self._cache is None:
|
if self._cache is None:
|
||||||
self.prefetch()
|
self.invalidate_cache()
|
||||||
assert self._cache is not None
|
assert self._cache is not None
|
||||||
|
|
||||||
if nix_options is 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.
|
nix_options (list[str] | None): Optional additional options to pass to the Nix build command.
|
||||||
"""
|
"""
|
||||||
if self._cache is None:
|
if self._cache is None:
|
||||||
self.prefetch()
|
self.invalidate_cache()
|
||||||
assert self._cache is not None
|
assert self._cache is not None
|
||||||
assert self.flake_cache_path is not None
|
assert self.flake_cache_path is not None
|
||||||
not_fetched_selectors = []
|
not_fetched_selectors = []
|
||||||
@@ -614,7 +616,7 @@ class Flake:
|
|||||||
nix_options (list[str] | None): Optional additional options to pass to the Nix build command.
|
nix_options (list[str] | None): Optional additional options to pass to the Nix build command.
|
||||||
"""
|
"""
|
||||||
if self._cache is None:
|
if self._cache is None:
|
||||||
self.prefetch()
|
self.invalidate_cache()
|
||||||
assert self._cache is not None
|
assert self._cache is not None
|
||||||
assert self.flake_cache_path is not None
|
assert self.flake_cache_path is not None
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Machine:
|
|||||||
return f"{self.flake}#{self.name}"
|
return f"{self.flake}#{self.name}"
|
||||||
|
|
||||||
def flush_caches(self) -> None:
|
def flush_caches(self) -> None:
|
||||||
self.flake.prefetch()
|
self.flake.invalidate_cache()
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return f"Machine(name={self.name}, flake={self.flake})"
|
return f"Machine(name={self.name}, flake={self.flake})"
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ def realize_nix_path(clan_dir: Flake, nix_path: str) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
flake = Flake(identifier=nix_path, inputs_from=clan_dir.identifier)
|
flake = Flake(identifier=nix_path, inputs_from=clan_dir.identifier)
|
||||||
flake.prefetch()
|
flake.invalidate_cache()
|
||||||
|
|
||||||
|
|
||||||
def get_template(
|
def get_template(
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ def test_cache_persistance(flake: ClanFlake) -> None:
|
|||||||
|
|
||||||
flake1 = Flake(str(flake.path))
|
flake1 = Flake(str(flake.path))
|
||||||
flake2 = Flake(str(flake.path))
|
flake2 = Flake(str(flake.path))
|
||||||
flake1.prefetch()
|
flake1.invalidate_cache()
|
||||||
flake2.prefetch()
|
flake2.invalidate_cache()
|
||||||
assert isinstance(flake1._cache, FlakeCache) # noqa: SLF001
|
assert isinstance(flake1._cache, FlakeCache) # noqa: SLF001
|
||||||
assert isinstance(flake2._cache, FlakeCache) # noqa: SLF001
|
assert isinstance(flake2._cache, FlakeCache) # noqa: SLF001
|
||||||
assert not flake1._cache.is_cached( # 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")
|
||||||
flake1.select("nixosConfigurations.*.config.networking.{hostName,hostId}")
|
flake1.select("nixosConfigurations.*.config.networking.{hostName,hostId}")
|
||||||
flake2.prefetch()
|
flake2.invalidate_cache()
|
||||||
assert flake2._cache.is_cached( # noqa: SLF001
|
assert flake2._cache.is_cached( # noqa: SLF001
|
||||||
"nixosConfigurations.*.config.networking.{hostName,hostId}"
|
"nixosConfigurations.*.config.networking.{hostName,hostId}"
|
||||||
)
|
)
|
||||||
@@ -80,8 +80,8 @@ def test_conditional_all_selector(flake: ClanFlake) -> None:
|
|||||||
|
|
||||||
flake1 = Flake(str(flake.path))
|
flake1 = Flake(str(flake.path))
|
||||||
flake2 = Flake(str(flake.path))
|
flake2 = Flake(str(flake.path))
|
||||||
flake1.prefetch()
|
flake1.invalidate_cache()
|
||||||
flake2.prefetch()
|
flake2.invalidate_cache()
|
||||||
assert isinstance(flake1._cache, FlakeCache) # noqa: SLF001
|
assert isinstance(flake1._cache, FlakeCache) # noqa: SLF001
|
||||||
assert isinstance(flake2._cache, FlakeCache) # noqa: SLF001
|
assert isinstance(flake2._cache, FlakeCache) # noqa: SLF001
|
||||||
log.info("First select")
|
log.info("First select")
|
||||||
@@ -93,7 +93,7 @@ def test_conditional_all_selector(flake: ClanFlake) -> None:
|
|||||||
assert res1 == res2
|
assert res1 == res2
|
||||||
assert res1["clan-core"].get("clan") is not None
|
assert res1["clan-core"].get("clan") is not None
|
||||||
|
|
||||||
flake2.prefetch()
|
flake2.invalidate_cache()
|
||||||
|
|
||||||
|
|
||||||
# Test that the caching works
|
# Test that the caching works
|
||||||
|
|||||||
Reference in New Issue
Block a user