fixes #967, flake8 approved

This commit is contained in:
alalazo 2016-05-18 11:52:27 +02:00
parent fcc30cbf30
commit 23c7089789

View file

@ -22,65 +22,91 @@
# 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
from llnl.util.tty.colify import *
from llnl.util.tty.color import *
from llnl.util.lang import *
import spack
import spack.spec
from llnl.util.lang import *
from llnl.util.tty.colify import *
from llnl.util.tty.color import *
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',
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',
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',
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',
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',
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',
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',
subparser.add_argument('-N',
'--namespace',
action='store_true',
help='Show fully qualified package names.')
subparser.add_argument(
'query_specs', nargs=argparse.REMAINDER,
subparser.add_argument('query_specs',
nargs=argparse.REMAINDER,
help='optional specs to filter results')
@ -109,11 +135,12 @@ 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)]
@ -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 fmt(s):
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):
@ -198,7 +225,8 @@ def find(parser, args):
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)