Skip to content

Commit

Permalink
ENH: ditch pkg_resources for pkg_supports function
Browse files Browse the repository at this point in the history
  • Loading branch information
kohr-h committed Sep 10, 2018
1 parent 99dde28 commit 7f560e8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions odl/util/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ def pkg_supports(feature, pkg_version, pkg_feat_dict):
>>> pkg_supports('feat5', '1.0', feat_dict)
False
"""
from pkg_resources import parse_requirements
from packaging.requirements import Requirement

feature = str(feature)
pkg_version = str(pkg_version)
Expand All @@ -1521,16 +1521,11 @@ def pkg_supports(feature, pkg_version, pkg_feat_dict):
ver_specs = ['pkg' + supp_ver for supp_ver in supp_versions]
# Each parse_requirements list contains only one entry since we specify
# only one package
ver_reqs = [list(parse_requirements(ver_spec))[0]
for ver_spec in ver_specs]
ver_reqs = [Requirement(ver_spec) for ver_spec in ver_specs]

# If one of the requirements in the list is met, return True
for req in ver_reqs:
if req.specifier.contains(pkg_version, prereleases=True):
return True

# No match
return False
# If one of the requirements in the list is met, return True, else False
return any(req.specifier.contains(pkg_version, prereleases=True)
for req in ver_reqs)


class NumpyRandomSeed(object):
Expand Down

0 comments on commit 7f560e8

Please sign in to comment.