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
| Attribute | Type | Description |
|---|---|---|
| manifest_version | string = 1.1 | the manifest format standard |
| manifest_name | string = staticfiles.json | The filename used to store the JSON mapping of original file paths to their hashed versions. |
| manifest_strict | boolean = true | Determines whether to raise a ValueError if a file path is missing from the manifest during lookup. |
| keep_intermediate_files | boolean = false | Controls 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
| Name | Type | Description |
|---|---|---|
| *args | any | Variable length argument list passed to the parent class constructor. |
| manifest_storage | object = None | The storage backend to use for the manifest file. Defaults to self if not provided. |
| **kwargs | any | Arbitrary 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
| Type | Description |
|---|---|
string | The 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
| Type | Description |
|---|---|
tuple | A 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
| Name | Type | Description |
|---|---|---|
| args | any | Positional arguments passed to the parent post_process method |
| kwargs | any | Keyword arguments including 'dry_run' which, if true, prevents saving the manifest to storage |
Returns
| Type | Description |
|---|---|
generator | A 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
| Type | Description |
|---|---|
null | No 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
| Name | Type | Description |
|---|---|---|
| name | string | The original relative path or URL of the static file to look up |
Returns
| Type | Description |
|---|---|
string | The URL-safe path to the hashed version of the file, preserving query strings or fragments |