Skip to content

_manifest

Manifest parsing and validation. Pure functions.

Classes

RuntimeManifest dataclass

Manifest for a prebuilt runtime bundle.

This structure is typically loaded from a manifest.json stored alongside a runtime directory.

Attributes:

Name Type Description
runtime_version str

brmspy runtime bundle version.

fingerprint str

System fingerprint this runtime was built for.

r_version str

R version string used for the runtime build (for example "4.5.0").

cmdstan_version str

CmdStan version included in the runtime.

r_packages dict[str, str]

Mapping of R package names to versions.

manifest_hash str

Hash used to validate the runtime contents.

built_at str

Build timestamp.

Source code in brmspy/types/runtime.py
@dataclass(frozen=True)
class RuntimeManifest:
    """
    Manifest for a prebuilt runtime bundle.

    This structure is typically loaded from a `manifest.json` stored alongside a
    runtime directory.

    Attributes
    ----------
    runtime_version : str
        brmspy runtime bundle version.
    fingerprint : str
        System fingerprint this runtime was built for.
    r_version : str
        R version string used for the runtime build (for example ``"4.5.0"``).
    cmdstan_version : str
        CmdStan version included in the runtime.
    r_packages : dict[str, str]
        Mapping of R package names to versions.
    manifest_hash : str
        Hash used to validate the runtime contents.
    built_at : str
        Build timestamp.
    """

    runtime_version: str
    fingerprint: str
    r_version: str
    cmdstan_version: str
    r_packages: dict[str, str]  # {package_name: version}
    manifest_hash: str
    built_at: str

Attributes

runtime_version instance-attribute
fingerprint instance-attribute
r_version instance-attribute
cmdstan_version instance-attribute
r_packages instance-attribute
manifest_hash instance-attribute
built_at instance-attribute

Functions

__init__(runtime_version, fingerprint, r_version, cmdstan_version, r_packages, manifest_hash, built_at)

Functions

log_warning(msg, method_name=None)

Log a warning message.

Parameters:

Name Type Description Default
msg str

The warning message to log

required
method_name str

The name of the method/function. If None, will auto-detect from call stack.

None
Source code in brmspy/helpers/log.py
def log_warning(msg: str, method_name: str | None = None):
    """
    Log a warning message.

    Parameters
    ----------
    msg : str
        The warning message to log
    method_name : str, optional
        The name of the method/function. If None, will auto-detect from call stack.

    """
    log(msg, method_name=method_name, level=logging.WARNING)

parse_manifest(path)

Parse manifest.json. Returns None if missing/invalid.

Source code in brmspy/_runtime/_manifest.py
def parse_manifest(path: Path) -> RuntimeManifest | None:
    """Parse manifest.json. Returns None if missing/invalid."""
    if not path.exists():
        return None

    data = None
    try:
        with path.open("r", encoding="utf-8") as f:
            data = json.load(f)

        return RuntimeManifest(
            runtime_version=data.get("runtime_version", ""),
            fingerprint=data.get("fingerprint", ""),
            r_version=data.get("r_version", ""),
            cmdstan_version=data.get("cmdstan_version", ""),
            r_packages=data.get("r_packages", {}),
            manifest_hash=data.get("manifest_hash", ""),
            built_at=data.get("built_at", ""),
        )
    except Exception as e:
        log_warning(f"Failed parsing manifest: {e}")
        log_warning(f"Broken manifest contents: {data}")
        return None

validate_manifest(manifest, expected_fingerprint)

Validate manifest matches expected fingerprint. Raises RuntimeError with details if mismatch.

Source code in brmspy/_runtime/_manifest.py
def validate_manifest(manifest: RuntimeManifest, expected_fingerprint: str) -> None:
    """
    Validate manifest matches expected fingerprint.
    Raises RuntimeError with details if mismatch.
    """
    if manifest.fingerprint != expected_fingerprint:
        raise RuntimeError(
            f"Runtime fingerprint mismatch: "
            f"manifest={manifest.fingerprint}, expected={expected_fingerprint}"
        )

compute_manifest_hash(manifest_dict)

Compute SHA256 of manifest content.

Source code in brmspy/_runtime/_manifest.py
def compute_manifest_hash(manifest_dict: dict) -> str:
    """Compute SHA256 of manifest content."""
    # Create a copy without the hash field itself
    data = {k: v for k, v in manifest_dict.items() if k != "manifest_hash"}

    # Serialize to JSON in a deterministic way
    json_str = json.dumps(data, sort_keys=True, separators=(",", ":"))

    # Compute SHA256
    return hashlib.sha256(json_str.encode("utf-8")).hexdigest()