fixes #967, flake8 approved
This commit is contained in:
parent
fcc30cbf30
commit
23c7089789
1 changed files with 83 additions and 54 deletions
|
@ -22,66 +22,92 @@
|
||||||
# License along with this program; if not, write to the Free Software
|
# License along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import sys
|
|
||||||
import collections
|
|
||||||
import itertools
|
|
||||||
import argparse
|
import argparse
|
||||||
from StringIO import StringIO
|
import sys
|
||||||
|
|
||||||
import llnl.util.tty as tty
|
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
|
||||||
import spack.spec
|
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"
|
||||||
|
|
||||||
description ="Find installed spack packages"
|
|
||||||
|
|
||||||
def setup_parser(subparser):
|
def setup_parser(subparser):
|
||||||
format_group = subparser.add_mutually_exclusive_group()
|
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(
|
format_group.add_argument(
|
||||||
'-s', '--short', action='store_const', dest='mode', const='short',
|
'-d',
|
||||||
help='Show only specs (default)')
|
'--deps',
|
||||||
format_group.add_argument(
|
action='store_const',
|
||||||
'-p', '--paths', action='store_const', dest='mode', const='paths',
|
dest='mode',
|
||||||
help='Show paths to package install directories')
|
const='deps',
|
||||||
format_group.add_argument(
|
|
||||||
'-d', '--deps', action='store_const', dest='mode', const='deps',
|
|
||||||
help='Show full dependency DAG of installed packages')
|
help='Show full dependency DAG of installed packages')
|
||||||
|
|
||||||
subparser.add_argument(
|
subparser.add_argument('-l',
|
||||||
'-l', '--long', action='store_true', dest='long',
|
'--long',
|
||||||
help='Show dependency hashes as well as versions.')
|
action='store_true',
|
||||||
subparser.add_argument(
|
dest='long',
|
||||||
'-L', '--very-long', action='store_true', dest='very_long',
|
help='Show dependency hashes as well as versions.')
|
||||||
help='Show dependency hashes as well as versions.')
|
subparser.add_argument('-L',
|
||||||
subparser.add_argument(
|
'--very-long',
|
||||||
'-f', '--show-flags', action='store_true', dest='show_flags',
|
action='store_true',
|
||||||
help='Show spec compiler flags.')
|
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(
|
subparser.add_argument(
|
||||||
'-e', '--explicit', action='store_true',
|
'-e',
|
||||||
|
'--explicit',
|
||||||
|
action='store_true',
|
||||||
help='Show only specs that were installed explicitly')
|
help='Show only specs that were installed explicitly')
|
||||||
subparser.add_argument(
|
subparser.add_argument(
|
||||||
'-E', '--implicit', action='store_true',
|
'-E',
|
||||||
|
'--implicit',
|
||||||
|
action='store_true',
|
||||||
help='Show only specs that were installed as dependencies')
|
help='Show only specs that were installed as dependencies')
|
||||||
subparser.add_argument(
|
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.')
|
help='Show only specs Spack does not have a package for.')
|
||||||
subparser.add_argument(
|
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.')
|
help='Show missing dependencies as well as installed specs.')
|
||||||
subparser.add_argument(
|
subparser.add_argument('-M',
|
||||||
'-M', '--only-missing', action='store_true', dest='only_missing',
|
'--only-missing',
|
||||||
help='Show only missing dependencies.')
|
action='store_true',
|
||||||
subparser.add_argument(
|
dest='only_missing',
|
||||||
'-N', '--namespace', action='store_true',
|
help='Show only missing dependencies.')
|
||||||
help='Show fully qualified package names.')
|
subparser.add_argument('-N',
|
||||||
|
'--namespace',
|
||||||
|
action='store_true',
|
||||||
|
help='Show fully qualified package names.')
|
||||||
|
|
||||||
subparser.add_argument(
|
subparser.add_argument('query_specs',
|
||||||
'query_specs', nargs=argparse.REMAINDER,
|
nargs=argparse.REMAINDER,
|
||||||
help='optional specs to filter results')
|
help='optional specs to filter results')
|
||||||
|
|
||||||
|
|
||||||
def gray_hash(spec, length):
|
def gray_hash(spec, length):
|
||||||
|
@ -109,14 +135,15 @@ def display_specs(specs, **kwargs):
|
||||||
|
|
||||||
# Traverse the index and print out each package
|
# Traverse the index and print out each package
|
||||||
for i, (architecture, compiler) in enumerate(sorted(index)):
|
for i, (architecture, compiler) in enumerate(sorted(index)):
|
||||||
if i > 0: print
|
if i > 0:
|
||||||
|
print
|
||||||
|
|
||||||
header = "%s{%s} / %s{%s}" % (
|
header = "%s{%s} / %s{%s}" % (spack.spec.architecture_color,
|
||||||
spack.spec.architecture_color, architecture,
|
architecture, spack.spec.compiler_color,
|
||||||
spack.spec.compiler_color, compiler)
|
compiler)
|
||||||
tty.hline(colorize(header), char='-')
|
tty.hline(colorize(header), char='-')
|
||||||
|
|
||||||
specs = index[(architecture,compiler)]
|
specs = index[(architecture, compiler)]
|
||||||
specs.sort()
|
specs.sort()
|
||||||
|
|
||||||
abbreviated = [s.format(format_string, color=True) for s in specs]
|
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):
|
for abbrv, spec in zip(abbreviated, specs):
|
||||||
if hashes:
|
if hashes:
|
||||||
print gray_hash(spec, hlen),
|
print(gray_hash(spec, hlen), )
|
||||||
print format % (abbrv, spec.prefix)
|
print(format % (abbrv, spec.prefix))
|
||||||
|
|
||||||
elif mode == 'deps':
|
elif mode == 'deps':
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
print spec.tree(
|
print(spec.tree(
|
||||||
format=format_string,
|
format=format_string,
|
||||||
color=True,
|
color=True,
|
||||||
indent=4,
|
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':
|
elif mode == 'short':
|
||||||
# Print columns of output if not printing flags
|
# Print columns of output if not printing flags
|
||||||
if not flags:
|
if not flags:
|
||||||
|
|
||||||
def fmt(s):
|
def fmt(s):
|
||||||
string = ""
|
string = ""
|
||||||
if hashes:
|
if hashes:
|
||||||
|
@ -149,18 +177,17 @@ def fmt(s):
|
||||||
string += s.format('$-%s$@$+' % nfmt, color=True)
|
string += s.format('$-%s$@$+' % nfmt, color=True)
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
||||||
colify(fmt(s) for s in specs)
|
colify(fmt(s) for s in specs)
|
||||||
# Print one entry per line if including flags
|
# Print one entry per line if including flags
|
||||||
else:
|
else:
|
||||||
for spec in specs:
|
for spec in specs:
|
||||||
# Print the hash if necessary
|
# Print the hash if necessary
|
||||||
hsh = gray_hash(spec, hlen) + ' ' if hashes else ''
|
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:
|
else:
|
||||||
raise ValueError(
|
raise ValueError("Invalid mode for display_specs: %s. Must be one of (paths, deps, short)." % mode) # NOQA: ignore=E501
|
||||||
"Invalid mode for display_specs: %s. Must be one of (paths, deps, short)." % mode)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def find(parser, args):
|
def find(parser, args):
|
||||||
|
@ -192,13 +219,14 @@ def find(parser, args):
|
||||||
if args.implicit:
|
if args.implicit:
|
||||||
explicit = True
|
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
|
# Get all the specs the user asked for
|
||||||
if not query_specs:
|
if not query_specs:
|
||||||
specs = set(spack.installed_db.query(**q_args))
|
specs = set(spack.installed_db.query(**q_args))
|
||||||
else:
|
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)
|
specs = set.union(*results)
|
||||||
|
|
||||||
if not args.mode:
|
if not args.mode:
|
||||||
|
@ -206,7 +234,8 @@ def find(parser, args):
|
||||||
|
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
tty.msg("%d installed packages." % len(specs))
|
tty.msg("%d installed packages." % len(specs))
|
||||||
display_specs(specs, mode=args.mode,
|
display_specs(specs,
|
||||||
|
mode=args.mode,
|
||||||
long=args.long,
|
long=args.long,
|
||||||
very_long=args.very_long,
|
very_long=args.very_long,
|
||||||
show_flags=args.show_flags)
|
show_flags=args.show_flags)
|
||||||
|
|
Loading…
Reference in a new issue