From a9cfa32c34b6dbe4f41f0d7ecb809752090a56b9 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Mon, 16 Oct 2023 00:08:11 +0200 Subject: spack checksum: handle all versions dropped better (#40530) * spack checksum: fix error when all versions are dropped * add test --- lib/spack/spack/cmd/checksum.py | 2 +- lib/spack/spack/stage.py | 6 ++++-- lib/spack/spack/test/cmd/checksum.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) (limited to 'lib') 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") -- cgit v1.2.3-70-g09d2