repomatic.cache module¶
Global cache for tool executables, API responses and generated tool configs.
Four 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}/{digest}/{filename}, where the digest names the content. Two runs
that generate different configs for one tool (two checkouts, two branches)
write two files, so neither run reads the config of the other. Passed to tools
via explicit --config flags so repomatic never writes to the user’s
repository.
Locks (locks/): the lock files lock_path() names, which the tool
runner holds while a config file sits in the working directory. Neither listed
nor cleaned: a lock file deleted while a run holds it lets the next run start
without waiting.
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[ColumnSpec, ...] = (ColumnSpec(id='type', label='Type', description='', max_width=None, optional=False, sortable=True), ColumnSpec(id='name', label='Name', description='', max_width=None, optional=False, sortable=True), ColumnSpec(id='detail', label='Detail', description='', max_width=None, optional=False, sortable=True), ColumnSpec(id='size', label='Size', description='', max_width=None, optional=False, sortable=True), ColumnSpec(id='age', label='Age', description='', max_width=None, optional=False, sortable=True))¶
Column definitions for the
repomatic cache showtable.Lives beside the entry dataclasses it renders; the CLI derives its
--sort-bychoices from it.
- repomatic.cache.CONFIG_DIGEST_LENGTH = 16¶
Hex digits of the content digest that names a cached config directory.
Sixty-four bits: enough to keep apart every config one cache ever holds.
- 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 listing skips sidecars and the clean removes them along with their entry. Computing, writing, and verifying the digest itself stays with the caller (
tooling/binaries.py), per the module note above.
- 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, from
click_extra.get_cache_dir().
- Return type:
- Returns:
Absolute path to the cache root (may not exist yet).
- repomatic.cache.lock_path(name)[source]¶
Return the path of the lock file called name.
The file lives in the
locks/subtree, which no listing or clean touches.
- class repomatic.cache.CachedFile(*, path, size, mtime)[source]¶
Bases:
objectOne file of a cache subtree, with the facts every entry carries.
The three caches (binaries, HTTP responses, tool configs) differ only in how they name an entry. Each subclass reads its identity fields off the path of the entry, in
from_path(). The listing, the age filter and the clean are the same for all three, so they live here.- scope_option: ClassVar[str]¶
The
repomatic cache cleanoption that narrows a clean to one scope of this cache.
- classmethod clear(scope=None, max_age_days=None)[source]¶
Remove the entries of this cache that both filters select.
Empty directories left behind are pruned afterwards.
- 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.BinaryCacheEntry(*, path, size, 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.
- scope_option: ClassVar[str] = 'tool'¶
The
repomatic cache cleanoption that narrows a clean to one scope of this cache.
- classmethod from_path(path, root)[source]¶
Read the four levels of
{tool}/{version}/{platform}/{executable}.A digest sidecar is part of its binary’s entry, not an entry itself.
- class repomatic.cache.HttpCacheEntry(*, path, size, 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.
- scope_option: ClassVar[str] = 'namespace'¶
The
repomatic cache cleanoption that narrows a clean to one scope of this cache.
- classmethod from_path(path, root)[source]¶
Read
{namespace}/{key}.json, where the key can hold slashes.
- class repomatic.cache.ConfigCacheEntry(*, path, size, mtime, tool, digest, 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.
- scope_option: ClassVar[str] = 'tool'¶
The
repomatic cache cleanoption that narrows a clean to one scope of this cache.
- classmethod from_path(path, root)[source]¶
Read
{tool}/{digest}/{filename}.A file directly in the tool directory, with no digest level, is still an entry: the clean has to reach it.
- repomatic.cache.CACHE_KINDS: tuple[type[CachedFile], ...] = (<class 'repomatic.cache.BinaryCacheEntry'>, <class 'repomatic.cache.HttpCacheEntry'>, <class 'repomatic.cache.ConfigCacheEntry'>)¶
Every cache, in the order
repomatic cache showlists them.
- repomatic.cache.cached_binary_path(name, version, platform_key, executable)[source]¶
Construct the cache path for a binary (does not check existence).
- 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.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.store_config(tool_name, filename, content)[source]¶
Store a generated tool config in the cache atomically.
The digest of content names the directory of the file, so the same content always lands on the same path, and different content never overwrites it. A run storing a config refreshes its age, which keeps a config in use out of reach of
auto_purge().- Parameters:
- Return type:
- Returns:
Path to the cached config file, or
Noneif the write failed (permissions, read-only filesystem, sandbox restrictions).
- 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.clean(*, tool=None, namespace=None, max_age_days=None)[source]¶
Remove cached entries, as
repomatic cache cleanselects them.A scope filter reaches only the caches it applies to: tool narrows the binary and config caches and leaves HTTP responses alone, namespace the reverse. With neither filter, every cache is cleaned.
- Parameters:
- Return type:
- Returns:
Tuple of (files_deleted, bytes_freed) over every cache cleaned.
- repomatic.cache.auto_purge()[source]¶
Remove cached entries older than the configured TTL.
Called automatically after every store, and runs at most once per cache root per process (see
_PURGED_ROOTS). Purges every cache. Resolves the TTL fromREPOMATIC_CACHE_MAX_AGEenv var, thencache.max-agein[tool.repomatic], then theCacheConfig.max_agefield default. Set to0to disable.- Return type: