mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-31 16:36:20 +00:00
Remove import-time dependency version checks.
This commit is contained in:
parent
c76fc6d959
commit
6623ed3e4b
@ -277,91 +277,6 @@ def get_package_versions_and_locations():
|
||||
return packages, cross_check_errors
|
||||
|
||||
|
||||
def split_requirement(req):
|
||||
"""
|
||||
Split up a single requirement string into the different version constraint pieces.
|
||||
|
||||
This is like req.split(",") except it doesn't split on , found inside [].
|
||||
|
||||
:return: A list of the split up pieces.
|
||||
"""
|
||||
in_extras = False
|
||||
pieces = []
|
||||
chunk = ''
|
||||
for ch in req:
|
||||
if in_extras:
|
||||
if ch == ']':
|
||||
in_extras = False
|
||||
chunk += ch
|
||||
else:
|
||||
if ch == '[':
|
||||
in_extras = True
|
||||
chunk += ch
|
||||
elif ch == ',':
|
||||
pieces.append(chunk)
|
||||
chunk = ''
|
||||
else:
|
||||
chunk += ch
|
||||
pieces.append(chunk)
|
||||
return pieces
|
||||
|
||||
|
||||
def check_requirement(req, vers_and_locs):
|
||||
# We support only conjunctions of <=, >=, and !=
|
||||
reqlist = split_requirement(req)
|
||||
name = reqlist[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:
|
||||
return
|
||||
(actual, location, comment) = vers_and_locs[name]
|
||||
if actual is None:
|
||||
# comment is (type, message, (filename, line number, function name, text)) for the original ImportError
|
||||
raise ImportError("for requirement %r: %s" % (req, comment))
|
||||
if actual == 'unknown':
|
||||
return
|
||||
try:
|
||||
actualver = normalized_version(actual, what="actual version %r of %s from %r" %
|
||||
(actual, name, location))
|
||||
matched = match_requirement(req, reqlist, actualver)
|
||||
except verlib.IrrationalVersionError:
|
||||
# meh, it probably doesn't matter
|
||||
return
|
||||
|
||||
if not matched:
|
||||
msg = ("We require %s, but could only find version %s.\n" % (req, actual))
|
||||
if location and location != 'unknown':
|
||||
msg += "The version we found is from %r.\n" % (location,)
|
||||
msg += ("To resolve this problem, uninstall that version, either using your\n"
|
||||
"operating system's package manager or by moving aside the directory.")
|
||||
raise PackagingError(msg)
|
||||
|
||||
|
||||
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('>=')
|
||||
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
|
||||
else:
|
||||
raise PackagingError("no version info or could not understand requirement %r" % (req,))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list):
|
||||
"""This function returns a list of errors due to any failed cross-checks."""
|
||||
|
||||
@ -453,36 +368,6 @@ def get_error_string(errors, debug=False):
|
||||
% (os.environ.get('PYTHONPATH'), install_requires, (os.pathsep+"\n ").join(sys.path)) )
|
||||
return msg
|
||||
|
||||
def check_all_requirements():
|
||||
"""This function returns a list of errors due to any failed checks."""
|
||||
|
||||
from allmydata._auto_deps import install_requires
|
||||
|
||||
fatal_errors = []
|
||||
|
||||
# We require at least 2.6 on all platforms.
|
||||
# (On Python 3, we'll have failed long before this point.)
|
||||
if sys.version_info < (2, 6):
|
||||
try:
|
||||
version_string = ".".join(map(str, sys.version_info))
|
||||
except Exception:
|
||||
version_string = repr(sys.version_info)
|
||||
fatal_errors.append("Tahoe-LAFS currently requires Python v2.6 or greater (but less than v3), not %s"
|
||||
% (version_string,))
|
||||
|
||||
vers_and_locs = dict(_vers_and_locs_list)
|
||||
for requirement in install_requires:
|
||||
try:
|
||||
check_requirement(requirement, vers_and_locs)
|
||||
except (ImportError, PackagingError) as e:
|
||||
fatal_errors.append("%s: %s" % (e.__class__.__name__, e))
|
||||
|
||||
if fatal_errors:
|
||||
raise PackagingError(get_error_string(fatal_errors + _cross_check_errors, debug=True))
|
||||
|
||||
check_all_requirements()
|
||||
|
||||
|
||||
def get_package_versions():
|
||||
return dict([(k, v) for k, (v, l, c) in _vers_and_locs_list])
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
|
||||
import sys
|
||||
import pkg_resources
|
||||
from pkg_resources import Requirement
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata import check_requirement, cross_check, get_package_versions_and_locations, \
|
||||
extract_openssl_version, PackagingError
|
||||
from allmydata import cross_check, get_package_versions_and_locations, \
|
||||
extract_openssl_version
|
||||
from allmydata.util.verlib import NormalizedVersion as V, \
|
||||
IrrationalVersionError, \
|
||||
suggest_normalized_version as suggest
|
||||
@ -28,43 +27,6 @@ class MockSSL(object):
|
||||
|
||||
|
||||
class CheckRequirement(unittest.TestCase):
|
||||
def test_check_requirement(self):
|
||||
self._check_success("setuptools >= 0.6c6", {"setuptools": ("0.6", "", None)})
|
||||
self._check_success("setuptools >= 0.6c6", {"setuptools": ("0.6", "", "distribute")})
|
||||
self._check_success("pycrypto >= 2.1.0, != 2.2, != 2.4", {"pycrypto": ("2.1.0", "", None)})
|
||||
self._check_success("pycrypto >= 2.1.0, != 2.2, != 2.4", {"pycrypto": ("2.3.0", "", None)})
|
||||
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("zope.interface", {"zope.interface": ("unknown", "", None)})
|
||||
self._check_success("mock", {"mock": ("0.6.0", "", None)})
|
||||
self._check_success("foo >= 1.0", {"foo": ("1.0", "", None), "bar": ("2.0", "", None)})
|
||||
|
||||
self._check_success("foolscap[secure_connections] >= 0.6.0", {"foolscap": ("0.7.0", "", None)})
|
||||
|
||||
self._check_failure("foolscap[secure_connections] >= 0.6.0", {"foolscap": ("0.5.1", "", None)})
|
||||
self._check_failure("pycrypto >= 2.1.0, != 2.2, != 2.4", {"pycrypto": ("2.2.0", "", None)})
|
||||
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("foo >= 1.0", {})
|
||||
|
||||
self.failUnlessRaises(ImportError, check_requirement,
|
||||
"foo >= 1.0", {"foo": (None, None, "foomodule")})
|
||||
|
||||
def _check_success(self, req, vers_and_locs):
|
||||
check_requirement(req, vers_and_locs)
|
||||
|
||||
for pkg, ver in vers_and_locs.items():
|
||||
self.failUnless(ver[0] in Requirement.parse(req), str((ver, req)))
|
||||
|
||||
def _check_failure(self, req, vers_and_locs):
|
||||
self.failUnlessRaises(PackagingError, check_requirement, req, vers_and_locs)
|
||||
|
||||
for pkg, ver in vers_and_locs.items():
|
||||
self.failIf(ver[0] in Requirement.parse(req), str((ver, req)))
|
||||
|
||||
def test_packages_from_pkg_resources(self):
|
||||
if hasattr(sys, 'frozen'):
|
||||
raise unittest.SkipTest("This test doesn't apply to frozen builds.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user