Registry¶
The registries every {type: Name} of a config is resolved in, Cfg[...] for slots that
hold other components and INJECTED arguments. How to register a class of your own:
Add a component.
grasppanda.registry
¶
Component registries.
Every swappable piece of GraspPanda is a class registered in exactly one flat
:class:Registry. A config node {type: Name, **kwargs} is resolved against the
registry that owns the slot it sits in; the owner is decided by the parent's type
annotation (Cfg[Backbone]), never by searching every registry for a name.
Design notes (see docs/design/ARCHITECTURE.md §6):
- Lookup is lazy: the first
getimports every module below the registry's package, so adding a file is enough to register a component. - Duplicate names raise. A failed lookup lists close matches and says whether the name lives in a different registry.
- Registered classes may not take
**kwargs: every config key must be checkable against a signature before anything is constructed.
RegistryError
¶
Bases: LookupError
A component name could not be resolved or registered.
BuildError
¶
Bases: RuntimeError
A component could not be constructed from its config node.
Cfg
¶
Bases: Generic[T]
Annotation for a component slot.
backbone: Cfg[Backbone] means: either an already built Backbone or a
config node {type: ...} that builds one. The static validator uses the type
argument to find the registry that owns the slot.
Registry
¶
A flat name → component table with lazy auto-import.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Display name, upper case by convention ( |
required |
location
|
str | None
|
Dotted package whose modules are imported on first lookup. |
None
|
provided
|
tuple[str, ...]
|
Constructor arguments the engine supplies itself (for example
|
()
|
injectable
|
tuple[str, ...]
|
Required constructor arguments the engine fills in when a config
leaves them out (for example |
()
|
populate
|
Callable[[Registry], None] | None
|
Callback that fills the registry on first lookup, used to expose
third-party classes such as |
None
|
third_party
property
¶
True when the registry exposes classes this project does not define.
base(cls)
¶
Class decorator declaring the base type of this registry's components.
register(name=None, *, force=False, allow_var_kwargs=False)
¶
Decorator form of :meth:add.
add(obj, name=None, *, force=False, allow_var_kwargs=False)
¶
Register obj under name (default: its __name__).
names()
¶
Sorted names of all registered components.
get(name)
¶
Return the component registered as name or raise :class:RegistryError.
build(cfg, /, **injected)
¶
Construct a component from a config node.
cfg is {type: Name, **kwargs} or an already built object, which is
returned unchanged. injected values fill parameters the node leaves unset;
a node that sets the same parameter to a different value is an error rather
than a silent override.
component_parameters(obj)
¶
Return the keyword parameters of a component and whether it takes **kwargs.
all_registries()
¶
All registries by name.
registry_for(tp)
¶
Return the registry whose base class tp is or derives from.
slot_registry(annotation)
¶
Return the registry named by a Cfg[Base] annotation, else None.