djblets.features.registry¶
Registry for managing feature registrations.
- class FeaturesRegistry¶
-
A registry for instantiated features.
This manages all instances of
Feature
subclasses that the product has created, providing easy access to features for checking purposes.- default_errors: RegistryErrorsDict = {'already_registered': 'Could not register feature %(item)s: This feature is already registered or its ID conflicts with another feature.', 'attribute_registered': 'Could not register feature %(item)s: Another feature (%(duplicate)s) is already registered with the same feature ID.', 'invalid_attribute': '"%(attr_name)s" is not a registered lookup attribute.', 'load_entry_point': 'Could not load entry point %(entry_point)s: %(error)s.', 'missing_attribute': 'Could not register %(item)s: it does not have a "%(attr_name)s" attribute.', 'not_registered': 'No item registered with %(attr_name)s = %(attr_value)s.', 'unregister': 'Could not unregister feature %(item)s: This feature was not yet registered.'}¶
The default error formatting strings.
If subclasses need to provide additional errors that can be overridden, they should copy
DEFAULT_ERRORS
and set their copy on the subclass as this attribute.- Type:
- already_registered_error_class¶
alias of
FeatureConflictError
- lookup_error_class¶
alias of
FeatureNotFoundError
- register(feature: Feature) None ¶
Register a feature instance.
The feature’s
initialize()
method will be called once registered.- Parameters:
feature (
djblets.features.feature.Feature
) – The feature to register.- Raises:
djblets.features.errors.FeatureConflictError – The feature’s ID conflicts with another feature class.
djblets.registries.errors.RegistrationError – The feature ID wasn’t set on the class.
- unregister(feature: Feature) None ¶
Unregister a feature instance.
The feature’s
shutdown()
method will be called once unregistered.- Parameters:
feature (
djblets.features.feature.Feature
) – The feature to unregister.- Raises:
djblets.features.errors.FeatureNotFoundError – Raised if the feature was not already registered.
- get_feature(feature_id: str) Optional[Feature] ¶
Return the feature instance with the given ID.
- Parameters:
feature_id (
str
) – The ID of the feature to return.- Returns:
The feature instance matching the ID or
None
if not found.- Return type:
- __annotations__ = {'_items': 'set[RegistryItemType]', '_lock': 'RLock', '_registry': 'dict[str, dict[object, RegistryItemType]]', 'already_registered_error_class': 'Type[AlreadyRegisteredError]', 'default_errors': 'RegistryErrorsDict', 'errors': 'RegistryErrorsDict', 'item_name': 'Optional[str]', 'lookup_attrs': 'Sequence[str]', 'lookup_error_class': 'Type[ItemLookupError]', 'state': 'RegistryState'}¶
- __orig_bases__ = (djblets.registries.registry.Registry[djblets.features.feature.Feature],)¶
- __parameters__ = ()¶
- get_features_registry() FeaturesRegistry ¶
Return the global features registry.
The first time this is called, a
FeaturesRegistry
will be instantiated and cached for future calls.- Returns:
The features registry.
- Return type: