From 23c7089789c2adf8c8861daf8cfd25e8e273a8c5 Mon Sep 17 00:00:00 2001 From: alalazo Date: Wed, 18 May 2016 11:52:27 +0200 Subject: fixes #967, flake8 approved --- lib/spack/spack/cmd/find.py | 135 +++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 53 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py index d0b6752495..7d6aef44a3 100644 --- a/lib/spack/spack/cmd/find.py +++ b/lib/spack/spack/cmd/find.py @@ -22,66 +22,92 @@ # License along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## -import sys -import collections -import itertools import argparse -from StringIO import StringIO +import sys import llnl.util.tty as tty +import spack +import spack.spec +from llnl.util.lang import * from llnl.util.tty.colify import * from llnl.util.tty.color import * -from llnl.util.lang import * -import spack -import spack.spec +description = "Find installed spack packages" -description ="Find installed spack packages" def setup_parser(subparser): format_group = subparser.add_mutually_exclusive_group() + format_group.add_argument('-s', + '--short', + action='store_const', + dest='mode', + const='short', + help='Show only specs (default)') + format_group.add_argument('-p', + '--paths', + action='store_const', + dest='mode', + const='paths', + help='Show paths to package install directories') format_group.add_argument( - '-s', '--short', action='store_const', dest='mode', const='short', - help='Show only specs (default)') - format_group.add_argument( - '-p', '--paths', action='store_const', dest='mode', const='paths', - help='Show paths to package install directories') - format_group.add_argument( - '-d', '--deps', action='store_const', dest='mode', const='deps', + '-d', + '--deps', + action='store_const', + dest='mode', + const='deps', help='Show full dependency DAG of installed packages') - subparser.add_argument( - '-l', '--long', action='store_true', dest='long', - help='Show dependency hashes as well as versions.') - subparser.add_argument( - '-L', '--very-long', action='store_true', dest='very_long', - help='Show dependency hashes as well as versions.') - subparser.add_argument( - '-f', '--show-flags', action='store_true', dest='show_flags', - help='Show spec compiler flags.') + subparser.add_argument('-l', + '--long', + action='store_true', + dest='long', + help='Show dependency hashes as well as versions.') + subparser.add_argument('-L', + '--very-long', + action='store_true', + dest='very_long', + help='Show dependency hashes as well as versions.') + subparser.add_argument('-f', + '--show-flags', + action='store_true', + dest='show_flags', + help='Show spec compiler flags.') subparser.add_argument( - '-e', '--explicit', action='store_true', + '-e', + '--explicit', + action='store_true', help='Show only specs that were installed explicitly') subparser.add_argument( - '-E', '--implicit', action='store_true', + '-E', + '--implicit', + action='store_true', help='Show only specs that were installed as dependencies') subparser.add_argument( - '-u', '--unknown', action='store_true', dest='unknown', + '-u', + '--unknown', + action='store_true', + dest='unknown', help='Show only specs Spack does not have a package for.') subparser.add_argument( - '-m', '--missing', action='store_true', dest='missing', + '-m', + '--missing', + action='store_true', + dest='missing', help='Show missing dependencies as well as installed specs.') - subparser.add_argument( - '-M', '--only-missing', action='store_true', dest='only_missing', - help='Show only missing dependencies.') - subparser.add_argument( - '-N', '--namespace', action='store_true', - help='Show fully qualified package names.') + subparser.add_argument('-M', + '--only-missing', + action='store_true', + dest='only_missing', + help='Show only missing dependencies.') + subparser.add_argument('-N', + '--namespace', + action='store_true', + help='Show fully qualified package names.') - subparser.add_argument( - 'query_specs', nargs=argparse.REMAINDER, - help='optional specs to filter results') + subparser.add_argument('query_specs', + nargs=argparse.REMAINDER, + help='optional specs to filter results') def gray_hash(spec, length): @@ -109,14 +135,15 @@ def display_specs(specs, **kwargs): # Traverse the index and print out each package for i, (architecture, compiler) in enumerate(sorted(index)): - if i > 0: print + if i > 0: + print - header = "%s{%s} / %s{%s}" % ( - spack.spec.architecture_color, architecture, - spack.spec.compiler_color, compiler) + 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 = index[(architecture, compiler)] specs.sort() abbreviated = [s.format(format_string, color=True) for s in specs] @@ -128,20 +155,21 @@ def display_specs(specs, **kwargs): for abbrv, spec in zip(abbreviated, specs): if hashes: - print gray_hash(spec, hlen), - print format % (abbrv, spec.prefix) + print(gray_hash(spec, hlen), ) + print(format % (abbrv, spec.prefix)) elif mode == 'deps': for spec in specs: - print spec.tree( + print(spec.tree( format=format_string, color=True, indent=4, - prefix=(lambda s: gray_hash(s, hlen)) if hashes else None) + 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: + def fmt(s): string = "" if hashes: @@ -149,18 +177,17 @@ def display_specs(specs, **kwargs): string += s.format('$-%s$@$+' % nfmt, color=True) 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.format(format_string, color=True) + '\n' + print(hsh + spec.format(format_string, color=True) + '\n') else: - raise ValueError( - "Invalid mode for display_specs: %s. Must be one of (paths, deps, short)." % mode) - + raise ValueError("Invalid mode for display_specs: %s. Must be one of (paths, deps, short)." % mode) # NOQA: ignore=E501 def find(parser, args): @@ -192,13 +219,14 @@ def find(parser, args): if args.implicit: explicit = True - q_args = { 'installed' : installed, 'known' : known, "explicit" : explicit } + q_args = {'installed': installed, 'known': known, "explicit": explicit} # Get all the specs the user asked for if not query_specs: specs = set(spack.installed_db.query(**q_args)) else: - results = [set(spack.installed_db.query(qs, **q_args)) for qs in query_specs] + results = [set(spack.installed_db.query(qs, **q_args)) + for qs in query_specs] specs = set.union(*results) if not args.mode: @@ -206,7 +234,8 @@ def find(parser, args): if sys.stdout.isatty(): tty.msg("%d installed packages." % len(specs)) - display_specs(specs, mode=args.mode, + display_specs(specs, + mode=args.mode, long=args.long, very_long=args.very_long, show_flags=args.show_flags) -- cgit v1.2.3-60-g2f50