djblets.features.registry¶
Registry for managing feature registrations.
- class FeaturesRegistry[source]¶
-
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.- lookup_attrs: Sequence[str] = ('feature_id',)[source]¶
A list of attributes that items can be looked up by.
- 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.'}[source]¶
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[source]¶
alias of
FeatureConflictError
- lookup_error_class[source]¶
alias of
FeatureNotFoundError
- register(feature: Feature) None [source]¶
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 [source]¶
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] [source]¶
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]', '_populated': 'bool', '_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]'}¶
- __orig_bases__ = (djblets.registries.registry.Registry[djblets.features.feature.Feature],)¶
- __parameters__ = ()¶
- get_features_registry() FeaturesRegistry [source]¶
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: