djblets.features¶
Feature switch support for applications.
This module contains convenience imports for:
FeatureLevel
- class Feature(register: bool = True)¶
Bases:
object
A feature in a product that can dynamically be turned on/off.
Feature subclasses are used to provide dynamic access to a given feature in a product. The feature may appear off for most users but on for a select few, or only on in a development server, for instance.
Whether a feature is enabled is controlled by the
stability level
of the feature and by thefeature checker
. It will be enabled iflevel
isSTABLE
or if the feature checker returns that the feature is enabled.Consuming applications are expected to subclass this and define the information on the feature, and choose a feature checker to use.
- name: Optional[StrOrPromise] = None¶
The name of the feature.
- summary: Optional[StrOrPromise] = None¶
A summary of the feature.
- level: FeatureLevel = 10¶
Stability level of the feature.
- __init__(register: bool = True) None ¶
Initialize the feature.
Subclasses that wish to provide special initialization should instead override
initialize()
.- Parameters:
register (
bool
, optional) – Whether to register this feature instance. This should generally beTrue
for all callers, except in special cases (like unit tests).- Raises:
djblets.features.errors.FeatureConflictError – The feature ID on this class conflicts with another feature.
- initialize() None ¶
Initialize the feature.
Subclasses that wish to initialize feature logic within the class (such as connecting to signals) should do so by overriding this method.
This will always be called when instantiating the subclass, or when re-registering an unregistered feature class using the
features
registry.
- shutdown() None ¶
Shut down the feature.
Subclasses that wish to provide special shutdown logic within the class (such as disconnecting from signals) should do so by overriding this method.
This is called when unregistering the feature through the
features
registry.
- is_enabled(**kwargs) bool ¶
Return whether the feature is enabled for the given requirements.
This will return a boolean indicating if the feature is enabled.
If
level
isSTABLE
, it will always be enabled. Otherwise, iflevel
is notUNAVAILABLE
, the configured feature checker will be used instead.Callers can pass additional keyword arguments to this method, which the feature checker can use when determining if the feature is enabled. For example, a
HttpRequest
instance, or aUser
.
- __annotations__ = {'feature_id': 'Optional[str]', 'level': 'FeatureLevel', 'name': 'Optional[StrOrPromise]', 'summary': 'Optional[StrOrPromise]'}¶
- class FeatureLevel(value)¶
Bases:
IntEnum
Possible stability levels for features.
- UNAVAILABLE = 0¶
The feature is completely unavailable.
Feature checkers will not be consulted in this case.
- EXPERIMENTAL = 10¶
The feature is experimental.
A feature checker must enable this feature.
- BETA = 50¶
The feature is in beta.
A feature checker must enable this feature.
- STABLE = 100¶
The feature is stable and will always be enabled.
- 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:
FeaturesRegistry