Jump to >

djblets.features.registry

Registry for managing feature registrations.

class FeaturesRegistry[source]

Bases: djblets.registries.registry.Registry

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.

Type

list of str

default_errors: Dict[str, str] = {'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

dict

already_registered_error_class[source]

alias of djblets.features.errors.FeatureConflictError

lookup_error_class[source]

alias of djblets.features.errors.FeatureNotFoundError

register(feature)[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
unregister(feature)[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)[source]

Return the feature instance with the given ID.

Parameters

feature_id (unicode) – The ID of the feature to return.

Returns

The feature instance matching the ID or None if not found.

Return type

djblets.features.feature.Feature

__annotations__ = {'_items': 'Set[RegistryItemType]', '_populated': 'bool', '_registry': 'Dict[str, Dict[object, RegistryItemType]]', 'already_registered_error_class': 'Type[AlreadyRegisteredError]', 'default_errors': 'Dict[str, str]', 'errors': 'Dict[str, str]', 'item_name': 'Optional[str]', 'lookup_attrs': 'Sequence[str]', 'lookup_error_class': 'Type[ItemLookupError]'}
__parameters__ = ()
get_features_registry()[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

FeaturesRegistry