Skip to content

mostlyright.registry

mr.registry — the demoted, author-facing catalog writer (02).

mr.registry.source(spec) / mr.registry.label(spec) add a validated entry to the shipped _contributors._REGISTRY carrying a first-class SOURCE vs LABEL kind axis. The registry is a PLAIN DICT STORE consulted by lookups — it NEVER conjures an import path at runtime (static namespaces, dynamic catalog): a malicious id can never trigger an arbitrary import, and mypy / tree-shaking resolve every symbol statically. The registry only WRITES the discover() catalog index and VALIDATES contracts; the import graph stays static.

Three registration-time invariants, all enforced here (06/07/08,)

  1. The “.label.“ invariant (both directions). label(spec) requires .label. in spec.id; source(spec) rejects .label. in spec.id. This is the actual fix for “can’t tell feature from target at the call site” — feature-vs-target is a machine-checkable write-time property.
  2. The declared-prefix firewall (SOURCE only,,). source(spec) reads _contributors._FORBIDDEN_LABEL_PREFIXES and rejects a source whose declared prefix is a forbidden LABEL prefix (e.g. obs_) with a ContractError NAMING the labels-only firewall — WITHOUT loosening the firewall list. The canonical weather.obs source registers under the operator-pinned met_ prefix; obs_* stays label-only forever. The firewall is kind-scoped: a LABEL legitimately OWNS a label prefix (cli_) + label columns — validating a label through the source firewall would reject its own flagship, so the declared-prefix + label-column firewall guards SOURCES only. The bitemporal-field + point_in_time_fidelity validation applies to BOTH kinds.
  3. Idempotent, conflict-checked writes. Registering the same id with an identical spec is a no-op; the same id with a different spec raises (mirrors core.validator.register_schema).

CWOP is NEVER registered here, and the four parity-firewall files stay untouched.

entries()Return an isolated shallow copy of the catalog (id → SourceContract).
get(id)Look up a registered contract by id WITHOUT importing anything.
label(spec, *[, _builtin])Register a settlement LABEL (kind="label").
register_alias_resolver(domain, resolver)Register a per-domain entity alias resolver (last write wins per domain).
resolve_entity(alias, *[, domain])Resolve an entity alias (e.g. "nyc" → KNYC/KLGA) via domain resolvers.
source(spec, *[, _builtin])Register a FEATURE source (kind="source").
EntityNotFoundError(alias, suggestion, *[, …])An entity alias could not be resolved by any registered resolver (R-07).

exception mostlyright.registry.EntityNotFoundError(alias, suggestion, , request_id=None, error_code=None)

Section titled “exception mostlyright.registry.EntityNotFoundError(alias, suggestion, , request_id=None, error_code=None)”

Bases: NoDataError

An entity alias could not be resolved by any registered resolver (R-07).

Carries a DETERMINISTIC nearest-match suggestion computed by pure edit-distance / prefix match over the static registry id set + the resolver vocabularies — NO fuzzy-match / vector-similarity / network dependency (threat). An identical alias always yields an identical suggestion (scriptable).

  • Parameters:
    • alias (str)
    • suggestion (str)
    • request_id (str | None)
    • error_code (str)
  • Return type: None

Subclass override — the stable string enum surfaced via error_code.

Return an isolated shallow copy of the catalog (id → SourceContract).

Mutating the returned dict cannot corrupt the backing store — the copy IS the isolation. No import is triggered by this lookup.

Look up a registered contract by id WITHOUT importing anything.

mostlyright.registry.label(spec, , _builtin=False)

Section titled “mostlyright.registry.label(spec, , _builtin=False)”

Register a settlement LABEL (kind="label").

Validates the bitemporal field list + point_in_time_fidelity + prefix, and REQUIRES a .label. id path. The declared-prefix + label-column firewall is NOT applied (a label legitimately owns a label prefix + label columns — that IS a target frame). Returns the registered spec. _builtin=True is for first-party import-time registration only — see source().

mostlyright.registry.register_alias_resolver(domain, resolver)

Section titled “mostlyright.registry.register_alias_resolver(domain, resolver)”

Register a per-domain entity alias resolver (last write wins per domain).

mostlyright.registry.resolve_entity(alias, , domain=None)

Section titled “mostlyright.registry.resolve_entity(alias, , domain=None)”

Resolve an entity alias (e.g. "nyc" → KNYC/KLGA) via domain resolvers.

Routes through each registered resolver (or only domain’s resolver when given), returning the first {"domain", "entities", "note"} result. The cross-venue settlement-station warning is preserved in the note (threat ). On an UNRESOLVABLE alias, raises EntityNotFoundError carrying a deterministic nearest-match suggestion (R-07, no fuzzy dep).

mostlyright.registry.source(spec, , _builtin=False)

Section titled “mostlyright.registry.source(spec, , _builtin=False)”

Register a FEATURE source (kind="source").

Validates the bitemporal field list + point_in_time_fidelity + prefix, applies the SOURCE-only declared-prefix + label-column firewall (R-09), and rejects a .label. id path. Returns the registered spec. _builtin=True is for first-party import-time registration only: it skips the one-shot experimental warning so a fresh install’s first import stays silent and the latch stays armed for a genuine user registration.