repomatic.cache module¶
Global cache for downloaded tool executables, HTTP API responses, and generated tool configurations.
Three cache subtrees under the user-level cache directory:
Binary cache (bin/): platform-specific tool executables, keyed by
{tool}/{version}/{platform}/{executable}. Each cached binary has a
.sha256 sidecar written after a verified archive download. Cache hits
verify the binary against this sidecar to detect local tampering.
HTTP response cache (http/): JSON API responses from PyPI and GitHub,
keyed by {namespace}/{key}.json. Freshness is controlled by a per-caller
TTL (seconds); stale entries remain on disk until auto-purge removes them.
Config cache (config/): generated tool configuration files, keyed by
{tool}/{filename}. Overwritten on every invocation from the current
[tool.X] section in pyproject.toml or bundled defaults. Passed to
tools via explicit --config flags so repomatic never writes to the
user’s repository.
Note
The cache module is intentionally a pure storage layer. It does not know about checksums, registries, API semantics, or tool specifications. All trust and freshness decisions belong to the caller.
- repomatic.cache.CACHE_LIST_HEADER_DEFS: tuple[tuple[str, str], ...] = (('Type', 'type'), ('Name', 'name'), ('Detail', 'detail'), ('Size', 'size'), ('Age', 'age'))¶
Column definitions for the
repomatic cache showtable.Lives beside the entry dataclasses it renders; the CLI derives its
--sort-bychoices from it.
- class repomatic.cache.CachedFile(size, path, mtime)[source]¶
Bases:
objectThe filesystem facts every cached entry carries, whatever it holds.
The three caches (binaries, HTTP responses, tool configs) differ only in how they name an entry; everything the listing, the age filter and the purge loop need is here, so those all take a
CachedFileand never care which subtree it came from.Subclasses supply their own identity fields plus
kindandscope.- kind: ClassVar[str] = ''¶
The cache this entry belongs to, as the
repomatic cache showtable spells it.
- property scope: str¶
The name a
cache cleanfilter matches this entry on.Doubles as the table’s subject column: the thing a reader identifies the entry by (
--tool ruff,--namespace pypi) is the same thing the listing shows them, so one property serves both.
- class repomatic.cache.CacheEntry(size, path, mtime, tool='', version='', platform='', executable='')[source]¶
Bases:
CachedFileA single cached binary with its metadata.
- kind: ClassVar[str] = 'binary'¶
The cache this entry belongs to, as the
repomatic cache showtable spells it.
- class repomatic.cache.HttpCacheEntry(size, path, mtime, namespace='', key='')[source]¶
Bases:
CachedFileA single cached HTTP response with its metadata.
- kind: ClassVar[str] = 'http'¶
The cache this entry belongs to, as the
repomatic cache showtable spells it.
- class repomatic.cache.ConfigCacheEntry(size, path, mtime, tool='', filename='')[source]¶
Bases:
CachedFileA single cached tool configuration file with its metadata.
- kind: ClassVar[str] = 'config'¶
The cache this entry belongs to, as the
repomatic cache showtable spells it.
- repomatic.cache.cache_dir()[source]¶
Resolve the cache root directory.
Precedence (highest to lowest):
REPOMATIC_CACHE_DIRenvironment variable.cache.dirin[tool.repomatic].Platform-specific default.
- Return type:
- Returns:
Absolute path to the cache root (may not exist yet).
- repomatic.cache.cached_binary_path(name, version, platform_key, executable)[source]¶
Construct the cache path for a binary (does not check existence).
- repomatic.cache.SIDECAR_SUFFIX = '.sha256'¶
Suffix of the digest sidecar stored beside each cached binary.
Part of the binary cache’s on-disk layout: the listers skip sidecars and the purger removes them along with their entry. Computing, writing, and verifying the digest itself stays with the caller (
tool_runner), per the module note above.
- repomatic.cache.binary_sidecar_path(binary_path)[source]¶
Return the digest sidecar path for a cached binary.
- repomatic.cache.get_cached_binary(name, version, platform_key, executable)[source]¶
Return the cached binary path if it exists and is executable.
Does not verify the checksum. The caller is responsible for integrity checks since it owns the checksum value and the
skip_checksumflag.
- repomatic.cache.store_binary(name, version, platform_key, source)[source]¶
Copy an extracted binary into the cache atomically.
Writes to a temporary file in the target directory, then renames to the final name. This is atomic on POSIX (same-filesystem rename) and safe on Windows (
Path.replaceoverwrites atomically).Triggers
auto_purge()after a successful store.- Parameters:
- Return type:
- Returns:
Path to the cached binary, or
Nonewhen the cache is unwritable (a read-only cache root, a restricted CI mount): callers fall back to their staging copy, matchingstore_response()andstore_config().
- repomatic.cache.cache_info()[source]¶
List all cached binaries.
The
bin/layout is fixed at four levels ({tool}/{version}/{platform}/{executable}), so one glob walks it and the identity fields read straight off each path’s ancestry.- Return type:
- Returns:
List of
CacheEntryinstances, sorted by tool name then version.
- repomatic.cache.clear_cache(tool=None, max_age_days=None)[source]¶
Remove cached binaries.
- Parameters:
- Return type:
- Returns:
Tuple of (files_deleted, bytes_freed).
- repomatic.cache.get_cached_response(namespace, key, max_age_seconds)[source]¶
Return a cached HTTP response if it exists and is fresh.
- Parameters:
- Return type:
- Returns:
Raw cached response bytes, or
Noneif not cached or stale.
- repomatic.cache.store_response(namespace, key, data)[source]¶
Store an HTTP response in the cache atomically.
Uses the same write-to-temp-then-rename pattern as
store_binary(). Triggersauto_purge()after a successful store.- Parameters:
- Return type:
- Returns:
Path to the cached response file, or
Noneif the write failed (permissions, read-only filesystem, sandbox restrictions).
- repomatic.cache.http_cache_info()[source]¶
List all cached HTTP responses.
- Return type:
- Returns:
List of
HttpCacheEntryinstances, sorted by namespace then key.
- repomatic.cache.clear_http_cache(namespace=None, max_age_days=None)[source]¶
Remove cached HTTP responses.
- Parameters:
- Return type:
- Returns:
Tuple of (files_deleted, bytes_freed).
- repomatic.cache.store_config(tool_name, filename, content)[source]¶
Store a generated tool config in the cache atomically.
Uses the same write-to-temp-then-rename pattern as
store_response(). Does not triggerauto_purge(): config files are tiny and overwritten on every invocation, so age-based pruning is unnecessary.- Parameters:
- Return type:
- Returns:
Path to the cached config file, or
Noneif the write failed (permissions, read-only filesystem, sandbox restrictions).
- repomatic.cache.config_cache_info()[source]¶
List all cached tool configurations.
- Return type:
- Returns:
List of
ConfigCacheEntryinstances, sorted by tool name.
- repomatic.cache.clear_config_cache(tool=None, max_age_days=None)[source]¶
Remove cached tool configurations.
- Parameters:
tool (
str|None) – If set, only remove entries for this tool. Otherwise remove all cached configurations.max_age_days (
int|None) – If set, only remove entries older than this many days, matchingclear_cache()andclear_http_cache().
- Return type:
- Returns:
Tuple of (files_deleted, bytes_freed).
- repomatic.cache.cache_rows()[source]¶
List every cached file across the three caches, as table rows.
Backs
repomatic cache show: each entry renders itself (CachedFile.as_row()), so the command stays a print call and a new cache kind shows up in the listing by existing.
- repomatic.cache.auto_purge()[source]¶
Remove cached entries older than the configured TTL.
Called automatically after
store_binary()andstore_response(), and runs at most once per cache root per process (see_PURGED_ROOTS). Purges both binary and HTTP cache entries. Resolves the TTL fromREPOMATIC_CACHE_MAX_AGEenv var, thencache.max-agein[tool.repomatic], then theCacheConfig.max_agefield default. Set to0to disable.- Return type: