We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need shared foundation for component registries to avoid code duplication.
src/stimulus/core/registry.py
BaseRegistry
Required for all component registries. Example usage:
class ComponentRegistry(BaseRegistry[AbstractComponent]):
The text was updated successfully, but these errors were encountered:
could be something like this :
"""Central registry system for Stimulus components.""" from importlib.metadata import entry_points from typing import Type, Dict, TypeVar, Generic T = TypeVar('T') class BaseRegistry(Generic[T]): """Base registry class for component registration.""" def __init__(self, entry_point_group: str, base_class: Type[T]): self._components: Dict[str, Type[T]] = {} self.entry_point_group = entry_point_group self.base_class = base_class self.load_builtins() self.load_plugins() def register(self, name: str) -> callable: """Decorator factory for component registration.""" def decorator(cls: Type[T]): if not issubclass(cls, self.base_class): raise TypeError(f"{cls.__name__} must subclass {self.base_class.__name__}") self._components[name] = cls return cls return decorator def load_builtins(self): """Override in child classes to register built-in components""" pass def load_plugins(self): """Load external components from entry points""" for ep in entry_points().select(group=self.entry_point_group): self._components[ep.name] = ep.load() def get(self, name: str, **params) -> T: """Instantiate a component with parameters""" cls = self._components.get(name) if not cls: available = ", ".join(self._components.keys()) raise ValueError(f"Unknown {self.base_class.__name__} '{name}'. Available: {available}") return cls(**params) @property def component_names(self): return list(self._components.keys())
Sorry, something went wrong.
No branches or pull requests
Is your change request related to a problem? Please describe.
Need shared foundation for component registries to avoid code duplication.
Describe the solution you'd like
src/stimulus/core/registry.py
with:BaseRegistry
class handling entry points/decoratorsDescribe alternatives you've considered
Additional context
Required for all component registries. Example usage:
The text was updated successfully, but these errors were encountered: