Changeset 2c99294a in trunk


Ignore:
Timestamp:
2015-07-28T23:20:33Z (10 years ago)
Author:
Daira Hopwood <daira@…>
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)
Message:

Don't show scary diagnostic warnings from --version[-and-path] (corrected). refs ticket:2436

The previous version would incorrectly add to the output of
get_package_versions_string each time it was called.

Signed-off-by: Daira Hopwood <daira@…>

Location:
src/allmydata
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/__init__.py

    r3239527 r2c99294a  
    179179    import warnings
    180180    from _auto_deps import package_imports, global_deprecation_messages, deprecation_messages, \
    181         runtime_warning_messages, warning_imports
     181        runtime_warning_messages, warning_imports, ignorable
    182182
    183183    def package_dir(srcfile):
     
    247247            packages.append( (pkgname, get_openssl_version()) )
    248248
    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
    250269
    251270
     
    301320
    302321
    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_resources
    310     from _auto_deps import install_requires
    311 
    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 
    318322def cross_check(pkg_resources_vers_and_locs, imported_vers_and_locs_list):
    319323    """This function returns a list of errors due to any failed cross-checks."""
    320324
    321     from _auto_deps import not_import_versionable, ignorable
     325    from _auto_deps import not_import_versionable
    322326
    323327    errors = []
     
    377381                                              % (name, pr_ver, str(pr_normver), pr_loc, imp_ver, str(imp_normver), imp_loc))
    378382
    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 
    386383    return errors
     384
     385
     386_vers_and_locs_list, _cross_check_errors = get_package_versions_and_locations()
    387387
    388388
     
    407407    from allmydata._auto_deps import install_requires
    408408
    409     errors = []
     409    fatal_errors = []
    410410
    411411    # We require at least 2.6 on all platforms.
     
    416416        except Exception:
    417417            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,))
    420420
    421421    vers_and_locs = dict(_vers_and_locs_list)
     
    424424            check_requirement(requirement, vers_and_locs)
    425425        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))
    430430
    431431check_all_requirements()
     
    450450    output = "\n".join(res) + "\n"
    451451
    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)
    456454
    457455    return output
  • TabularUnified src/allmydata/test/test_import.py

    r3239527 r2c99294a  
    99class T(unittest.TestCase):
    1010    def test_report_import_error(self):
     11        marker = "wheeeyo"
    1112        real_import_func = __import__
    1213        def raiseIE_from_this_particular_func(name, *args):
    1314            if name == "foolscap":
    14                 marker = "wheeeyo"
    1515                raise ImportError(marker + " foolscap cant be imported")
    1616            else:
     
    1919        # Let's run as little code as possible with __import__ patched.
    2020        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)
    2222
    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  
    11
     2import sys
     3import pkg_resources
    24from pkg_resources import Requirement
    35
    46from twisted.trial import unittest
    57
    6 from allmydata import check_requirement, cross_check, extract_openssl_version, PackagingError
     8from allmydata import check_requirement, cross_check, get_package_versions_and_locations, \
     9     extract_openssl_version, PackagingError
    710from allmydata.util.verlib import NormalizedVersion as V, \
    811                                  IrrationalVersionError, \
     
    7073            self.failIf(ver[0] in Requirement.parse(req), str((ver, req)))
    7174
     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
    7294    def test_cross_check_ticket_1355(self):
    7395        # The bug in #1355 is triggered when a version string from either pkg_resources or import
     
    90112
    91113        res = cross_check({"foo": ("unparseable", "")}, [])
    92         self.failUnlessEqual(len(res), 1)
    93         self.failUnlessIn("not found by import", res[0])
     114        self.failUnlessEqual(res, [])
    94115
    95116        res = cross_check({"argparse": ("unparseable", "")}, [])
Note: See TracChangeset for help on using the changeset viewer.