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,)
- The “.label.“ invariant (both directions).
label(spec)requires.label.inspec.id;source(spec)rejects.label.inspec.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. - The declared-prefix firewall (SOURCE only,,).
source(spec)reads_contributors._FORBIDDEN_LABEL_PREFIXESand rejects a source whose declaredprefixis a forbidden LABEL prefix (e.g.obs_) with aContractErrorNAMING the labels-only firewall — WITHOUT loosening the firewall list. The canonicalweather.obssource registers under the operator-pinnedmet_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_fidelityvalidation applies to BOTH kinds. - 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.
Functions
Section titled “Functions”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"). |
Exceptions
Section titled “Exceptions”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).
default_error_code: str
Section titled “default_error_code: str”Subclass override — the stable string enum surfaced via error_code.
mostlyright.registry.entries()
Section titled “mostlyright.registry.entries()”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.
- Return type:
dict[str,SourceContract]
mostlyright.registry.get(id)
Section titled “mostlyright.registry.get(id)”Look up a registered contract by id WITHOUT importing anything.
- Raises: KeyError – the id is not registered.
- Return type:
SourceContract - Parameters: id (str)
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().
- Raises:
ContractError – nonconforming spec, an id path missing
.label., or a conflicting re-registration. - Return type:
SourceContract - Parameters:
- spec (SourceContract)
- _builtin (bool)
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).
- Return type:
None - Parameters:
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).
- Raises:
EntityNotFoundError – no resolver could resolve
alias. - Return type:
dict[str,Any] - Parameters:
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.
- Raises:
ContractError – nonconforming spec, forbidden label prefix, label-shaped
column, a
.label.id path, or a conflicting re-registration. - Return type:
SourceContract - Parameters:
- spec (SourceContract)
- _builtin (bool)