From: Daira Hopwood Date: Fri, 17 Apr 2015 22:39:55 +0000 (+0100) Subject: Fix version checking by supporting '==' requirements. X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=db2c4d05530af51b25f4a482b68d669f820b7487;p=tahoe-lafs%2Ftahoe-lafs.git Fix version checking by supporting '==' requirements. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/__init__.py b/src/allmydata/__init__.py index fa512a13..b378cc5a 100644 --- a/src/allmydata/__init__.py +++ b/src/allmydata/__init__.py @@ -270,10 +270,14 @@ def get_package_versions_and_locations(): def check_requirement(req, vers_and_locs): - # We support only conjunctions of <=, >=, and != + # We support only conjunctions of <=, >=, ==, and != reqlist = req.split(',') - name = reqlist[0].split('<=')[0].split('>=')[0].split('!=')[0].strip(' ').split('[')[0] + name = (reqlist[0].split('<=')[0] + .split('>=')[0] + .split('==')[0] + .split('!=')[0] + .strip(' ').split('[')[0]) if name not in vers_and_locs: raise PackagingError("no version info for %s" % (name,)) if req.strip(' ') == name: @@ -297,25 +301,20 @@ def check_requirement(req, vers_and_locs): def match_requirement(req, reqlist, actualver): for r in reqlist: - s = r.split('<=') - if len(s) == 2: - required = s[1].strip(' ') - if not (actualver <= normalized_version(required, what="required maximum version %r in %r" % (required, req))): - return False # maximum requirement not met - else: - s = r.split('>=') + for op, compare, desc in [('<=', lambda x, y: x <= y, "required maximum version"), + ('>=', lambda x, y: x >= y, "required minimum version"), + ('==', lambda x, y: x == y, "required exact version"), + ('!=', lambda x, y: x != y, "excluded version"), + (None, None, None)]: + if op is None: + raise PackagingError("no version info or could not understand requirement %r" % (req,)) + s = r.split(op) if len(s) == 2: required = s[1].strip(' ') - if not (actualver >= normalized_version(required, what="required minimum version %r in %r" % (required, req))): - return False # minimum requirement not met - else: - s = r.split('!=') - if len(s) == 2: - required = s[1].strip(' ') - if not (actualver != normalized_version(required, what="excluded version %r in %r" % (required, req))): - return False # not-equal requirement not met + if not compare(actualver, normalized_version(required, what="%s %r in %r" % (desc, required, req))): + return False # requirement not met else: - raise PackagingError("no version info or could not understand requirement %r" % (req,)) + break # next requirement from reqlist return True diff --git a/src/allmydata/_auto_deps.py b/src/allmydata/_auto_deps.py index d9985db0..55cdc5e1 100644 --- a/src/allmydata/_auto_deps.py +++ b/src/allmydata/_auto_deps.py @@ -9,11 +9,12 @@ # under both the old and new semantics. That can be achieved by limiting # requirement specs to one of the following forms: # +# * == X # * >= X, <= Y where X < Y # * >= X, != Y, != Z, ... where X < Y < Z... # # (In addition, check_requirement in allmydata/__init__.py only supports -# >=, <= and != operators.) +# >=, <=, ==, and != operators.) install_requires = [ # We require newer versions of setuptools (actually @@ -93,7 +94,6 @@ not_import_versionable = [ 'mock', 'pyasn1', 'pyasn1-modules', - 'python-gflags', ] # Dependencies reported by pkg_resources that we can safely ignore. @@ -105,6 +105,8 @@ ignorable = [ 'twisted-web', 'twisted-core', 'twisted-conch', + 'python-gflags', + 'httplib2', ] import sys diff --git a/src/allmydata/test/test_version.py b/src/allmydata/test/test_version.py index ee149b0e..f351c894 100644 --- a/src/allmydata/test/test_version.py +++ b/src/allmydata/test/test_version.py @@ -36,6 +36,7 @@ class CheckRequirement(unittest.TestCase): self._check_success("pycrypto >= 2.1.0, != 2.2, != 2.4", {"pycrypto": ("2.4.1", "", None)}) self._check_success("Twisted >= 11.0.0, <= 12.2.0", {"Twisted": ("11.0.0", "", None)}) self._check_success("Twisted >= 11.0.0, <= 12.2.0", {"Twisted": ("12.2.0", "", None)}) + self._check_success("oauth2client == 1.1.0", {"oauth2client": ("1.1.0", "", None)}) self._check_success("zope.interface", {"zope.interface": ("unknown", "", None)}) self._check_success("mock", {"mock": ("0.6.0", "", None)}) @@ -54,6 +55,7 @@ class CheckRequirement(unittest.TestCase): self._check_failure("pycrypto >= 2.1.0, != 2.2, != 2.4", {"pycrypto": ("2.0.0", "", None)}) self._check_failure("Twisted >= 11.0.0, <= 12.2.0", {"Twisted": ("10.2.0", "", None)}) self._check_failure("Twisted >= 11.0.0, <= 12.2.0", {"Twisted": ("13.0.0", "", None)}) + self._check_failure("oauth2client == 1.1.0", {"oauth2client": ("1.0.0", "", None)}) self._check_failure("foo >= 1.0", {}) self._check_failure("foo >= 1.0", {"foo": ("irrational", "", None)})