imbed.components.components_util#
Utils for components
Functions
|
Add a 'default' key to a registry pointing to a specified component. |
|
Get the store for a specific component type |
|
Get the standard components for the project. |
Classes
|
A dict-based registry with decorator support for registration. |
- class imbed.components.components_util.ComponentRegistry(name, *, factory=None)[source]#
Bases:
dictA dict-based registry with decorator support for registration.
This registry provides:
Decorator-based registration with @registry.register()
Custom key support with @registry.register(‘custom_key’)
Direct registration via registry.register_item(key, item)
Optional factory functions to wrap registered items
Full dict compatibility for backward compatibility
Examples
>>> registry = ComponentRegistry('my_components') >>> @registry.register() ... def my_function(x): ... return x * 2 >>> registry['my_function'](5) 10 >>> @registry.register('custom_name') ... def another_function(x): ... return x + 1 >>> registry['custom_name'](5) 6
- register(key=None, **config)[source]#
Decorator to register a component.
- Parameters:
key (
str) – Registration key (defaults to function/class name)**config – Additional configuration passed to factory if present
- Return type:
Callable[[T],T]- Returns:
Decorator function that registers and returns the component
Examples
>>> registry = ComponentRegistry('test') >>> @registry.register() ... def my_func(): ... return 42 >>> registry['my_func']() 42 >>> @registry.register('custom') ... def other_func(): ... return 99 >>> registry['custom']() 99
- imbed.components.components_util.add_default_key(d, default_key, enviornment_var=None)[source]#
Add a ‘default’ key to a registry pointing to a specified component.
- Parameters:
d (
dict) – The registry dict to add default todefault_key – Either a string key or a callable (uses __name__ as key)
enviornment_var – Optional environment variable to override default_key
- Returns:
The modified dict
- Raises:
ValueError – If the default_key is not found in the registry