The one directory deeperfly keeps what it can fetch or make again (ADR-0151).
cache_dir is where the operating system keeps a user's
caches, or $DEEPERFLY_CACHE_DIR. Two parts live in it (PARTS): models, the
released detectors a run downloaded (released), and
jax, the kernels the GUI server compiled. Either can be deleted at any time: a
model is downloaded again, a kernel compiled again. deeperfly cache reports the
directory and clears it; deeperfly models remove deletes one model.
cache_dir
cache_dir(env: Mapping[str, str] | None = None) -> Path
The cache directory of deeperfly, which may not exist yet.
$DEEPERFLY_CACHE_DIR when set. Otherwise deeperfly under the user's cache:
$XDG_CACHE_HOME when that is an absolute path, else ~/.cache on Linux and
~/Library/Caches on macOS. On Windows, deeperfly/Cache under
%LOCALAPPDATA%. env is the environment it is read from, this process's by
default.
Source code in src/deeperfly/cache.py
| def cache_dir(env: Mapping[str, str] | None = None) -> Path:
"""The cache directory of deeperfly, which may not exist yet.
`$DEEPERFLY_CACHE_DIR` when set. Otherwise `deeperfly` under the user's cache:
`$XDG_CACHE_HOME` when that is an absolute path, else `~/.cache` on Linux and
`~/Library/Caches` on macOS. On Windows, `deeperfly/Cache` under
`%LOCALAPPDATA%`. `env` is the environment it is read from, this process's by
default.
"""
env = os.environ if env is None else env
if env.get(ENV):
return Path(env[ENV]).expanduser().absolute()
home = Path(env.get("HOME") or Path.home())
if sys.platform == "win32":
local = env.get("LOCALAPPDATA", "")
base = Path(local) if local else home / "AppData" / "Local"
return base / "deeperfly" / "Cache"
xdg = env.get("XDG_CACHE_HOME", "")
if xdg and Path(xdg).is_absolute():
return Path(xdg) / "deeperfly"
if sys.platform == "darwin":
return home / "Library" / "Caches" / "deeperfly"
return home / ".cache" / "deeperfly"
|
clear
clear() -> dict[str, int]
Delete every part of the cache; the bytes each held.
A part that is a link, as a models pointing at a shared copy, loses the link
and what it points at is left alone. Anything else in the directory stays.
Source code in src/deeperfly/cache.py
| def clear() -> dict[str, int]:
"""Delete every part of the cache; the bytes each held.
A part that is a link, as a `models` pointing at a shared copy, loses the link
and what it points at is left alone. Anything else in the directory stays.
"""
root = cache_dir()
freed = {}
for part in PARTS:
path = root / part
if path.is_symlink():
freed[part] = 0
path.unlink()
elif path.exists():
freed[part] = tree_size(path)
shutil.rmtree(path)
return freed
|
tree_size
tree_size(path: Path) -> int
The bytes of the files under path, 0 when it is not a directory.
Source code in src/deeperfly/cache.py
| def tree_size(path: Path) -> int:
"""The bytes of the files under `path`, 0 when it is not a directory."""
if not path.is_dir():
return 0
return sum(f.stat().st_size for f in path.rglob("*") if f.is_file())
|
usage
usage() -> dict[str, int]
The bytes each part of the cache holds, 0 for one that is not there.
Source code in src/deeperfly/cache.py
| def usage() -> dict[str, int]:
"""The bytes each part of the cache holds, 0 for one that is not there."""
root = cache_dir()
return {part: tree_size(root / part) for part in PARTS}
|