New option "--first" for "spack location" (#36283)

This commit is contained in:
G-Ragghianti 2023-05-10 06:26:29 -04:00 committed by GitHub
parent a2ea30aceb
commit ebb40ee0d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -590,7 +590,7 @@ _spack_buildcache_rebuild_index() {
_spack_cd() {
if $list_options
then
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages --source-dir -b --build-dir -e --env"
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages --source-dir -b --build-dir -e --env --first"
else
_all_packages
fi
@ -1243,7 +1243,7 @@ _spack_load() {
_spack_location() {
if $list_options
then
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages --source-dir -b --build-dir -e --env"
SPACK_COMPREPLY="-h --help -m --module-dir -r --spack-root -i --install-dir -p --package-dir -P --packages -s --stage-dir -S --stages --source-dir -b --build-dir -e --env --first"
else
_all_packages
fi