an.library.ids#
Asset ids, version labels and library references — the library’s persisted names.
Three grammars, each a persisted identifier (ADR 0005 decisions 3 and 4, plan §1 decision 7), so each is checked here once and never re-parsed by hand elsewhere:
an asset id is
<kind>.<slug>— flat, readable, filename-safe (character.alice-reiniger). The kind prefix keeps two kinds from colliding on one slug and makesfind(kind=…)cheap;a version label is
v001,v002, … — the studio convention, for people. The version’smanifest_sha256is its identity for machines;a library reference is
[<namespace>:]<asset_id>[@<version>], where<version>is a label,latest(floating; resolved once at check-out and pinned) orsha256:<prefix>(exact content). The namespace names the library an id resolves in when several are federated (cutan:character.alice@v003).
Because these strings become file names (records/<asset_id>.json,
versions/<asset_id>/<vNNN>.json), the grammars are also the path-traversal
guard: nothing that parses here can contain /, .. or a drive letter.
>>> ref = parse_ref("cutan:character.alice-reiniger@v003")
>>> (ref.namespace, ref.asset_id, ref.version, ref.kind)
('cutan', 'character.alice-reiniger', 'v003', 'character')
>>> str(ref)
'cutan:character.alice-reiniger@v003'
>>> version_label(12)
'v012'
Module Attributes
the record's head, resolved once and then pinned. |
|
The prefix of a content-addressed version selector ( |
Functions
|
The kind an asset id declares by its prefix. |
|
Return |
|
Return |
|
Return |
|
Parse a library reference. |
|
The label of the |
|
The number of a version label. |
Classes
|
A parsed |
Exceptions
An asset id, version label or library reference that does not parse. |
- exception an.library.ids.AssetIdError[source]#
Bases:
ValueErrorAn asset id, version label or library reference that does not parse.
- an.library.ids.LATEST: str = 'latest'#
the record’s head, resolved once and then pinned.
- Type:
The floating version
- class an.library.ids.LibraryRef(asset_id, version=None, namespace=None)[source]#
Bases:
objectA parsed
[<namespace>:]<asset_id>[@<version>].versionisNonewhen the reference gave none (read aslatestby readers; refused where a pin is required, e.g.AssetRef.library).- with_namespace(namespace)[source]#
The same asset and version, qualified by another library name.
- Return type:
- an.library.ids.SHA256_PREFIX: str = 'sha256:'#
The prefix of a content-addressed version selector (
sha256:<hex prefix>).
- an.library.ids.asset_kind(asset_id)[source]#
The kind an asset id declares by its prefix.
- Return type:
>>> asset_kind("environment.palace-hall") 'environment'
- an.library.ids.check_asset_id(asset_id)[source]#
Return
asset_idif it is<kind>.<slug>, else raiseAssetIdError.- Return type:
>>> check_asset_id("prop.teacup-victorian") 'prop.teacup-victorian' >>> check_asset_id("Alice") Traceback (most recent call last): AssetIdError: ...
- an.library.ids.check_namespace(name)[source]#
Return
nameif it can name a library (a package name), else raise.- Return type:
- an.library.ids.check_version_label(label)[source]#
Return
labelif it isvNNN, else raiseAssetIdError.- Return type:
- an.library.ids.parse_ref(text, *, require_version=False, require_pin=False)[source]#
Parse a library reference.
require_version=Truerefuses a reference with no@<version>;require_pin=Truealso refuses@latest— the grammar ofAssetRef.library, where a floating reference would make a render depend on whatever the library’s head is that day.- Return type:
>>> parse_ref("character.alice") LibraryRef(asset_id='character.alice', version=None, namespace=None) >>> parse_ref("character.alice@sha256:0a1b2c3d").version 'sha256:0a1b2c3d' >>> parse_ref("character.alice", require_version=True) Traceback (most recent call last): AssetIdError: ...