From 99c9365974c4a4e282b7e988bb1942c19129cb02 Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Fri, 6 Dec 2019 12:29:57 -0800 Subject: Bugfix: spack find -p fails in environment (#13972) * force spack find -p to print abstract specs without prefixes * hashes have the same issue; improve handling of find -L to match find -l --- lib/spack/spack/cmd/__init__.py | 3 +++ lib/spack/spack/cmd/find.py | 8 +++++++- lib/spack/spack/test/cmd/find.py | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index 0d2e92940b..87526e32d9 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -212,6 +212,9 @@ def disambiguate_spec(spec, env, local=False, installed=True): def gray_hash(spec, length): + if not length: + # default to maximum hash length + length = 32 h = spec.dag_hash(length) if spec.concrete else '-' * length return colorize('@K{%s}' % h) diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py index 37cfcd30d5..65946e2a4c 100644 --- a/lib/spack/spack/cmd/find.py +++ b/lib/spack/spack/cmd/find.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) from __future__ import print_function +import copy import llnl.util.tty as tty import llnl.util.tty.color as color @@ -166,11 +167,16 @@ def display_env(env, args, decorator): else: tty.msg('Root specs') + # Root specs cannot be displayed with prefixes, since those are not + # set for abstract specs. Same for hashes + root_args = copy.copy(args) + root_args.paths = False + # Roots are displayed with variants, etc. so that we can see # specifically what the user asked for. cmd.display_specs( env.user_specs, - args, + root_args, decorator=lambda s, f: color.colorize('@*{%s}' % f), namespace=True, show_flags=True, diff --git a/lib/spack/spack/test/cmd/find.py b/lib/spack/spack/test/cmd/find.py index 45b065fce9..fe29d12d59 100644 --- a/lib/spack/spack/test/cmd/find.py +++ b/lib/spack/spack/test/cmd/find.py @@ -12,9 +12,12 @@ import spack.cmd.find from spack.main import SpackCommand from spack.spec import Spec from spack.util.pattern import Bunch +import spack.environment as ev find = SpackCommand('find') +env = SpackCommand('env') +install = SpackCommand('install') base32_alphabet = 'abcdefghijklmnopqrstuvwxyz234567' @@ -302,3 +305,16 @@ def test_find_no_sections(database, config): def test_find_command_basic_usage(database): output = find() assert 'mpileaks' in output + + +@pytest.mark.regression('9875') +def test_find_prefix_in_env(mutable_mock_env_path, install_mockery, mock_fetch, + mock_packages, mock_archive, config): + """Test `find` formats requiring concrete specs work in environments.""" + env('create', 'test') + with ev.read('test'): + install('mpileaks') + find('-p') + find('-l') + find('-L') + # Would throw error on regression -- cgit v1.2.3-70-g09d2