Loom ID registry¶
See also: Keys and content gates (what an entry is
keyed by), SBOM fragments (how fragments merge),
Configuration (id-registry, update-id-registry) and
GitHub Action (the id-registry and
update-id-registry inputs).
Fragments come from independent runs, so the same dataset or model would
normally get a different spdxId in each, leaving the merged SBOM as
disconnected islands. A Loom ID registry pins ids so every run, on every
surface, agrees.
Declare a registry¶
A registry is used only when declared. Nothing is searched for or
auto-discovered on any surface: every CLI subcommand, the Hatchling build
hook, the library API (including loom.Run) and the GitHub Action.
[tool.pitloom]
id-registry = "loom-id-registry.json"
Precedence: --id-registry FILE (id_registry= in the API, id-registry
input in the Action), then the applicable config's id-registry key (the
project's own [tool.pitloom], or a --config file), then no registry,
silently. A relative --id-registry resolves against the current directory
on every command.
A declared registry that is missing, unreadable or invalid is fatal: the CLI
prints one ERROR: line and exits 1; the library API and loom.Run raise
FileNotFoundError (missing, or not a file) or ValueError; the Hatchling hook logs one ERROR: and fails the build.
Create a registry¶
loom id generate data src --entity model -o loom-id-registry.json # pin ids before a run
loom id import existing-sbom.spdx3.json -o loom-id-registry.json # or reuse ids from an SBOM
loom project # uses the declared registry
id generate [PATH...] takes -o/--id-registry FILE (registry to create or
update), --project-dir DIR and repeatable -e/--entity NAME[:TYPE] (an
explicit entity id ahead of a run; TYPE defaults to ai_AIPackage). A
file, model or dataset NAME that exists below the project root is stored
under its path key with its content hash, other names by name, each with an
INFO: (-e rules).
--max-dataset-hash-bytes BYTES (an integer of at least 1; 0 is a usage
error) caps the bytes read to hash one dataset, else the project's own
max-dataset-hash-bytes, else 4 GiB.
--entity NAME@VERSION:software_Package pins one release of a dependency, or
of the project's own package (a NAME with no @VERSION holds only a package
that states no version; see Package keys).
The string splits on its last colon: the suffix is a TYPE only
when it is a known registry type (software_File, software_Package,
ai_AIPackage, dataset_DatasetPackage). A suffix shaped like a type name
(prefix_ClassName) or a known type in another case is a usage error (exit
2), not part of NAME. Anything else is part of NAME, so a URL or a
Windows drive path works, as in
-e https://huggingface.co/datasets/imdb:dataset_DatasetPackage. A trailing
:, a TYPE with white space around it, a control character (a newline), a
blank NAME or a package NAME that is not a PEP 508 name (foo==1.0:
write foo@1.0) is a usage error too.
--namespace IRI sets a new registry's namespace, the one its own ids are
minted in (Namespaces) (an absolute IRI without #, and without user information, a secret query
value such as token or an access token, or a query nested or encoded too
deeply to read, also in a URL anywhere in it
(urn:x:https://user:pw@host/ns): any user name is refused,
ssh://git@... too; a
code, session, ticket, sid or otp parameter is accepted as
written; default: the project directory's name and a random UUID4); an
existing registry with another namespace is one ERROR:, exit 1. The
library's IdRegistry(namespace=...) and IdRegistry.new(namespace=...)
refuse such a namespace with a ValueError, coded
credentials-unsafe/registry for a credential. A
registry whose namespace is not a valid namespace IRI (one holding a
credential included), or whose spdxId is not a non-empty string, does not
load. One with an entry whose key or spdxId holds a credential loads
with a WARNING: per entry by default, and in the refuse mode
(url-credentials = "refuse", --refuse-url-credentials) does not load: it
is refused, left as it is. Either way you remove the entry (see
Credentials in a key). id import into an empty
registry adopts the SBOM document's namespace only when it is a valid
namespace IRI; otherwise one
WARNING: FILE=<sbom>: SBOM namespace <why>; the ID registry keeps its
own, not <namespace> [sbom-invalid]. It keeps the namespace it adopted
unless another run changed the file's namespace meanwhile.
id import SBOM_FILE takes -o/--id-registry FILE and --project-dir DIR.
A new registry stores its project root (--project-dir, default the current
directory, for both commands) relative to its own directory; an existing one
keeps it, and generate, or import with an explicit --project-dir, naming
another root is one ERROR:, exit 1.
The registry also keeps, per id prefix, the highest number it has issued or
read in its namespace (id_counters), so an id that has left the registry
(a harvest replaced its entry) is never minted again for another file. An id
handed over by an SBOM, a harvest or id import reserves numbers only up to
10**9, and one whose prefix is not a valid IRI segment (it holds /, ?, a
space, # or a lowercase %xx) reserves nothing. A document also skips
every id the registry holds for a file, package, AI package or dataset package
when it mints one, so a new id never equals a held one; a model card's dataset
keeps the id held under its own name. A file whose version is not an
integer (3.0) or that repeats a JSON object key (duplicate key 'X') does
not load. For a symlinked registry, project_root is relative to
the symlink target's directory.
generate records each AI model file's SHA-256 with its entry, so a
retrained file (other bytes) gets a new id on every surface. A registry from an
earlier release (format version 3 or 2) is rejected, on every command, with one
ERROR: and nothing written; delete it and re-run loom id generate or loom
id import (what changed).
Target file. -o/--id-registry if given, else the config's
id-registry key (both commands: read from --project-dir, default the
current directory; pyproject.toml's [tool.pitloom] or setup.cfg's
[tool:pitloom]). The location is required, never assumed: with neither,
both commands print ERROR: loom id <command>: no ID registry declared: pass --id-registry FILE
or set id-registry in [tool.pitloom] ([tool:pitloom] for setup.cfg),
exit 1 and write nothing. loom-id-registry.json is only the suggested name.
A broken pyproject.toml/setup.cfg is one ERROR: line, never a
traceback, and takes precedence over that error.
- A missing target is created. An existing target that cannot be loaded (not
JSON, wrong version, a version 3 or 2 file, a key the format does not have:
ID registry: FILE=<path>: unknown top-level key(s): 'files' [registry-unknown-key]) is oneERROR:and exit 1, never silently replaced. A registry file that cannot record its project root (on Windows, a file on another drive than the project) is not saved:ID registry: FILE=<path>: project root '<root>' has no path relative to the file's directory; <reason> [registry-unusable](ERROR:forloom id,WARNING:where the SBOM is already built; the library raises it coded). A registry file inside the project always works. - A registry file is read whole, up to the fixed 50 MiB cap for a JSON
document: a larger one is not read (
FILE=<path>: larger than the <limit>-byte JSON-document cap for the ID registry; not read [over-cap], exit 1). Only a regular file is read: a FIFO or a device there isinput-not-found(is not a file), opened without waiting for a writer. - Registry keys, and the default
PATHs (src,data,models), stay relative to--project-dir; a relative-oorPATHresolves against the current directory. --project-dirmust be an existing directory, elseERROR: loom id <command>: project directory not found: '<p>' [input-not-found](a file there addsis not a directory; exit 1). EachPATHmust exist, elseERROR: loom id generate: PATH not found: '<p>' [input-not-found](exit 1, nothing written), and must resolve inside--project-dir, elseERROR: loom id generate: PATH '<p>' is outside --project-dir '<dir>' [option-invalid](exit 1), whether directly or only through a symlink. Both name thePATHas typed...is collapsed lexically before any symlink is followed (link/..is the directory abovelinkas written). A symlink that itself lives inside the project is fine even if it points outside: it is indexed under its in-project location, as the defaultPATHs are, and aPATHnaming a symlinked directory (data/models -> ../bigdisk/models) is walked. A symlink to a directory found below aPATHis not followed. Aloom.Runthat names a file below a symlinked directory keys it by its path as written, so it finds no entry.- A file or directory below a
PATHthat cannot be read or listed gets the sharedWARNING: FILE=<path>: ...orWARNING: DIR=<path>: ...line (the path project-relative,/-separated) and the run continues; a partial tree is never indexed silently. A file whose name a registry cannot hold (not UTF-8 encodable) getsWARNING: ID registry: PATH '<path>': name cannot be encoded as UTF-8 (lone surrogate); not indexed [text-malformed/registry]. APATHargument itself that cannot be read or listed is anERROR:(exit 1, nothing written) on every Python version, naming it as typed:FILE=<path>: could not read for ID registry indexing; <reason> [file-unreadable],DIR=<path>: could not list for ID registry indexing; <reason> [dir-unlistable], or, when its directory cannot be searched,FILE=<path>: could not read for the input check; <reason>. An unreadable default directory (src,data,models) is theDIR=warning instead, and a missing one is left out. - Build, virtual-environment, VCS and cache directories are not indexed; see
Directories that are skipped. A
PATHthat is, or lies below, one of them indexes nothing and gets oneWARNING:. -o -is a usage error (exit 2): a registry is never written to stdout.- After a write that created the registry (never one that updated an
existing file), and unless the target is already the project's declared
id-registry, both commands logINFO: ID registry: to use this registry, add to [tool.pitloom] in pyproject.toml: id-registry = "<path>". If the table declares a differentid-registry, the line readschange id-registry in [tool.pitloom] ... to:instead (replace the key; a repeated key is invalid TOML). Forsetup.cfgit names[tool:pitloom] in setup.cfgand the path is unquoted, as INI values are not unquoted on read. Paste theid-registry = ...part verbatim.
What a registry pins¶
Given the same registry, a file, dependency package, the project's own
package (project, wheel, embed-wheel, the Hatchling hook) or an AI model
carries the same id everywhere. A package is keyed by its name and version, so
each release has its own id. env reuses a dependency's id only. A file, a
model that has a file and a dataset package that exists below the root are
keyed by their path from the registry's project root, everything else by name;
a file's or model's entry holds its SHA-256, so changed content gets a new id;
one model file is one id on every surface. A directory is the exception: it is
keyed by its distribution path (demo, not src/demo) and id generate does
not index it. Details: Keys and content gates.
Exceptions:
- A wheel whose name did not come from its
METADATA(calledunknown) is neither looked up nor recorded; its package gets a per-document id, with oneINFO:when a registry is declared. Its ids depend on its file name, so a renamed copy gets new ids: see Wheel SBOMs. - A
src/- orlib/-layout project's files are found bywheeland sdist targets through a layout alias; other layouts get their own ids from a wheel-only run. With the registry's root above the project,wheel,project <sdist>andembed-wheelneed--project-dirto find it: see Monorepo. - A
loom.Rundataset package whose path exists below the registry's root is keyed by that path, whatever way the script spells it (../data/t.txtfrom a subdirectory isdata/t.txt); a remote, missing or outside-the-root dataset by its name. A dataset that is one file also gets asoftware_Fileunder the same path key. Datasets found at build time andenv's root package are not looked up, so a registry entry does not pin them. - Regeneration is stable: an unchanged file keeps its id; changed content gets a fresh one (different bytes are different provenance). That holds for an AI model on every surface: the model's file is its key and its SHA-256 gates the lookup, so a retrained file is a new id. Two model files with one stem are two models with two ids. A dataset pin with no recorded SHA-256 hits any content: see Content gates.
- A registry inside the project tree is left out of the SBOM's file set
(and of a wheel's Merkle root), with one
WARNING: ID registry: FILE=<path>: inside the project's file set; left out of it [registry-conflict/file-set]per run when the file set actually contains it;id generatedoes not index it either. With--allow-build, the copy found in the build-and-read extraction is left out too (recognised as a file the build extracted, whereverTMPDIRis, with an equal SHA-256). The copy a built wheel or sdist carries is left out bywheel,embed-wheelandproject <sdist>, whatever its bytes. A wheel member is the copy only when its path equals the registry's path below the project, or that path less exactly one leading part (asrc/layout), with a directory and the file left; of several such members only the longest is left out, and a file with a shorter tail (reg.json,data/reg.json) is kept. An sdist member must match the whole path belowname-version/. The path is taken below--project-dir; without one (wheel,embed-wheel,project <sdist>) below the nearest directory that holds the registry and apyproject.toml,setup.cfgorsetup.py, no higher than the project root the registry stores, else below that root. Keep the registry outside the package directory (the project root is fine). - Two versions of a dependency in one document (behind different markers)
are two keys, each pinned and recorded on its own. A key held by two
elements of one document that both read the registry (two bundled
libraries of one name and version) cannot be pinned automatically: runs do
not record it, and a pinned id goes to the first of them, with a
WARNING:.loom id importskips every key held by several elements, with oneINFO: ID registry: not imported (name held by several elements): <type> '<key>', ... [registry-key-ambiguous]line. - A
projectrun of a project with a dynamic version statesunknownand so keys its own package by name alone; a wheel or hook run of it states the version: the two give that package two ids. - A self-referencing extra, or a bundled library named like the project or a dependency, never reads the registry and silently gets its own id; runs still record the name for the project or dependency.
Directories that are skipped¶
id generate (below the project root) and a loom.Run dataset directory
(below the dataset's own directory) skip any directory named .git,
__pycache__, .mypy_cache, .pytest_cache, .pyrefly_cache,
.ruff_cache, .venv, venv, node_modules, dist, build, .tox,
.hatch or fragments, and everything below it. Only the names of
directories below the root count: a project that itself lives under a
directory called build is indexed. A dataset directory also leaves out
symbolic links to directories and the declared registry file. id generate
also leaves out the declared registry, matched by identity and never by name:
a stray loom-id-registry.json that is not the declared file is indexed. The
set is IGNORED_DIR_NAMES in src/pitloom/core/walk_rules.py.
Namespaces¶
An spdxId is an opaque IRI; the SBOM is valid whatever namespaces its ids
use. With a registry, one SBOM can hold ids of several, because an id is
pinned as it was first minted:
- The registry's namespace is the one
id generate,-eandloomregister ids in. It is a random UUID4 stored in the file when the registry is created, the SBOM document's id afterid importinto an empty registry, or--namespace IRI. It never changes for the registry. - The document's namespace,
https://spdx.org/spdxdocs/<name>-<uuid>, is the one a build mints every other id in: theSpdxDocumentand itssoftware_Sbom, relationships, annotations, and an element the registry does not hold yet. Its<uuid>is derived from the project's content (name, version, dependencies, lock pins, file set), so it changes with it. Harvesting then pins those ids, as minted, so after a release one SBOM can hold the registry's namespace and the namespaces of earlier documents.
The registry's namespace is random, not content-derived, because it must
outlive every release (a content-derived one would move with each) and be
unique per registry (a name-derived one would be shared by two projects of the
same name). It is a registry input, so the same registry gives the same SBOM.
For a namespace you choose, pass --namespace (a URL you own). It governs only
the ids the registry mints, not the document's namespace.
Harvesting new ids¶
loom project/wheel/env/generate also write newly minted ids back into
a declared registry after each run (--update-id-registry, on by default;
--no-update-id-registry to stop; never creates a registry). Running loom
project, then loom wheel --id-registry loom-id-registry.json and loom env
--id-registry loom-id-registry.json, keeps the same spdxIds with no manual
id generate/import between them. A name held by several elements of one
document is not written.
A harvest records a SHA-256 only for software_File and ai_AIPackage
entries (the two content-gated types) and never erases one already recorded:
an element with no hash and another id leaves such an entry as is, with one
INFO: ID registry: content gate kept for '<type>' <key>: harvested id <id>
not recorded over <id>. loom id import is the exception: there the
imported id wins and the hash goes, with one INFO: ID registry: content gate
dropped for '<type>' <key>: imported id <id> replaces <id> per entry, so
importing an older SBOM of a model gives it that SBOM's id back.
dataset_DatasetPackage elements are the exception: a dataset id is pinned
deliberately (-e NAME:dataset_DatasetPackage or id import), never from a
run's fallback id. A model is harvested under its file's key with its SHA-256,
so its entry only matches the same bytes. A harvest writes each element under
the key its lookup used, not its name, and an element with no recorded key (a
merged loom fragment, an id import) never moves an id held under another key
of the same type, and a fragment's stale element (an older SHA-256) never rolls
a newer entry back: see Merged fragments and
harvest.
loom.Run writes one kind of entry itself: a model declared with path=
whose file the registry does not know, saved after the fragment when the
run ends without an exception (update-id-registry = false in
pitloom_config stops it). A training and an evaluation script declaring
the same model and file share its id; a retrained file gets a new one.
Registry writes go through one routine: it re-reads the file, re-applies only
the run's own changes and replaces the file atomically, so runs sharing a
registry keep each other's entries. id generate, id import, a harvest and
loom.Run all use it, and an unchanged file is not rewritten. A writable
registry in a read-only directory is written in place, which is not atomic. A
loom.Run given an IdRegistry object that was never loaded, for a file that
exists, merges into that file and never overwrites it. There is no lock.
A read-only registry file is never overwritten, on any platform. A failed save
logs one WARNING:, what stopped it with its code: a write the system refused
is WARNING: FILE=<path>: could not write for the ID registry; <reason>
[file-unwritable] (the registry as given, never a temporary file), a file
that no longer loads says its own line. The run's SBOM is built before the
save and still written. The registry is written through a temporary file, so
a failure leaves it as it was; where the directory refuses a temporary file it
is written in place, and a full disk can leave it part-written. loom
id generate and loom id import print the same line as their one ERROR:
and exit 1. A library IdRegistry with no file logs WARNING: ID registry: no
file to save to; the ids this run added are not saved
[registry-file-missing].
Two loom.Run blocks that exit at the very same moment against one registry
can each write the same id for a different model into their fragments: the
registry keeps one key per id, and the run that saves second logs another run
saved ... first, but its fragment is already written. Run scripts that share
a registry one after another, not at once.
From Python¶
The id_registry= argument (a path, or an already-loaded IdRegistry) is the
library equivalent of --id-registry, taken by the generator functions,
embed_wheel_sbom(), enrich_model() and loom.run. Precedence:
id_registry= wins over the applicable config's id-registry key, which
wins over no registry at all (silently). A relative id_registry= path
resolves against the project directory for a project directory target
(and embed_wheel_sbom(project_dir=...), and enrich_model(project_target=dir)
-- the project the enrichment fragment will merge into), and against the
current directory for any other target, an sdist included. The CLI makes
--id-registry absolute against the current directory first, so there
it always means the file under the current directory. A declared
registry file that's missing (or not a file) raises FileNotFoundError
(ID registry file not found: '<path>', adding is not a file when
something else is there, a FIFO or device included, code input-not-found),
naming the path as given -- the flag or argument
as typed, the configured id-registry value as written -- never the
resolved absolute path; one that's unreadable or invalid raises
ValueError carrying its code (registry-malformed, registry-wrong-format,
registry-unknown-key, json-malformed, file-unreadable: ID registry:
FILE=<path>: <reason> or FILE=<path>: not valid JSON for the ID registry;
<reason>), naming the path as given too. See
ID registry message codes.
Neither is silently skipped or replaced. loom.run reads no [tool.pitloom] unless given one
as pitloom_config=; its own id_registry= resolves against the current
directory, a pitloom_config= file's id-registry against that file's
directory.
IdRegistry.load() takes a str or path-like (else TypeError). register()
and the loader reject a name that UTF-8 cannot hold (a lone surrogate) with
ValueError (text-malformed/registry, registry-malformed); generate()
skips such a file with the PATH WARNING:, and harvest and id import
skip such an element with a WARNING: (both text-malformed/registry).
register() stores a key holding user information, a secret query value
or an access token, or a query nested or encoded too deeply to read (a PURL
qualifier and a dotless scp-style address included) with a WARNING:, and
raises ValueError for it in the refuse mode (refuse_credentials=True on
IdRegistry.load(), IdRegistry.new() or the constructor); harvest and id
import skip an element whose key or spdxId holds one, with a WARNING:, in
either mode; IdRegistry.load() and IdRegistry.rebase() load a file that
holds such an entry with a WARNING:, and in the refuse mode raise
ValueError and leave it as it is (all credentials-unsafe/registry; see
Credentials in a key).
generate() raises FileNotFoundError (PATH not found: '<path>'
[input-not-found]) for a path that is not there, and ValueError (ID
registry: PATH '<path>' is not inside the project root '<root>'
[option-invalid]) for
a path outside the root; a symlink inside the project that points outside is keyed
by its project path. id import of an SBOM whose @graph is not a list is
ERROR: loom id import: FILE=<path>: SBOM @graph is not a list [sbom-invalid],
as embed-wheel --sbom refuses it; one the SPDX 3 reader refuses (an object
with no type) is ERROR: loom id import: FILE=<path>: SBOM cannot be read as
SPDX 3; <reason> [sbom-invalid].
In CI¶
A registry is used only when declared: via the Action's id-registry input, or
via [tool.pitloom] id-registry in the project's own config. Nothing is
auto-discovered. Once declared, loom project/wheel/env/generate (and
the Action, which wraps them) harvest newly-minted ids back into it by
default -- see update-id-registry in Configuration.
That write only ever touches the runner's local checkout; it never needs
elevated permissions itself (that's a git push, which Pitloom never does).
But the write is ephemeral unless a workflow step commits it back, so a
release/publish job that intentionally runs with permissions: contents: read
(common for trusted PyPI publishing -- see this repo's own
pypi-publish.yml)
can update loom-id-registry.json locally but shouldn't have its permissions
relaxed just to push that one file.
Instead, run registry maintenance in a separate, appropriately-scoped
workflow -- the same shape this repo already uses to commit a generated
CITATION.cff back to the repo
(codemeta2cff.yml).
A declared id-registry that does not exist yet is an ERROR:, not
silently skipped, so the registry file must exist before the build step
below runs. Either commit one made by loom id generate (recommended, so
every build reads the same committed file) or keep the seed step in the
snippet below (it also creates the file on its first run, so the very first
workflow run still succeeds).
A committed registry from an earlier Pitloom release (format version 3 or 2)
is an ERROR:: regenerate it with loom id generate or loom id import and
commit the result. A registry in format version 4, which that command
writes, can be read only by Pitloom 0.22.0 or later (0.21.x reads version 3,
0.20.2 and earlier version 2), so the snippet below pins 0.22.0 for both the
CLI and the action.
name: Update Loom ID registry
on:
push:
branches: [main]
paths:
- "src/**"
- "data/**"
- "models/**"
permissions: read-all
concurrency:
group: update-loom-id-registry-${{ github.ref }}
cancel-in-progress: false
jobs:
update-id-registry:
runs-on: ubuntu-latest
permissions:
contents: write # EndBug/add-and-commit needs write to push loom-id-registry.json
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: "3.x"
# Same release as the action below, which installs its own pinned version.
# 0.22.0 is the first release with registry format 4.
- run: pip install pitloom==0.22.0
# Extras-free: keys each model by its file path, with the file's
# SHA-256, whether or not "ai" extras are installed. Creates
# loom-id-registry.json on first run. Only omit this step if a
# loom-id-registry.json is already committed to the repo -- a
# declared-but-missing registry fails the step below.
- name: Seed/refresh AI model registry entries
run: loom id generate --id-registry loom-id-registry.json
# Pin the first release with registry format 4 (v0.21.x reads version 3).
- uses: bact/pitloom@v0.22.0
with:
project-path: .
# Required: nothing auto-discovers a registry -- declare it.
# Must already exist by this point (the seed step above
# creates it on first run) -- a declared-but-missing registry
# is an ERROR:, not silently skipped.
id-registry: loom-id-registry.json
# Optional: richer ai_AIPackage metadata (architecture,
# hyperparameters, etc.) -- NOT what keeps spdxIds stable, that's
# the step above. Omit if there are no AI models, or if sparse
# metadata is acceptable.
extras: "ai"
- name: Commit and push updated loom-id-registry.json
uses: EndBug/add-and-commit@v11.0.0
with:
message: "Update loom-id-registry.json"
add: "loom-id-registry.json"
Two things worth calling out about that snippet:
- AI model id stability doesn't come from
extras: "ai". A model's registry key is its file's path, with the file's SHA-256 as the gate, on every surface:loom id generateand a run agree whether or not the extras are installed.extras: "ai"only affects metadata richness (architecture, hyperparameters, etc.), not which spdxId a model gets. - Race conditions: this workflow never competes with the publish
workflow to push (the publish job doesn't commit, per the guidance
above). It can race with itself, though -- two pushes to
mainclose together could trigger two concurrent runs both trying to commit and push. Theconcurrency:group above queues same-branch runs instead of racing them. One sequencing caveat remains, shared by any generated-and-committed file (this repo's ownCITATION.cffincluded): cutting a release at the exact moment a registry-update commit is in flight could still pick up a slightly-staleloom-id-registry.json.