Skip to content

Commit

Permalink
Merge pull request #968 from epfl-scitas/find_always_zero_pkgs
Browse files Browse the repository at this point in the history
Fix : spack find
  • Loading branch information
tgamblin committed May 18, 2016
2 parents d592a16 + 23c7089 commit af77857
Showing 1 changed file with 83 additions and 54 deletions.
137 changes: 83 additions & 54 deletions lib/spack/spack/cmd/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand All @@ -128,39 +155,39 @@ 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:
string += gray_hash(s, hlen) + ' '
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):
Expand All @@ -186,27 +213,29 @@ def find(parser, args):
if args.unknown:
known = False

explicit = None
explicit = any
if args.explicit:
explicit = False
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:
args.mode = 'short'

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)

0 comments on commit af77857

Please sign in to comment.