Esempio n. 1
0
def check_python_versions(files):
    """Check that a set of Python files works with supported Ptyhon versions"""
    # This is a dict dict mapping:
    #   version -> filename -> reasons
    #
    # Reasons are tuples of (lineno, string), where the string is the
    # cause for a version incompatibility.
    all_issues = {}

    # Parse files and run pyqver on each file.
    for path in files:
        with open(path) as pyfile:
            full_text = pyfile.read()
        versions = pyqver.get_versions(full_text, path)

        for ver, reasons in versions.items():
            if ver <= spack_min_supported:
                continue

            # Record issues. Mark exceptions with '# nopyqver' comment
            for lineno, cause in reasons:
                lines = full_text.split('\n')
                if not re.search(r'#\s*nopyqver\s*$', lines[lineno - 1]):
                    all_issues.setdefault(ver, {})[path] = reasons

    # Print a message if there are are issues
    if all_issues:
        tty.msg("Spack must remain compatible with Python version %d.%d"
                % spack_min_supported)

    # Print out a table showing which files/linenos require which
    # python version, and a string describing why.
    for v in sorted(all_issues.keys(), reverse=True):
        messages = []
        for path in sorted(all_issues[v].keys()):
            short_path = path
            if path.startswith(spack.paths.prefix):
                short_path = path[len(spack.paths.prefix):]

            reasons = [r for r in set(all_issues[v][path]) if r]
            for lineno, cause in reasons:
                file_line = "%s:%s" % (short_path.lstrip('/'), lineno)
                messages.append((file_line, cause))

        print()
        tty.msg("These files require version %d.%d:" % v)
        maxlen = max(len(f) for f, prob in messages)
        fmt = "%%-%ds%%s" % (maxlen + 3)
        print(fmt % ('File', 'Reason'))
        print(fmt % ('-' * (maxlen), '-' * 20))
        for msg in messages:
            print(fmt % msg)

    # Fail this test if there were issues.
    assert not all_issues
Esempio n. 2
0
def check_python_versions(files):
    """Check that a set of Python files works with supported Ptyhon versions"""
    # This is a dict dict mapping:
    #   version -> filename -> reasons
    #
    # Reasons are tuples of (lineno, string), where the string is the
    # cause for a version incompatibility.
    all_issues = {}

    # Parse files and run pyqver on each file.
    for path in files:
        with open(path) as pyfile:
            full_text = pyfile.read()
        versions = pyqver.get_versions(full_text, path)

        for ver, reasons in versions.items():
            if ver <= spack_min_supported:
                continue

            # Record issues. Mark exceptions with '# nopyqver' comment
            for lineno, cause in reasons:
                lines = full_text.split('\n')
                if not re.search(r'#\s*nopyqver\s*$', lines[lineno - 1]):
                    all_issues.setdefault(ver, {})[path] = reasons

    # Print a message if there are are issues
    if all_issues:
        tty.msg("Spack must remain compatible with Python version %d.%d" %
                spack_min_supported)

    # Print out a table showing which files/linenos require which
    # python version, and a string describing why.
    for v in sorted(all_issues.keys(), reverse=True):
        messages = []
        for path in sorted(all_issues[v].keys()):
            short_path = path
            if path.startswith(spack.prefix):
                short_path = path[len(spack.prefix):]

            reasons = [r for r in set(all_issues[v][path]) if r]
            for lineno, cause in reasons:
                file_line = "%s:%s" % (short_path.lstrip('/'), lineno)
                messages.append((file_line, cause))

        print()
        tty.msg("These files require version %d.%d:" % v)
        maxlen = max(len(f) for f, prob in messages)
        fmt = "%%-%ds%%s" % (maxlen + 3)
        print(fmt % ('File', 'Reason'))
        print(fmt % ('-' * (maxlen), '-' * 20))
        for msg in messages:
            print(fmt % msg)

    # Fail this test if there were issues.
    assert not all_issues
Esempio n. 3
0
    def check_python_versions(self, *files):
        # dict version -> filename -> reasons
        all_issues = {}

        for fn in files:
            if fn != '/Users/gamblin2/src/spack/var/spack/packages/vim/package.py':
                continue
            print fn

            with open(fn) as pyfile:
                versions = pyqver2.get_versions(pyfile.read())
                for ver, reasons in versions.items():
                    if ver > spack_max_version:
                        if not ver in all_issues:
                            all_issues[ver] = {}
                        all_issues[ver][fn] = reasons

        if all_issues:
            tty.error("Spack must run on Python version %d.%d"
                      % spack_max_version)

        for v in sorted(all_issues.keys(), reverse=True):
            msgs = []
            for fn in sorted(all_issues[v].keys()):
                short_fn = fn
                if fn.startswith(spack.prefix):
                    short_fn = fn[len(spack.prefix):]

                reasons = [r for r in set(all_issues[v][fn]) if r]
                for r in reasons:
                    msgs.append(("%s:%s" % ('spack' + short_fn, r[0]), r[1]))

            tty.error("These files require version %d.%d:" % v)
            maxlen = max(len(f) for f, prob in msgs)
            fmt = "%%-%ds%%s" % (maxlen+3)
            print fmt % ('File', 'Reason')
            print fmt % ('-' * (maxlen), '-' * 20)
            for msg in msgs:
                print fmt % msg

        self.assertTrue(len(all_issues) == 0)
Esempio n. 4
0
    def check_python_versions(self, *files):
        # dict version -> filename -> reasons
        all_issues = {}

        for fn in files:
            with open(fn) as pyfile:
                versions = pyqver2.get_versions(pyfile.read())
                for ver, reasons in versions.items():
                    if ver > spack_max_version:
                        if not ver in all_issues:
                            all_issues[ver] = {}
                        all_issues[ver][fn] = reasons

        if all_issues:
            tty.error("Spack must run on Python version %d.%d"
                      % spack_max_version)

        for v in sorted(all_issues.keys(), reverse=True):
            msgs = []
            for fn in sorted(all_issues[v].keys()):
                short_fn = fn
                if fn.startswith(spack.prefix):
                    short_fn = fn[len(spack.prefix):]

                reasons = [r for r in set(all_issues[v][fn]) if r]
                for r in reasons:
                    msgs.append(("%s:%s" % ('spack' + short_fn, r[0]), r[1]))

            tty.error("These files require version %d.%d:" % v)
            maxlen = max(len(f) for f, prob in msgs)
            fmt = "%%-%ds%%s" % (maxlen+3)
            print fmt % ('File', 'Reason')
            print fmt % ('-' * (maxlen), '-' * 20)
            for msg in msgs:
                print fmt % msg

        self.assertTrue(len(all_issues) == 0)