Add hash hint to multi-spec message (#32652)
This commit is contained in:
parent
457daf4be6
commit
54d06fca79
@ -291,18 +291,23 @@ def disambiguate_spec_from_hashes(spec, hashes, local=False, installed=True, fir
|
||||
elif first:
|
||||
return matching_specs[0]
|
||||
|
||||
elif len(matching_specs) > 1:
|
||||
ensure_single_spec_or_die(spec, matching_specs)
|
||||
|
||||
return matching_specs[0]
|
||||
|
||||
|
||||
def ensure_single_spec_or_die(spec, matching_specs):
|
||||
if len(matching_specs) <= 1:
|
||||
return
|
||||
|
||||
format_string = "{name}{@version}{%compiler}{arch=architecture}"
|
||||
args = ["%s matches multiple packages." % spec, "Matching packages:"]
|
||||
args += [
|
||||
colorize(" @K{%s} " % s.dag_hash(7)) + s.cformat(format_string)
|
||||
for s in matching_specs
|
||||
colorize(" @K{%s} " % s.dag_hash(7)) + s.cformat(format_string) for s in matching_specs
|
||||
]
|
||||
args += ["Use a more specific spec."]
|
||||
args += ["Use a more specific spec (e.g., prepend '/' to the hash)."]
|
||||
tty.die(*args)
|
||||
|
||||
return matching_specs[0]
|
||||
|
||||
|
||||
def gray_hash(spec, length):
|
||||
if not length:
|
||||
|
@ -35,7 +35,6 @@
|
||||
"""
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.link_tree import MergeConflictError
|
||||
from llnl.util.tty.color import colorize
|
||||
|
||||
import spack.cmd
|
||||
import spack.environment as ev
|
||||
@ -66,16 +65,7 @@ def squash(matching_specs):
|
||||
tty.die("Spec matches no installed packages.")
|
||||
|
||||
matching_in_view = [ms for ms in matching_specs if ms in view_specs]
|
||||
|
||||
if len(matching_in_view) > 1:
|
||||
spec_format = "{name}{@version}{%compiler}{arch=architecture}"
|
||||
args = ["Spec matches multiple packages.", "Matching packages:"]
|
||||
args += [
|
||||
colorize(" @K{%s} " % s.dag_hash(7)) + s.cformat(spec_format)
|
||||
for s in matching_in_view
|
||||
]
|
||||
args += ["Use a more specific spec."]
|
||||
tty.die(*args)
|
||||
spack.cmd.ensure_single_spec_or_die("Spec", matching_in_view)
|
||||
|
||||
return matching_in_view[0] if matching_in_view else matching_specs[0]
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
import spack.spec
|
||||
import spack.user_environment as uenv
|
||||
from spack.main import SpackCommand, SpackCommandError
|
||||
from spack.main import SpackCommand
|
||||
|
||||
load = SpackCommand("load")
|
||||
unload = SpackCommand("unload")
|
||||
@ -115,10 +115,12 @@ def test_load_first(install_mockery, mock_fetch, mock_archive, mock_packages):
|
||||
"""Test with and without the --first option"""
|
||||
install("libelf@0.8.12")
|
||||
install("libelf@0.8.13")
|
||||
# Now there are two versions of libelf
|
||||
with pytest.raises(SpackCommandError):
|
||||
# This should cause an error due to multiple versions
|
||||
load("--sh", "libelf")
|
||||
|
||||
# Now there are two versions of libelf, which should cause an error
|
||||
out = load("--sh", "libelf", fail_on_error=False)
|
||||
assert "matches multiple packages" in out
|
||||
assert "Use a more specific spec" in out
|
||||
|
||||
# Using --first should avoid the error condition
|
||||
load("--sh", "--first", "libelf")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user