def get_conflicts(self, *specs): """ Return list of tuples (<spec>, <spec in view>) where the spec active in the view differs from the one to be activated. """ in_view = map(self.get_spec, specs) return [(s, v) for s, v in zip(specs, in_view) if v is not None and s != v]
def print_status(self, *specs, **kwargs): if kwargs.get("with_dependencies", False): specs = set(get_dependencies(specs)) specs = sorted(specs, key=lambda s: s.name) in_view = list(map(self.get_spec, specs)) for s, v in zip(specs, in_view): if not v: tty.error(self._croot + 'Package not linked: %s' % s.name) elif s != v: self.print_conflict(v, s, level="warn") in_view = list(filter(None, in_view)) if len(specs) > 0: tty.msg("Packages linked in %s:" % self._croot[:-1]) # Make a dict with specs keyed by architecture and compiler. index = index_by(specs, ('architecture', 'compiler')) # Traverse the index and print out each package for i, (architecture, compiler) in enumerate(sorted(index)): if i > 0: print() header = "%s{%s} / %s{%s}" % ( spack.spec.architecture_color, architecture, spack.spec.compiler_color, compiler) tty.hline(colorize(header), char='-') specs = index[(architecture, compiler)] specs.sort() format_string = '{name}{@version}' format_string += '{%compiler}{compiler_flags}{variants}' abbreviated = [s.cformat(format_string) for s in specs] # Print one spec per line along with prefix path width = max(len(s) for s in abbreviated) width += 2 format = " %%-%ds%%s" % width for abbrv, s in zip(abbreviated, specs): prefix = '' if self.verbose: prefix = colorize('@K{%s}' % s.dag_hash(7)) print(prefix + (format % (abbrv, self.get_projection_for_spec(s)))) else: tty.warn(self._croot + "No packages found.")
def add_specs(self, *specs, **kwargs): assert all((s.concrete for s in specs)) specs = set(specs) if kwargs.get("with_dependencies", True): specs.update(get_dependencies(specs)) if kwargs.get("exclude", None): specs = set(filter_exclude(specs, kwargs["exclude"])) conflicts = self.get_conflicts(*specs) if conflicts: for s, v in conflicts: self.print_conflict(v, s) return extensions = set(filter(lambda s: s.package.is_extension, specs)) standalones = specs - extensions set(map(self._check_no_ext_conflicts, extensions)) # fail on first error, otherwise link extensions as well if all(map(self.add_standalone, standalones)): all(map(self.add_extension, extensions))
def get_dependencies(specs): "Get set of dependencies (includes specs)" retval = set() set(map(retval.update, (set(s.traverse()) for s in specs))) return retval
def colorize_root(root): colorize = ft.partial(tty.color.colorize, color=sys.stdout.isatty()) pre, post = map(colorize, "@M[@. @M]@.".split()) return "".join([pre, root, post])