Skip to content

Commit

Permalink
spack checksum: handle all versions dropped better (spack#40530)
Browse files Browse the repository at this point in the history
* spack checksum: fix error when all versions are dropped

* add test
  • Loading branch information
haampie authored Oct 15, 2023
1 parent 718aa8b commit a9cfa32
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/spack/spack/cmd/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def checksum(parser, args):
filtered_url_dict = spack.stage.interactive_version_filter(
url_dict, pkg.versions, url_changes=url_changed_for_version
)
if filtered_url_dict is None:
if not filtered_url_dict:
exit(0)
url_dict = filtered_url_dict
else:
Expand Down
6 changes: 4 additions & 2 deletions lib/spack/spack/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,15 +893,17 @@ def interactive_version_filter(
if print_header:
has_filter = version_filter != VersionList([":"])
header = []
if len(sorted_and_filtered) == len(orig_url_dict):
if not sorted_and_filtered:
header.append("No versions selected")
elif len(sorted_and_filtered) == len(orig_url_dict):
header.append(
f"Selected {llnl.string.plural(len(sorted_and_filtered), 'version')}"
)
else:
header.append(
f"Selected {len(sorted_and_filtered)} of {len(orig_url_dict)} versions"
)
if known_versions:
if sorted_and_filtered and known_versions:
num_new = sum(1 for v in sorted_and_filtered if v not in known_versions)
header.append(f"{llnl.string.plural(num_new, 'new version')}")
if has_filter:
Expand Down
16 changes: 16 additions & 0 deletions lib/spack/spack/test/cmd/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ def test_checksum_interactive_quit_from_ask_each():
}


def test_checksum_interactive_nothing_left():
"""If nothing is left after interactive filtering, return an empty dict."""
input = input_from_commands("f", "@2", "c")
assert (
interactive_version_filter(
{
Version("1.1"): "https://www.example.com/pkg-1.1.tar.gz",
Version("1.0"): "https://www.example.com/pkg-1.0.tar.gz",
Version("0.9"): "https://www.example.com/pkg-0.9.tar.gz",
},
input=input,
)
== {}
)


def test_checksum_interactive_new_only():
# The 1.0 version is known already, and should be dropped on `n`.
input = input_from_commands("n", "c")
Expand Down

0 comments on commit a9cfa32

Please sign in to comment.