datalad_core.features
- datalad_core.features = <datalad_core.services.feature_registry.FeatureRegistry object>
Facility for deferred determination of named properties
Callables that return an arbitrary name-value mapping can be registered in an instance of this class, The execution of such a callable is deferred until a corresponding value is first requested by label. Any computed value is then cached, and subsequent queries to not re-execute the callable.
This can be useful for centralizing an efficient query of platform/system/environment features (hence the name), which may be expensive, but nevertheless necessary to determine.
Any registered callable must not have required arguments. It must return a mapping from any number of hashable labels to the respective values.
>>> fr = FeatureRegistry() >>> fr.register(lambda: {'feat1': 42 / 3, 'feat2': 'a' * 1000}, ['feat1', 'feat2']) >>> list(fr.keys()) ['feat1', 'feat2'] >>> 'feat1' in fr True >>> 'feat1' in fr.evaluated() False >>> fr['feat2'].startswith('aaaa') True >>> 'feat1' in fr.evaluated() True