summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2023-10-16 00:08:11 +0200
committerGitHub <noreply@github.com>2023-10-15 15:08:11 -0700
commita9cfa32c34b6dbe4f41f0d7ecb809752090a56b9 (patch)
treee33a4da8496a1f01347b11719284941ace186269 /lib
parent718aa8b82f0533f65fc7afbf79eda793125bb260 (diff)
downloadspack-a9cfa32c34b6dbe4f41f0d7ecb809752090a56b9.tar.gz
spack-a9cfa32c34b6dbe4f41f0d7ecb809752090a56b9.tar.bz2
spack-a9cfa32c34b6dbe4f41f0d7ecb809752090a56b9.tar.xz
spack-a9cfa32c34b6dbe4f41f0d7ecb809752090a56b9.zip
spack checksum: handle all versions dropped better (#40530)
* spack checksum: fix error when all versions are dropped * add test
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/checksum.py2
-rw-r--r--lib/spack/spack/stage.py6
-rw-r--r--lib/spack/spack/test/cmd/checksum.py16
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/spack/spack/cmd/checksum.py b/lib/spack/spack/cmd/checksum.py
index fa969c0979..efa4a268c1 100644
--- a/lib/spack/spack/cmd/checksum.py
+++ b/lib/spack/spack/cmd/checksum.py
@@ -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:
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index c86ed1955b..90fb193a63 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -893,7 +893,9 @@ 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')}"
)
@@ -901,7 +903,7 @@ def interactive_version_filter(
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:
diff --git a/lib/spack/spack/test/cmd/checksum.py b/lib/spack/spack/test/cmd/checksum.py
index ce7784c7a1..8001334e3e 100644
--- a/lib/spack/spack/test/cmd/checksum.py
+++ b/lib/spack/spack/test/cmd/checksum.py
@@ -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")