plesty.sdk.cache

Cache management.

Classes

CachedFile

Function decorator for defining cached (text) files with content generated at runtime.

Functions

ensure_cache(→ pathlib.Path)

Ensure that the '.plesty' cache directory exists and that all files are

gitignore(→ str)

This file causes the entire '.plesty' cache directory to be ignored by version control.

sdk_version(→ str)

This file specifies the version number of the Plesty SDK used when creating the cache.

Module Contents

class plesty.sdk.cache.CachedFile(filename: str)

Function decorator for defining cached (text) files with content generated at runtime. This class also serves as a registry of files to be cached.

Add the File object to the registry.

Parameters:

filename (str) – The path to the file to be cached, relative to the ‘.plesty’ cache directory.

registry: ClassVar[list[CachedFile]] = []

Registry of instanciated CachedFile objects.

filename: str

The path to the file to be cached, relative to the ‘.plesty’ cache directory.

content: collections.abc.Callable[[], str]

The decorated function that generates the content of the cached file.

__call__(content: collections.abc.Callable[[], str]) → None

Apply the decorator to a function.

Parameters:

content (collections.abc.Callable[[], str])

Return type:

None

generate(cache_directory: pathlib.Path) → None

Write the content of the cached file to disk.

Parameters:

cache_directory (pathlib.Path) – The path to the ‘.plesty’ cache directory.

Return type:

None

is_correct(cache_directory: pathlib.Path) → bool

Check whether the cached file is up-to-date by comparing the generated content with the content of the existing file on disk.

Parameters:

cache_directory (pathlib.Path) – The path to the ‘.plesty’ cache directory.

Returns:

False, if the file does not exist on disk or its content is not up-to-date. True otherwise.

Return type:

bool

plesty.sdk.cache.ensure_cache(project_directory: pathlib.Path) → pathlib.Path

Ensure that the ‘.plesty’ cache directory exists and that all files are up-to-date. If not, (re)create the cache.

Parameters:

project_directory (pathlib.Path) – The path to the Python project directory.

Returns:

The path to the ‘.plesty’ cache directory.

Return type:

pathlib.Path

plesty.sdk.cache.gitignore() → str

This file causes the entire ‘.plesty’ cache directory to be ignored by version control.

Return type:

str

plesty.sdk.cache.sdk_version() → str

This file specifies the version number of the Plesty SDK used when creating the cache.

Return type:

str