registry¶
Generic named registry for pluggable components.
Every otto extension seam (term/transfer backends, host classes, lab
repositories, CLI commands, …) stores its entries in a Registry:
one storage idiom, uniform fail-loud errors with did-you-mean suggestions,
and per-entry origin attribution. Domain modules keep their public
register_*/build_* wrapper functions; this class is the shared engine
behind them.
>>> r: Registry[str] = Registry("demo backend", register_hint="register_demo()")
>>> r.register("json", "the-json-backend", origin="example")
>>> r.get("json")
'the-json-backend'
>>> r.names()
['json']
-
otto.registry.caller_module(depth: int =
1) str¶ Return the
__name__of the module depth call frames above the caller.
-
class otto.registry.Registry(kind: str, *, register_hint: str, collision_hint: str | None =
None)¶ -
Named registry of pluggable components; fail-loud lookups with suggestions.
-
register(name: str, obj: T, *, overwrite: bool =
False, origin: str | None =None) None¶ Register obj under name; duplicates are loud unless overwrite.
origin attributes the entry (defaults to the caller’s module); it is used in collision and listing messages.
- Raises:¶
ValueError – If name is already registered and overwrite is false; the message names both registering modules and ends with this registry’s collision hint.
- get(name: str) T¶
Return the entry registered under name.
- Raises:¶
ValueError – If name is unknown; the message lists registered names, adds a did-you-mean suggestion, and points at the registration function.
- unregister(name: str) None¶
Remove the entry registered under name.
- Raises:¶
ValueError – If name is unknown (same rich error as
get()).
-
register(name: str, obj: T, *, overwrite: bool =