Skip to main content

ManifestFilesMixin

This class provides a mechanism for persisting and loading a mapping of original file paths to their hashed versions using a JSON manifest file. It extends file hashing capabilities by ensuring that file name lookups are performed against a stored manifest, supporting strict mode for missing entries and automatic manifest updates during post-processing. The mixin manages manifest storage, versioning, and integrity hashes to maintain consistency across static file deployments.

Attributes

AttributeTypeDescription
manifest_versionstring = 1.1the manifest format standard
manifest_namestring = staticfiles.jsonThe filename used to store the JSON mapping of original file paths to their hashed versions.
manifest_strictboolean = trueDetermines whether to raise a ValueError if a file path is missing from the manifest during lookup.
keep_intermediate_filesboolean = falseControls whether intermediate hashed files are preserved during the post-processing phase.

Constructor

Signature

def ManifestFilesMixin(
*args: any,
manifest_storage: object = None,
**kwargs: any
) - > null

Parameters

NameTypeDescription
*argsanyVariable length argument list passed to the parent class constructor.
manifest_storageobject = NoneThe storage backend to use for the manifest file. Defaults to self if not provided.
**kwargsanyArbitrary keyword arguments passed to the parent class constructor.

Methods


read_manifest()

@classmethod
def read_manifest() - > string

Reads the raw content of the manifest file from the storage backend. Returns the decoded string content or None if the file does not exist.

Returns

TypeDescription
stringThe raw string content of the manifest file, or None if the file is missing

load_manifest()

@classmethod
def load_manifest() - > tuple

Parses the manifest file content and validates its version. Returns a mapping of file paths and the manifest's unique hash, or raises a ValueError if the format is invalid.

Returns

TypeDescription
tupleA tuple containing a dictionary of hashed file paths and the manifest version hash string

post_process()

@classmethod
def post_process(
args: any,
kwargs: any
) - > generator

Triggers the standard file hashing process and persists the resulting mapping to the manifest file. This method ensures the manifest is updated after all files are processed unless a dry run is specified.

Parameters

NameTypeDescription
argsanyPositional arguments passed to the parent post_process method
kwargsanyKeyword arguments including 'dry_run' which, if true, prevents saving the manifest to storage

Returns

TypeDescription
generatorA generator yielding information about the processed files from the parent class

save_manifest()

@classmethod
def save_manifest() - > null

Serializes the current hashed file mapping into a JSON formatted manifest and saves it to storage. It calculates a unique hash for the manifest itself based on the sorted file entries.

Returns

TypeDescription
nullNo return value

stored_name()

@classmethod
def stored_name(
name: string
) - > string

Retrieves the hashed filename from the manifest for a given original path. If the name is missing and strict mode is enabled, it raises a ValueError; otherwise, it falls back to computing the hashed name.

Parameters

NameTypeDescription
namestringThe original relative path or URL of the static file to look up

Returns

TypeDescription
stringThe URL-safe path to the hashed version of the file, preserving query strings or fragments