summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorG-Ragghianti <33492707+G-Ragghianti@users.noreply.github.com>2023-05-10 06:26:29 -0400
committerGitHub <noreply@github.com>2023-05-10 12:26:29 +0200
commitebb40ee0d185d6ae3aa2258f4594933976c7099b (patch)
tree32910f4d616b3640a39c8742ec8082ee7a61b637 /lib
parenta2ea30aceb6b09d48d4a0c76bbadaf9bff1a5437 (diff)
downloadspack-ebb40ee0d185d6ae3aa2258f4594933976c7099b.tar.gz
spack-ebb40ee0d185d6ae3aa2258f4594933976c7099b.tar.bz2
spack-ebb40ee0d185d6ae3aa2258f4594933976c7099b.tar.xz
spack-ebb40ee0d185d6ae3aa2258f4594933976c7099b.zip
New option "--first" for "spack location" (#36283)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/location.py10
-rw-r--r--lib/spack/spack/test/cmd/location.py9
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/location.py b/lib/spack/spack/cmd/location.py
index aba8264a28..0afac01b0c 100644
--- a/lib/spack/spack/cmd/location.py
+++ b/lib/spack/spack/cmd/location.py
@@ -76,6 +76,14 @@ def setup_parser(subparser):
help="location of the named or current environment",
)
+ subparser.add_argument(
+ "--first",
+ action="store_true",
+ default=False,
+ dest="find_first",
+ help="use the first match if multiple packages match the spec",
+ )
+
arguments.add_common_arguments(subparser, ["spec"])
@@ -121,7 +129,7 @@ def location(parser, args):
# install_dir command matches against installed specs.
if args.install_dir:
env = ev.active_environment()
- spec = spack.cmd.disambiguate_spec(specs[0], env)
+ spec = spack.cmd.disambiguate_spec(specs[0], env, first=args.find_first)
print(spec.prefix)
return
diff --git a/lib/spack/spack/test/cmd/location.py b/lib/spack/spack/test/cmd/location.py
index 38d3f45619..1e42141199 100644
--- a/lib/spack/spack/test/cmd/location.py
+++ b/lib/spack/spack/test/cmd/location.py
@@ -37,6 +37,15 @@ def mock_spec():
shutil.rmtree(s.package.stage.path)
+def test_location_first(install_mockery, mock_fetch, mock_archive, mock_packages):
+ """Test with and without the --first option"""
+ install = SpackCommand("install")
+ install("libelf@0.8.12")
+ install("libelf@0.8.13")
+ # This would normally return an error without --first
+ assert location("--first", "--install-dir", "libelf")
+
+
def test_location_build_dir(mock_spec):
"""Tests spack location --build-dir."""
spec, pkg = mock_spec