New option "--first" for "spack location" (#36283)
This commit is contained in:
parent
a2ea30aceb
commit
ebb40ee0d1
@ -76,6 +76,14 @@ def setup_parser(subparser):
|
|||||||
help="location of the named or current environment",
|
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"])
|
arguments.add_common_arguments(subparser, ["spec"])
|
||||||
|
|
||||||
|
|
||||||
@ -121,7 +129,7 @@ def location(parser, args):
|
|||||||
# install_dir command matches against installed specs.
|
# install_dir command matches against installed specs.
|
||||||
if args.install_dir:
|
if args.install_dir:
|
||||||
env = ev.active_environment()
|
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)
|
print(spec.prefix)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -37,6 +37,15 @@ def mock_spec():
|
|||||||
shutil.rmtree(s.package.stage.path)
|
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):
|
def test_location_build_dir(mock_spec):
|
||||||
"""Tests spack location --build-dir."""
|
"""Tests spack location --build-dir."""
|
||||||
spec, pkg = mock_spec
|
spec, pkg = mock_spec
|
||||||
|
@ -590,7 +590,7 @@ _spack_buildcache_rebuild_index() {
|
|||||||
_spack_cd() {
|
_spack_cd() {
|
||||||
if $list_options
|
if $list_options
|
||||||
then
|
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
|
else
|
||||||
_all_packages
|
_all_packages
|
||||||
fi
|
fi
|
||||||
@ -1243,7 +1243,7 @@ _spack_load() {
|
|||||||
_spack_location() {
|
_spack_location() {
|
||||||
if $list_options
|
if $list_options
|
||||||
then
|
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
|
else
|
||||||
_all_packages
|
_all_packages
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user