pestifer.util.cacheable_object module

Implements the general-purpose CacheableObject class and the TarBytesFS class.

class pestifer.util.cacheable_object.CacheableObject(resource_root: str | Path, *, cache_dir: str | Path | object | None = None, force_rebuild: bool = False, ignore_suffixes: Iterable[str] = (), resource_label: str | None = None, **kwargs)[source]

Bases: object

Base/mixin providing native cache/de-cache behavior controlled by resource mtimes.

Subclasses must implement: _build_from_resources(self, resource_root: Path) -> None to populate self from files in resource_root.

Behavior:

  • On __init__, compare cache mtime to newest file mtime under resource_root.

  • If cache is fresh, hydrate self from cache and set self.from_cache = True.

  • Else, call _build_from_resources(...), ensure self.from_cache = False, and write cache.

APP_NAME = 'pestifer'
APP_VERSION = '2.5.2'
CACHE_COMPRESS = ('gzip', 3)
CACHE_PREFIX = 'cacheobj'
VERSION_SCOPE = 'major.minor'
class pestifer.util.cacheable_object.TarBytesFS(tar_bytes: bytes, compression: str | None = None)[source]

Bases: object

A class for handling tarred bytes as a filesystem.

compression
classmethod from_file(path: str | Path, compression: str | None = None)[source]

Initializes a TarBytesFS instance from a file.

fs()[source]

Returns a FileSystem handle for the TarBytesFS object

ls(path: str = '')[source]

Lists the contents of a directory in the tarred filesystem.

open(path: str, mode: str = 'rb')[source]

Opens a file in the tarred filesystem and returns a context handle to that file.

tar_bytes