Exemple #1
0
def dumpWithBlame(config, blame, indent=''):
    # colorama, BSD 3-Clause license, cross-platform terminal colours, pip install colorama
    import colorama
    DIM       = colorama.Style.DIM       #pylint: disable=no-member
    RESET_ALL = colorama.Style.RESET_ALL #pylint: disable=no-member
    RESET_COL = colorama.Fore.RESET      #pylint: disable=no-member
    # true/false = green/red:
    GREEN     = colorama.Fore.GREEN      #pylint: disable=no-member
    RED       = colorama.Fore.RED        #pylint: disable=no-member
    # numbers = blue
    BLUE      = colorama.Fore.BLUE       #pylint: disable=no-member
    # strings = magenta
    MAGENTA   = colorama.Fore.MAGENTA    #pylint: disable=no-member

    sys.stdout.write('{')
    if len(config):
        sys.stdout.write('\n')
        for (k, val), last in islast(config.items()):
            sys.stdout.write(indent+'  ')
            sys.stdout.write('"' + k + '": ')
            if isinstance(val, dict):
                dumpWithBlame(val, blame.get(k, {}), indent+'  ')
                if not last:
                    sys.stdout.write(',')
            else:
                if val is True:
                    sys.stdout.write(GREEN + 'true' + RESET_COL)
                elif val is False:
                    sys.stdout.write(RED + 'false' + RESET_COL)
                elif isinstance(val, int) or isinstance(val, float):
                    sys.stdout.write(BLUE + str(val) + RESET_COL)
                else:
                    # must be a string
                    sys.stdout.write('"'+MAGENTA + str(val) + RESET_COL+'"')
                if not last:
                    sys.stdout.write(',')
                if k in blame:
                    sys.stdout.write(' '+DIM+'// ' + blame[k])
            sys.stdout.write(RESET_ALL + '\n')
        sys.stdout.write(indent)
    sys.stdout.write('}')
Exemple #2
0
    def format(self, component, processed, indent=u"", tee=u"", installed_at=u"", test_dep=False, spec=None):
        r = u""

        if self.use_colours:
            DIM = colorama.Style.DIM  # pylint: disable=no-member
            BRIGHT = colorama.Style.BRIGHT  # pylint: disable=no-member
            GREEN = colorama.Fore.GREEN  # pylint: disable=no-member
            RED = colorama.Fore.RED  # pylint: disable=no-member
            RESET = colorama.Style.RESET_ALL  # pylint: disable=no-member
        else:
            DIM = BRIGHT = GREEN = RED = RESET = u""

        mods_path = component.modulesPath()
        deps = component.getDependencies(
            available_components=self.available, target=self.target, test=True, warnings=False
        )
        specs = dict([(x.name, x) for x in component.getDependencySpecs(target=self.target)])

        def isTestOnly(name):
            return specs[name].is_test_dependency

        def shouldDisplay(x):
            if self.list_all:
                # list everything everywhere (apart from test dependencies of test
                # dependencies, which should be considered irrelevant)
                if component.isTestDependency() and isTestOnly(x[0]):
                    return False
                else:
                    return True
            if not isTestOnly(x[0]) or not len(indent):
                # this is non-test dependency, or a top-level test dependency
                if not x[1]:
                    # if it's missing, display it
                    return True
                if x[1].path == os.path.join(mods_path, x[0]):
                    # if it's installed in this module, display it
                    return True
                if x[0] in deps_here:
                    # if it's first depended on by this module, then display it
                    return True
            # everything else shouldn't be displayed here
            return False

        origin_descr = ""
        if self.display_origin:
            origin = component.origin()
            if origin is not None:
                if origin.startswith("github://"):
                    origin_descr = " (" + origin[9:] + ")"
                else:
                    origin_descr = " (" + friendlyRegistryName(origin, short=True) + ")"

        line = indent[:-2] + tee + component.getName() + u" " + DIM + str(component.getVersion()) + origin_descr + RESET

        if spec and not spec.match(component.getVersion()):
            line += u" " + RESET + BRIGHT + RED + str(spec) + RESET
        if test_dep:
            line += u" " + DIM + u"(test dependency)" + RESET
        if len(installed_at):
            line += u" " + DIM + installed_at + RESET
        if component.installedLinked():
            line += GREEN + BRIGHT + u" -> " + RESET + GREEN + fsutils.realpath(component.path) + RESET

        r += line + "\n"

        deps_here = [x for x in list(deps.keys()) if (x not in processed)]
        print_deps = [x for x in list(deps.items()) if shouldDisplay(x)]

        processed += [x[0] for x in print_deps]

        for (name, dep), last in islast(print_deps):
            if last:
                next_indent = indent + u"  "
                tee = self.L_Char + self.Dash_Char + u" "
                next_tee = self.L_Char + self.Dash_Char + u" "
            else:
                next_indent = indent + self.Pipe_Char + u" "
                tee = self.T_Char + self.Dash_Char + u" "
                next_tee = self.T_Char + self.Dash_Char + u" "
            test_dep_status = u""
            if isTestOnly(name):
                test_dep_status = u" (test dependency)"

            version_req = specs[name].nonShrinkwrappedVersionReq()
            if not dep:
                r += (
                    indent
                    + tee
                    + name
                    + u" "
                    + version_req
                    + test_dep_status
                    + BRIGHT
                    + RED
                    + " missing"
                    + RESET
                    + "\n"
                )
            else:
                spec = access.remoteComponentFor(name, version_req, "modules").versionSpec()
                if not spec:
                    spec_descr = u""
                elif spec.match(dep.getVersion()):
                    spec_descr = u" " + str(spec)
                else:
                    spec_descr = u" " + RESET + BRIGHT + RED + str(spec)
                spec_descr += test_dep_status

                if name in deps_here:
                    # dependencies that are first used here may actually be
                    # installed higher up our dependency tree, if they are,
                    # illustrate that:
                    if dep.path == os.path.join(mods_path, name):
                        r += self.format(dep, processed, next_indent, next_tee, test_dep=isTestOnly(name), spec=spec)
                    else:
                        r += self.format(
                            dep,
                            processed,
                            next_indent,
                            next_tee,
                            installed_at=relpathIfSubdir(dep.unresolved_path),
                            test_dep=isTestOnly(name),
                            spec=spec,
                        )
                else:
                    r += indent + tee + DIM + name + spec_descr + RESET + "\n"
        return r
Exemple #3
0
    def format(self,
               component,
               processed,
               indent=u'',
               tee=u'',
               installed_at=u'',
               test_dep=False,
               spec=None):
        r = u''

        if self.use_colours:
            DIM = colorama.Style.DIM  #pylint: disable=no-member
            BRIGHT = colorama.Style.BRIGHT  #pylint: disable=no-member
            GREEN = colorama.Fore.GREEN  #pylint: disable=no-member
            RED = colorama.Fore.RED  #pylint: disable=no-member
            RESET = colorama.Style.RESET_ALL  #pylint: disable=no-member
        else:
            DIM = BRIGHT = GREEN = RED = RESET = u''

        mods_path = component.modulesPath()
        deps = component.getDependencies(available_components=self.available,
                                         target=self.target,
                                         test=True,
                                         warnings=False)
        specs = dict([(x.name, x)
                      for x in component.getDependencySpecs(target=self.target)
                      ])

        def isTestOnly(name):
            return specs[name].is_test_dependency

        def shouldDisplay(x):
            if self.list_all:
                # list everything everywhere (apart from test dependencies of test
                # dependencies, which should be considered irrelevant)
                if component.isTestDependency() and isTestOnly(x[0]):
                    return False
                else:
                    return True
            if (not isTestOnly(x[0]) or not len(indent)):
                # this is non-test dependency, or a top-level test dependency
                if not x[1]:
                    # if it's missing, display it
                    return True
                if x[1].path == os.path.join(mods_path, x[0]):
                    # if it's installed in this module, display it
                    return True
                if x[0] in deps_here:
                    # if it's first depended on by this module, then display it
                    return True
            # everything else shouldn't be displayed here
            return False

        origin_descr = ''
        if self.display_origin:
            origin = component.origin()
            if origin is not None:
                if origin.startswith('github://'):
                    origin_descr = ' (' + origin[9:] + ')'
                else:
                    origin_descr = ' (' + friendlyRegistryName(
                        origin, short=True) + ')'

        line = indent[:-2] + tee + component.getName() + u' ' + DIM + str(
            component.getVersion()) + origin_descr + RESET

        if spec and not spec.match(component.getVersion()):
            line += u' ' + RESET + BRIGHT + RED + str(spec) + RESET
        if test_dep:
            line += u' ' + DIM + u'(test dependency)' + RESET
        if len(installed_at):
            line += u' ' + DIM + installed_at + RESET
        if component.installedLinked():
            line += GREEN + BRIGHT + u' -> ' + RESET + GREEN + fsutils.realpath(
                component.path) + RESET

        r += line + '\n'

        deps_here = [x for x in list(deps.keys()) if (x not in processed)]
        print_deps = [x for x in list(deps.items()) if shouldDisplay(x)]

        processed += [x[0] for x in print_deps]

        for (name, dep), last in islast(print_deps):
            if last:
                next_indent = indent + u'  '
                tee = self.L_Char + self.Dash_Char + u' '
                next_tee = self.L_Char + self.Dash_Char + u' '
            else:
                next_indent = indent + self.Pipe_Char + u' '
                tee = self.T_Char + self.Dash_Char + u' '
                next_tee = self.T_Char + self.Dash_Char + u' '
            test_dep_status = u''
            if isTestOnly(name):
                test_dep_status = u' (test dependency)'

            version_req = specs[name].nonShrinkwrappedVersionReq()
            if not dep:
                r += indent + tee + name + u' ' + version_req + test_dep_status + BRIGHT + RED + ' missing' + RESET + '\n'
            else:
                spec = access.remoteComponentFor(name, version_req,
                                                 'modules').versionSpec()
                if not spec:
                    spec_descr = u''
                elif spec.match(dep.getVersion()):
                    spec_descr = u' ' + str(spec)
                else:
                    spec_descr = u' ' + RESET + BRIGHT + RED + str(spec)
                spec_descr += test_dep_status

                if name in deps_here:
                    # dependencies that are first used here may actually be
                    # installed higher up our dependency tree, if they are,
                    # illustrate that:
                    if dep.path == os.path.join(mods_path, name):
                        r += self.format(dep,
                                         processed,
                                         next_indent,
                                         next_tee,
                                         test_dep=isTestOnly(name),
                                         spec=spec)
                    else:
                        r += self.format(dep,
                                         processed,
                                         next_indent,
                                         next_tee,
                                         installed_at=relpathIfSubdir(
                                             dep.unresolved_path),
                                         test_dep=isTestOnly(name),
                                         spec=spec)
                else:
                    r += indent + tee + DIM + name + spec_descr + RESET + '\n'
        return r