diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2019-09-01 16:40:07 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2019-09-02 19:24:48 -0700 |
commit | 64af0a9874f64e058f885cac16b403868d981dc4 (patch) | |
tree | 08fe42be7e726439f87dd3565479bb203e4483fb /lib | |
parent | 9b8f1fdc40cc8a3eb6d41bef80252f46124e9047 (diff) | |
download | spack-64af0a9874f64e058f885cac16b403868d981dc4.tar.gz spack-64af0a9874f64e058f885cac16b403868d981dc4.tar.bz2 spack-64af0a9874f64e058f885cac16b403868d981dc4.tar.xz spack-64af0a9874f64e058f885cac16b403868d981dc4.zip |
command: add `spack find --format`
- spack find --format allows you to supply a format string and have specs
output in a more machine-readable way, without dedcoration
e.g.:
spack find --format "{name}-{version}-{hash}"
autoconf-2.69-icynozk7ti6h4ezzgonqe6jgw5f3ulx4
automake-1.16.1-o5v3tc77kesgonxjbmeqlwfmb5qzj7zy
bzip2-1.0.6-syohzw57v2jfag5du2x4bowziw3m5p67
...
or:
spack find --format "{hash}"
icynozk7ti6h4ezzgonqe6jgw5f3ulx4
o5v3tc77kesgonxjbmeqlwfmb5qzj7zy
syohzw57v2jfag5du2x4bowziw3m5p67
...
This is intended to make it much easier to script with `spack find`
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/__init__.py | 14 | ||||
-rw-r--r-- | lib/spack/spack/cmd/find.py | 62 |
2 files changed, 53 insertions, 23 deletions
diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index c289edc86c..b4de2a88c3 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -200,6 +200,20 @@ def gray_hash(spec, length): return colorize('@K{%s}' % h) +def display_formatted_specs(specs, format_string, deps=False): + """Print a list of specs formatted with the provided string. + + Arguments: + specs (list): list of specs to display. + deps (bool): whether to also print dependencies of specs. + """ + for spec in specs: + print(spec.format(format_string)) + if deps: + for depth, dep in spec.traverse(depth=True, root=False): + print(" " * depth, dep.format(format_string)) + + def display_specs(specs, args=None, **kwargs): """Display human readable specs with customizable formatting. diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py index 68d7a0f1d5..ef300a83cd 100644 --- a/lib/spack/spack/cmd/find.py +++ b/lib/spack/spack/cmd/find.py @@ -10,6 +10,7 @@ import llnl.util.lang import spack.environment as ev import spack.repo +import spack.cmd as cmd import spack.cmd.common.arguments as arguments from spack.cmd import display_specs from spack.util.string import plural @@ -33,11 +34,18 @@ def setup_parser(subparser): const='paths', help='show paths to package install directories') format_group.add_argument( + "--format", action="store", default=None, + help="output specs with the specified format string") + + # TODO: separate this entirely from the "mode" option -- it's + # TODO: orthogonal, but changing it for all commands that use it with + # TODO: display_spec is tricky. Also make -pd work together properly. + subparser.add_argument( '-d', '--deps', action='store_const', dest='mode', const='deps', - help='show full dependency DAG of installed packages') + help='output dependencies along with found specs') arguments.add_common_arguments( subparser, ['long', 'very_long', 'tags']) @@ -143,6 +151,26 @@ def setup_env(env): return decorator, added, roots, removed +def display_env(env, args, decorator): + tty.msg('In environment %s' % env.name) + + if not env.user_specs: + tty.msg('No root specs') + else: + tty.msg('Root specs') + # TODO: Change this to not print extraneous deps and variants + display_specs( + env.user_specs, args, + decorator=lambda s, f: color.colorize('@*{%s}' % f)) + print() + + if args.show_concretized: + tty.msg('Concretized roots') + display_specs( + env.specs_by_hash.values(), args, decorator=decorator) + print() + + def find(parser, args): q_args = query_arguments(args) results = args.specs(**q_args) @@ -168,25 +196,13 @@ def find(parser, args): results = [x for x in results if x.name in packages_with_tags] # Display the result - if env: - tty.msg('In environment %s' % env.name) - - if not env.user_specs: - tty.msg('No root specs') - else: - tty.msg('Root specs') - # TODO: Change this to not print extraneous deps and variants - display_specs( - env.user_specs, args, - decorator=lambda s, f: color.colorize('@*{%s}' % f)) - print() - - if args.show_concretized: - tty.msg('Concretized roots') - display_specs( - env.specs_by_hash.values(), args, decorator=decorator) - print() - - tty.msg("%s" % plural(len(results), 'installed package')) - - display_specs(results, args, decorator=decorator, all_headers=True) + if args.format: + cmd.display_formatted_specs( + results, args.format, deps=(args.mode == "deps")) + elif args.json: + cmd.display_specs_as_json(results, deps=(args.mode == "deps")) + else: + if env: + display_env(env, args, decorator) + tty.msg("%s" % plural(len(results), 'installed package')) + display_specs(results, args, decorator=decorator, all_headers=True) |