Skip to content

objects

objects #

A typed value as an object tree and back: a composite is its own tree, a scalar is wrapped.

OBJECT_LEAF = 'value' module-attribute #

The entry a scalar is stored under, so every object is a directory tree.

load_object(base, cgtype) #

The value whose object tree is rooted at base (the inverse of store_object).

Source code in capturegraph-lib/capturegraph/recipes/values/objects.py
def load_object(base: Path, cgtype: type[CGType]) -> object:
    """The value whose object tree is rooted at ``base`` (the inverse of ``store_object``)."""
    return cgtype.load(base / OBJECT_LEAF if issubclass(cgtype, Scalar) else base)

store_object(base, value, cgtype) #

Store value as the object tree rooted at base and return that root.

Source code in capturegraph-lib/capturegraph/recipes/values/objects.py
def store_object(base: Path, value: object, cgtype: type[CGType]) -> Path:
    """Store ``value`` as the object tree rooted at ``base`` and return that root."""
    if issubclass(cgtype, Scalar):
        base.mkdir(parents=True, exist_ok=True)
        cgtype.store(base / OBJECT_LEAF, value)
    else:
        cgtype.store(base, value)
    return base