Changeset 2c99294a in trunk
- Timestamp:
- 2015-07-28T23:20:33Z (10 years ago)
- Branches:
- master
- Children:
- 023f9fa
- Parents:
- 3239527
- git-author:
- Daira Hopwood <daira@…> (2015-07-28 22:41:13)
- git-committer:
- Daira Hopwood <daira@…> (2015-07-28 23:20:33)
- Location:
- src/allmydata
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/__init__.py ¶
r3239527 r2c99294a 179 179 import warnings 180 180 from _auto_deps import package_imports, global_deprecation_messages, deprecation_messages, \ 181 runtime_warning_messages, warning_imports 181 runtime_warning_messages, warning_imports, ignorable 182 182 183 183 def package_dir(srcfile): … … 247 247 packages.append( (pkgname, get_openssl_version()) ) 248 248 249 return packages 249 cross_check_errors = [] 250 251 if not hasattr(sys, 'frozen'): 252 import pkg_resources 253 from _auto_deps import install_requires 254 255 pkg_resources_vers_and_locs = dict([(p.project_name.lower(), (str(p.version), p.location)) 256 for p in pkg_resources.require(install_requires)]) 257 258 imported_packages = set([p.lower() for (p, _) in packages]) 259 extra_packages = [] 260 261 for pr_name, (pr_ver, pr_loc) in pkg_resources_vers_and_locs.iteritems(): 262 if pr_name not in imported_packages and pr_name not in ignorable: 263 extra_packages.append( (pr_name, (pr_ver, pr_loc, "according to pkg_resources")) ) 264 265 cross_check_errors = cross_check(pkg_resources_vers_and_locs, packages) 266 packages += extra_packages 267 268 return packages, cross_check_errors 250 269 251 270 … … 301 320 302 321 303 _vers_and_locs_list = get_package_versions_and_locations()304 305 306 def cross_check_pkg_resources_versus_import():307 """This function returns a list of errors due to any failed cross-checks."""308 309 import pkg_resources310 from _auto_deps import install_requires311 312 pkg_resources_vers_and_locs = dict([(p.project_name.lower(), (str(p.version), p.location))313 for p in pkg_resources.require(install_requires)])314 315 return cross_check(pkg_resources_vers_and_locs, _vers_and_locs_list)316 317 318 322 def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list): 319 323 """This function returns a list of errors due to any failed cross-checks.""" 320 324 321 from _auto_deps import not_import_versionable , ignorable325 from _auto_deps import not_import_versionable 322 326 323 327 errors = [] … … 377 381 % (name, pr_ver, str(pr_normver), pr_loc, imp_ver, str(imp_normver), imp_loc)) 378 382 379 imported_packages = set([p.lower() for (p, _) in imported_vers_and_locs_list])380 extra_vers_and_locs_list = []381 for pr_name, (pr_ver, pr_loc) in pkg_resources_vers_and_locs.iteritems():382 if pr_name not in imported_packages and pr_name not in ignorable:383 errors.append("Warning: dependency %r (version %r) found by pkg_resources not found by import."384 % (pr_name, pr_ver))385 386 383 return errors 384 385 386 _vers_and_locs_list, _cross_check_errors = get_package_versions_and_locations() 387 387 388 388 … … 407 407 from allmydata._auto_deps import install_requires 408 408 409 errors = []409 fatal_errors = [] 410 410 411 411 # We require at least 2.6 on all platforms. … … 416 416 except Exception: 417 417 version_string = repr(sys.version_info) 418 errors.append("Tahoe-LAFS currently requires Python v2.6 or greater (but less than v3), not %s"419 % (version_string,))418 fatal_errors.append("Tahoe-LAFS currently requires Python v2.6 or greater (but less than v3), not %s" 419 % (version_string,)) 420 420 421 421 vers_and_locs = dict(_vers_and_locs_list) … … 424 424 check_requirement(requirement, vers_and_locs) 425 425 except (ImportError, PackagingError), e: 426 errors.append("%s: %s" % (e.__class__.__name__, e))427 428 if errors:429 raise PackagingError(get_error_string( errors, debug=True))426 fatal_errors.append("%s: %s" % (e.__class__.__name__, e)) 427 428 if fatal_errors: 429 raise PackagingError(get_error_string(fatal_errors + _cross_check_errors, debug=True)) 430 430 431 431 check_all_requirements() … … 450 450 output = "\n".join(res) + "\n" 451 451 452 if not hasattr(sys, 'frozen'): 453 errors = cross_check_pkg_resources_versus_import() 454 if errors: 455 output += get_error_string(errors, debug=debug) 452 if _cross_check_errors: 453 output += get_error_string(_cross_check_errors, debug=debug) 456 454 457 455 return output -
TabularUnified src/allmydata/test/test_import.py ¶
r3239527 r2c99294a 9 9 class T(unittest.TestCase): 10 10 def test_report_import_error(self): 11 marker = "wheeeyo" 11 12 real_import_func = __import__ 12 13 def raiseIE_from_this_particular_func(name, *args): 13 14 if name == "foolscap": 14 marker = "wheeeyo"15 15 raise ImportError(marker + " foolscap cant be imported") 16 16 else: … … 19 19 # Let's run as little code as possible with __import__ patched. 20 20 patcher = MonkeyPatcher((__builtin__, '__import__', raiseIE_from_this_particular_func)) 21 vers_and_locs = patcher.runWithPatches(allmydata.get_package_versions_and_locations)21 vers_and_locs, errors = patcher.runWithPatches(allmydata.get_package_versions_and_locations) 22 22 23 for (pkgname, stuff) in vers_and_locs: 24 if pkgname == 'foolscap': 25 self.failUnless('wheeeyo' in str(stuff[2]), stuff) 26 self.failUnless('raiseIE_from_this_particular_func' in str(stuff[2]), stuff) 23 foolscap_stuffs = [stuff for (pkg, stuff) in vers_and_locs if pkg == 'foolscap'] 24 self.failUnlessEqual(len(foolscap_stuffs), 1) 25 comment = str(foolscap_stuffs[0][2]) 26 self.failUnlessIn(marker, comment) 27 self.failUnlessIn('raiseIE_from_this_particular_func', comment) 28 29 self.failUnless([e for e in errors if "dependency \'foolscap\' could not be imported" in e]) -
TabularUnified src/allmydata/test/test_version.py ¶
r3239527 r2c99294a 1 1 2 import sys 3 import pkg_resources 2 4 from pkg_resources import Requirement 3 5 4 6 from twisted.trial import unittest 5 7 6 from allmydata import check_requirement, cross_check, extract_openssl_version, PackagingError 8 from allmydata import check_requirement, cross_check, get_package_versions_and_locations, \ 9 extract_openssl_version, PackagingError 7 10 from allmydata.util.verlib import NormalizedVersion as V, \ 8 11 IrrationalVersionError, \ … … 70 73 self.failIf(ver[0] in Requirement.parse(req), str((ver, req))) 71 74 75 def test_packages_from_pkg_resources(self): 76 if hasattr(sys, 'frozen'): 77 raise unittest.SkipTest("This test doesn't apply to frozen builds.") 78 79 class MockPackage(object): 80 def __init__(self, project_name, version, location): 81 self.project_name = project_name 82 self.version = version 83 self.location = location 84 85 def call_pkg_resources_require(*args): 86 return [MockPackage("Foo", "1.0", "/path")] 87 self.patch(pkg_resources, 'require', call_pkg_resources_require) 88 89 (packages, errors) = get_package_versions_and_locations() 90 self.failUnlessIn(("foo", ("1.0", "/path", "according to pkg_resources")), packages) 91 self.failIfEqual(errors, []) 92 self.failUnlessEqual([e for e in errors if "was not found by pkg_resources" not in e], []) 93 72 94 def test_cross_check_ticket_1355(self): 73 95 # The bug in #1355 is triggered when a version string from either pkg_resources or import … … 90 112 91 113 res = cross_check({"foo": ("unparseable", "")}, []) 92 self.failUnlessEqual(len(res), 1) 93 self.failUnlessIn("not found by import", res[0]) 114 self.failUnlessEqual(res, []) 94 115 95 116 res = cross_check({"argparse": ("unparseable", "")}, [])
Note: See TracChangeset
for help on using the changeset viewer.