diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/__init__.py | 9 | ||||
-rw-r--r-- | lib/spack/spack/cmd/find.py | 66 | ||||
-rw-r--r-- | lib/spack/spack/spec.py | 2 |
3 files changed, 58 insertions, 19 deletions
diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index 023b7ae73e..00e30a551d 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -336,6 +336,7 @@ def display_specs(specs, args=None, **kwargs): groups (bool): display specs grouped by arch/compiler (default True) decorator (typing.Callable): function to call to decorate specs all_headers (bool): show headers even when arch/compiler aren't defined + status_fn (typing.Callable): if provided, prepend install-status info output (typing.IO): A file object to write to. Default is ``sys.stdout`` """ @@ -359,6 +360,7 @@ def display_specs(specs, args=None, **kwargs): groups = get_arg("groups", True) all_headers = get_arg("all_headers", False) output = get_arg("output", sys.stdout) + status_fn = get_arg("status_fn", None) decorator = get_arg("decorator", None) if decorator is None: @@ -386,6 +388,13 @@ def display_specs(specs, args=None, **kwargs): def fmt(s, depth=0): """Formatter function for all output specs""" string = "" + + if status_fn: + # This was copied from spec.tree's colorization logic + # then shortened because it seems like status_fn should + # always return an InstallStatus + string += colorize(status_fn(s).value) + if hashes: string += gray_hash(s, hlen) + " " string += depth * " " diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py index c4e2c77552..d09b2d8423 100644 --- a/lib/spack/spack/cmd/find.py +++ b/lib/spack/spack/cmd/find.py @@ -47,6 +47,10 @@ def setup_parser(subparser): ) subparser.add_argument( + "-I", "--install-status", action="store_true", help="show install status of packages" + ) + + subparser.add_argument( "-d", "--deps", action="store_true", help="output dependencies along with found specs" ) @@ -293,25 +297,24 @@ def display_env(env, args, decorator, results): ) print() - if args.show_concretized: - tty.msg("Concretized roots") - cmd.display_specs(env.specs_by_hash.values(), args, decorator=decorator) - print() - - # Display a header for the installed packages section IF there are installed - # packages. If there aren't any, we'll just end up printing "0 installed packages" - # later. - if results and not args.only_roots: - tty.msg("Installed packages") - def find(parser, args): - q_args = query_arguments(args) - results = args.specs(**q_args) - env = ev.active_environment() + if not env and args.only_roots: tty.die("-r / --only-roots requires an active environment") + if not env and args.show_concretized: + tty.die("-c / --show-concretized requires an active environment") + + if env: + if args.constraint: + init_specs = spack.cmd.parse_specs(args.constraint) + results = env.all_matching_specs(*init_specs) + else: + results = env.all_specs() + else: + q_args = query_arguments(args) + results = args.specs(**q_args) decorator = make_env_decorator(env) if env else lambda s, f: f @@ -332,6 +335,11 @@ def find(parser, args): if args.loaded: results = spack.cmd.filter_loaded_specs(results) + if args.install_status or args.show_concretized: + status_fn = spack.spec.Spec.install_status + else: + status_fn = None + # Display the result if args.json: cmd.display_specs_as_json(results, deps=args.deps) @@ -340,12 +348,34 @@ def find(parser, args): if env: display_env(env, args, decorator, results) - count_suffix = " (not shown)" if not args.only_roots: - cmd.display_specs(results, args, decorator=decorator, all_headers=True) - count_suffix = "" + display_results = results + if not args.show_concretized: + display_results = list(x for x in results if x.installed) + cmd.display_specs( + display_results, args, decorator=decorator, all_headers=True, status_fn=status_fn + ) # print number of installed packages last (as the list may be long) if sys.stdout.isatty() and args.groups: + installed_suffix = "" + concretized_suffix = " to be installed" + + if args.only_roots: + installed_suffix += " (not shown)" + concretized_suffix += " (not shown)" + else: + if env and not args.show_concretized: + concretized_suffix += " (show with `spack find -c`)" + pkg_type = "loaded" if args.loaded else "installed" - spack.cmd.print_how_many_pkgs(results, pkg_type, suffix=count_suffix) + spack.cmd.print_how_many_pkgs( + list(x for x in results if x.installed), pkg_type, suffix=installed_suffix + ) + + if env: + spack.cmd.print_how_many_pkgs( + list(x for x in results if not x.installed), + "concretized", + suffix=concretized_suffix, + ) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 78477a8894..d35163c638 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -4650,7 +4650,7 @@ class Spec: spec_str = " ^".join(root_str + sorted_dependencies) return spec_str.strip() - def install_status(self): + def install_status(self) -> InstallStatus: """Helper for tree to print DB install status.""" if not self.concrete: return InstallStatus.absent |