pkg_supports

odl.util.utility.pkg_supports(feature, pkg_version, pkg_feat_dict)[source]

Return bool indicating whether a package supports feature.

Parameters:
featurestr

Name of a potential feature of a package.

pkg_versionstr

Version of the package that should be checked for presence of the feature.

pkg_feat_dictdict

Specification of features of a package. Each item has the following form:

feature_name: version_specification

Here, feature_name is a string that is matched against feature, and version_specification is a string or a sequence of strings that specifies version sets. These specifications are the same as for setuptools requirements, just without the package name. A None entry signals "no support in any version", i.e., always False. If a sequence of requirements are given, they are OR-ed together. See Examples for details.

Returns:
supportsbool

True if pkg_version of the package in question supports feature, False otherwise.

Examples

>>> feat_dict = {
...     'feat1': '==0.5.1',
...     'feat2': '>0.6, <=0.9',  # both required simultaneously
...     'feat3': ['>0.6', '<=0.9'],  # only one required, i.e. always True
...     'feat4': ['==0.5.1', '>0.6, <=0.9'],
...     'feat5': None
... }
>>> pkg_supports('feat1', '0.5.1', feat_dict)
True
>>> pkg_supports('feat1', '0.4', feat_dict)
False
>>> pkg_supports('feat2', '0.5.1', feat_dict)
False
>>> pkg_supports('feat2', '0.6.1', feat_dict)
True
>>> pkg_supports('feat2', '0.9', feat_dict)
True
>>> pkg_supports('feat2', '1.0', feat_dict)
False
>>> pkg_supports('feat3', '0.4', feat_dict)
True
>>> pkg_supports('feat3', '1.0', feat_dict)
True
>>> pkg_supports('feat4', '0.5.1', feat_dict)
True
>>> pkg_supports('feat4', '0.6', feat_dict)
False
>>> pkg_supports('feat4', '0.6.1', feat_dict)
True
>>> pkg_supports('feat4', '1.0', feat_dict)
False
>>> pkg_supports('feat5', '0.6.1', feat_dict)
False
>>> pkg_supports('feat5', '1.0', feat_dict)
False