def compiler_list(args): tty.msg("Available compilers") index = index_by(spack.compilers.all_compilers(scope=args.scope), lambda c: (c.spec.name, c.operating_system, c.target)) # For a container, take each element which does not evaluate to false and # convert it to a string. For elements which evaluate to False (e.g. None) # convert them to '' (in which case it still evaluates to False but is a # string type). Tuples produced by this are guaranteed to be comparable in # Python 3 convert_str = (lambda tuple_container: tuple( str(x) if x else '' for x in tuple_container)) index_str_keys = list((convert_str(x), y) for x, y in index.items()) ordered_sections = sorted(index_str_keys, key=lambda item: item[0]) for i, (key, compilers) in enumerate(ordered_sections): if i >= 1: print() name, os, target = key os_str = os if target: os_str += "-%s" % target cname = "%s{%s} %s" % (spack.spec.compiler_color, name, os_str) tty.hline(colorize(cname), char='-') colify(reversed(sorted(c.spec for c in compilers)))
def iter_groups(specs, indent, all_headers): """Break a list of specs into groups indexed by arch/compiler.""" # Make a dict with specs keyed by architecture and compiler. index = index_by(specs, ('architecture', 'compiler')) ispace = indent * ' ' # 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 if architecture else 'no arch', spack.spec.compiler_color, compiler if compiler else 'no compiler') # Sometimes we want to display specs that are not yet concretized. # If they don't have a compiler / architecture attached to them, # then skip the header if all_headers or (architecture is not None or compiler is not None): sys.stdout.write(ispace) tty.hline(colorize(header), char='-') specs = index[(architecture, compiler)] specs.sort() yield specs
def compiler_list(args): tty.msg("Available compilers") index = index_by(spack.compilers.all_compilers(), 'name') for i, (name, compilers) in enumerate(index.items()): if i >= 1: print cname = "%s{%s}" % (spack.spec.compiler_color, name) tty.hline(colorize(cname), char='-') colify(reversed(sorted(compilers)))
def compiler_list(args): tty.msg("Available compilers") index = index_by(spack.compilers.all_compilers(scope=args.scope), 'name') for i, (name, compilers) in enumerate(index.items()): if i >= 1: print cname = "%s{%s}" % (spack.spec.compiler_color, name) tty.hline(colorize(cname), char='-') colify(reversed(sorted(compilers)))
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 find(parser, args): # Filter out specs that don't exist. query_specs = spack.cmd.parse_specs(args.query_specs) query_specs, nonexisting = partition_list( query_specs, lambda s: spack.db.exists(s.name)) if nonexisting: msg = "No such package%s: " % ('s' if len(nonexisting) > 1 else '') msg += ", ".join(s.name for s in nonexisting) tty.msg(msg) if not query_specs: return specs = [ s for s in spack.db.installed_package_specs() if not query_specs or any(s.satisfies(q) for q in query_specs) ] # 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 architecture in index: tty.hline(architecture, char='=', color=spack.spec.architecture_color) for compiler in index[architecture]: tty.hline(compiler, char='-', color=spack.spec.compiler_color) specs = index[architecture][compiler] specs.sort() abbreviated = [s.format('$_$@$+$#', color=True) for s in specs] if args.paths: # Print one spec per line along with prefix path width = max(len(s) for s in abbreviated) width += 2 format = " %-{}s%s".format(width) for abbrv, spec in zip(abbreviated, specs): print format % (abbrv, spec.prefix) elif args.full_specs: for spec in specs: print spec.tree(indent=4, format='$_$@$+', color=True), else: max_len = max([len(s.name) for s in specs]) max_len += 4 for spec in specs: format = '$-' + str(max_len) + '_$@$+$#' print " " + spec.format(format, color=True)
def find(parser, args): # Filter out specs that don't exist. query_specs = spack.cmd.parse_specs(args.query_specs) query_specs, nonexisting = partition_list( query_specs, lambda s: spack.db.exists(s.name)) if nonexisting: msg = "No such package%s: " % ('s' if len(nonexisting) > 1 else '') msg += ", ".join(s.name for s in nonexisting) tty.msg(msg) if not query_specs: return specs = [s for s in spack.db.installed_package_specs() if not query_specs or any(s.satisfies(q) for q in query_specs)] # 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 architecture in index: tty.hline(architecture, char='=', color=spack.spec.architecture_color) for compiler in index[architecture]: tty.hline(compiler, char='-', color=spack.spec.compiler_color) specs = index[architecture][compiler] specs.sort() abbreviated = [s.format('$_$@$+$#', color=True) for s in specs] if args.paths: # Print one spec per line along with prefix path width = max(len(s) for s in abbreviated) width += 2 format = " %-{}s%s".format(width) for abbrv, spec in zip(abbreviated, specs): print format % (abbrv, spec.package.prefix) elif args.full_specs: for spec in specs: print spec.tree(indent=4, format='$_$@$+', color=True), else: max_len = max([len(s.name) for s in specs]) max_len += 4 for spec in specs: format = '$-' + str(max_len) + '_$@$+$#' print " " + spec.format(format, color=True)
def compiler_list(args): tty.msg("Available compilers") index = index_by(spack.compilers.all_compilers(scope=args.scope), lambda c: (c.spec.name, c.operating_system, c.target)) ordered_sections = sorted(index.items(), key=lambda item: item[0]) for i, (key, compilers) in enumerate(ordered_sections): if i >= 1: print() name, os, target = key os_str = os if target: os_str += "-%s" % target cname = "%s{%s} %s" % (spack.spec.compiler_color, name, os_str) tty.hline(colorize(cname), char='-') colify(reversed(sorted(c.spec for c in compilers)))
def compiler_list(args): compilers = spack.compilers.all_compilers(scope=args.scope, init_config=False) # If there are no compilers in any scope, and we're outputting to a tty, give a # hint to the user. if len(compilers) == 0: if not sys.stdout.isatty(): return msg = "No compilers available" if args.scope is None: msg += ". Run `spack compiler find` to autodetect compilers" tty.msg(msg) return index = index_by(compilers, lambda c: (c.spec.name, c.operating_system, c.target)) tty.msg("Available compilers") # For a container, take each element which does not evaluate to false and # convert it to a string. For elements which evaluate to False (e.g. None) # convert them to '' (in which case it still evaluates to False but is a # string type). Tuples produced by this are guaranteed to be comparable in # Python 3 convert_str = (lambda tuple_container: tuple( str(x) if x else '' for x in tuple_container)) index_str_keys = list((convert_str(x), y) for x, y in index.items()) ordered_sections = sorted(index_str_keys, key=lambda item: item[0]) for i, (key, compilers) in enumerate(ordered_sections): if i >= 1: print() name, os, target = key os_str = os if target: os_str += "-%s" % target cname = "%s{%s} %s" % (spack.spec.compiler_color, name, os_str) tty.hline(colorize(cname), char='-') colify(reversed(sorted(c.spec for c in compilers)))
def display_specs(specs, args=None, **kwargs): """Display human readable specs with customizable formatting. Prints the supplied specs to the screen, formatted according to the arguments provided. Specs are grouped by architecture and compiler, and columnized if possible. There are three possible "modes": * ``short`` (default): short specs with name and version, columnized * ``paths``: Two columns: one for specs, one for paths * ``deps``: Dependency-tree style, like ``spack spec``; can get long Options can add more information to the default display. Options can be provided either as keyword arguments or as an argparse namespace. Keyword arguments take precedence over settings in the argparse namespace. Args: specs (list of spack.spec.Spec): the specs to display args (optional argparse.Namespace): namespace containing formatting arguments Keyword Args: mode (str): Either 'short', 'paths', or 'deps' long (bool): Display short hashes with specs very_long (bool): Display full hashes with specs (supersedes ``long``) namespace (bool): Print namespaces along with names show_flags (bool): Show compiler flags with specs variants (bool): Show variants with specs indent (int): indent each line this much decorators (dict): dictionary mappng specs to decorators header_callback (function): called at start of arch/compiler sections all_headers (bool): show headers even when arch/compiler aren't defined """ def get_arg(name, default=None): """Prefer kwargs, then args, then default.""" if name in kwargs: return kwargs.get(name) elif args is not None: return getattr(args, name, default) else: return default mode = get_arg('mode', 'short') hashes = get_arg('long', False) namespace = get_arg('namespace', False) flags = get_arg('show_flags', False) full_compiler = get_arg('show_full_compiler', False) variants = get_arg('variants', False) all_headers = get_arg('all_headers', False) decorator = get_arg('decorator', None) if decorator is None: decorator = lambda s, f: f indent = get_arg('indent', 0) ispace = indent * ' ' hlen = 7 if get_arg('very_long', False): hashes = True hlen = None nfmt = '{fullpackage}' if namespace else '{package}' ffmt = '' if full_compiler or flags: ffmt += '$%' if full_compiler: ffmt += '@' ffmt += '+' vfmt = '$+' if variants else '' format_string = '$%s$@%s%s' % (nfmt, ffmt, vfmt) # Make a dict with specs keyed by architecture and compiler. index = index_by(specs, ('architecture', 'compiler')) transform = {'package': decorator, 'fullpackage': decorator} # 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 if architecture else 'no arch', spack.spec.compiler_color, compiler if compiler else 'no compiler') # Sometimes we want to display specs that are not yet concretized. # If they don't have a compiler / architecture attached to them, # then skip the header if all_headers or (architecture is not None or compiler is not None): sys.stdout.write(ispace) tty.hline(colorize(header), char='-') specs = index[(architecture, compiler)] specs.sort() if mode == 'paths': # Print one spec per line along with prefix path abbreviated = [ s.cformat(format_string, transform=transform) for s in specs ] width = max(len(s) for s in abbreviated) width += 2 for abbrv, spec in zip(abbreviated, specs): # optional hash prefix for paths h = gray_hash(spec, hlen) if hashes else '' # only show prefix for concrete specs prefix = spec.prefix if spec.concrete else '' # print it all out at once fmt = "%%s%%s %%-%ds%%s" % width print(fmt % (ispace, h, abbrv, prefix)) elif mode == 'deps': for spec in specs: print( spec.tree(format=format_string, indent=4, prefix=(lambda s: gray_hash(s, hlen)) if hashes else None)) elif mode == 'short': def fmt(s): string = "" if hashes: string += gray_hash(s, hlen) + ' ' string += s.cformat('$%s$@%s' % (nfmt, vfmt), transform=transform) return string if not flags and not full_compiler: # Print columns of output if not printing flags colify((fmt(s) for s in specs), indent=indent) else: # Print one entry per line if including flags for spec in specs: # Print the hash if necessary hsh = gray_hash(spec, hlen) + ' ' if hashes else '' print(ispace + hsh + spec.cformat(format_string, transform=transform)) else: raise ValueError( "Invalid mode for display_specs: %s. Must be one of (paths," "deps, short)." % mode)
def compiler_list(args): tty.msg("Available compilers") index = index_by(spack.compilers.all_compilers(), 'name') for name, compilers in index.items(): tty.hline(name, char='-', color=spack.spec.compiler_color) colify(reversed(sorted(compilers)), indent=4)
def display_specs(specs, args=None, **kwargs): """Display human readable specs with customizable formatting. Prints the supplied specs to the screen, formatted according to the arguments provided. Specs are grouped by architecture and compiler, and columnized if possible. There are three possible "modes": * ``short`` (default): short specs with name and version, columnized * ``paths``: Two columns: one for specs, one for paths * ``deps``: Dependency-tree style, like ``spack spec``; can get long Options can add more information to the default display. Options can be provided either as keyword arguments or as an argparse namespace. Keyword arguments take precedence over settings in the argparse namespace. Args: specs (list of spack.spec.Spec): the specs to display args (optional argparse.Namespace): namespace containing formatting arguments Keyword Args: mode (str): Either 'short', 'paths', or 'deps' long (bool): Display short hashes with specs very_long (bool): Display full hashes with specs (supersedes ``long``) namespace (bool): Print namespaces along with names show_flags (bool): Show compiler flags with specs variants (bool): Show variants with specs """ def get_arg(name, default=None): """Prefer kwargs, then args, then default.""" if name in kwargs: return kwargs.get(name) elif args is not None: return getattr(args, name, default) else: return default mode = get_arg('mode', 'short') hashes = get_arg('long', False) namespace = get_arg('namespace', False) flags = get_arg('show_flags', False) full_compiler = get_arg('show_full_compiler', False) variants = get_arg('variants', False) hlen = 7 if get_arg('very_long', False): hashes = True hlen = None nfmt = '.' if namespace else '_' ffmt = '' if full_compiler or flags: ffmt += '$%' if full_compiler: ffmt += '@' ffmt += '+' vfmt = '$+' if variants else '' format_string = '$%s$@%s%s' % (nfmt, ffmt, vfmt) # 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) # Sometimes we want to display specs that are not yet concretized. # If they don't have a compiler / architecture attached to them, # then skip the header if architecture is not None or compiler is not None: tty.hline(colorize(header), char='-') specs = index[(architecture, compiler)] specs.sort() abbreviated = [s.cformat(format_string) for s in specs] if mode == 'paths': # 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, spec in zip(abbreviated, specs): prefix = gray_hash(spec, hlen) if hashes else '' print(prefix + (format % (abbrv, spec.prefix))) elif mode == 'deps': for spec in specs: print(spec.tree( format=format_string, indent=4, prefix=(lambda s: gray_hash(s, hlen)) if hashes else None)) elif mode == 'short': # Print columns of output if not printing flags if not flags and not full_compiler: def fmt(s): string = "" if hashes: string += gray_hash(s, hlen) + ' ' string += s.cformat('$-%s$@%s' % (nfmt, vfmt)) return string colify(fmt(s) for s in specs) # Print one entry per line if including flags else: for spec in specs: # Print the hash if necessary hsh = gray_hash(spec, hlen) + ' ' if hashes else '' print(hsh + spec.cformat(format_string) + '\n') else: raise ValueError( "Invalid mode for display_specs: %s. Must be one of (paths," "deps, short)." % mode)
def display_specs(specs, args=None, **kwargs): """Display human readable specs with customizable formatting. Prints the supplied specs to the screen, formatted according to the arguments provided. Specs are grouped by architecture and compiler, and columnized if possible. There are three possible "modes": * ``short`` (default): short specs with name and version, columnized * ``paths``: Two columns: one for specs, one for paths * ``deps``: Dependency-tree style, like ``spack spec``; can get long Options can add more information to the default display. Options can be provided either as keyword arguments or as an argparse namespace. Keyword arguments take precedence over settings in the argparse namespace. Args: specs (list of spack.spec.Spec): the specs to display args (optional argparse.Namespace): namespace containing formatting arguments Keyword Args: mode (str): Either 'short', 'paths', or 'deps' long (bool): Display short hashes with specs very_long (bool): Display full hashes with specs (supersedes ``long``) namespace (bool): Print namespaces along with names show_flags (bool): Show compiler flags with specs variants (bool): Show variants with specs """ def get_arg(name, default=None): """Prefer kwargs, then args, then default.""" if name in kwargs: return kwargs.get(name) elif args is not None: return getattr(args, name, default) else: return default mode = get_arg('mode', 'short') hashes = get_arg('long', False) namespace = get_arg('namespace', False) flags = get_arg('show_flags', False) full_compiler = get_arg('show_full_compiler', False) variants = get_arg('variants', False) hlen = 7 if get_arg('very_long', False): hashes = True hlen = None nfmt = '.' if namespace else '_' ffmt = '' if full_compiler or flags: ffmt += '$%' if full_compiler: ffmt += '@' ffmt += '+' vfmt = '$+' if variants else '' format_string = '$%s$@%s%s' % (nfmt, ffmt, vfmt) # 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() abbreviated = [s.cformat(format_string) for s in specs] if mode == 'paths': # 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, spec in zip(abbreviated, specs): prefix = gray_hash(spec, hlen) if hashes else '' print(prefix + (format % (abbrv, spec.prefix))) elif mode == 'deps': for spec in specs: print( spec.tree(format=format_string, indent=4, prefix=(lambda s: gray_hash(s, hlen)) if hashes else None)) elif mode == 'short': # Print columns of output if not printing flags if not flags and not full_compiler: def fmt(s): string = "" if hashes: string += gray_hash(s, hlen) + ' ' string += s.cformat('$-%s$@%s' % (nfmt, vfmt)) return string colify(fmt(s) for s in specs) # Print one entry per line if including flags else: for spec in specs: # Print the hash if necessary hsh = gray_hash(spec, hlen) + ' ' if hashes else '' print(hsh + spec.cformat(format_string) + '\n') else: raise ValueError( "Invalid mode for display_specs: %s. Must be one of (paths," "deps, short)." % mode)