spack checksum: fix error when initial filter yields empty list (#40799)

This commit is contained in:
Harmen Stoppels 2023-10-31 15:08:41 +01:00 committed by GitHub
parent 6933e1c3cb
commit 40a5c1ff2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -893,9 +893,9 @@ def interactive_version_filter(
""" """
# Find length of longest string in the list for padding # Find length of longest string in the list for padding
version_filter = initial_verion_filter or VersionList([":"]) version_filter = initial_verion_filter or VersionList([":"])
max_len = max(len(str(v)) for v in url_dict) if url_dict else 0
sorted_and_filtered = [v for v in url_dict if v.satisfies(version_filter)] sorted_and_filtered = [v for v in url_dict if v.satisfies(version_filter)]
sorted_and_filtered.sort(reverse=True) sorted_and_filtered.sort(reverse=True)
max_len = max(len(str(v)) for v in sorted_and_filtered)
orig_url_dict = url_dict # only copy when using editor to modify orig_url_dict = url_dict # only copy when using editor to modify
print_header = True print_header = True
VERSION_COLOR = spack.spec.VERSION_COLOR VERSION_COLOR = spack.spec.VERSION_COLOR
@ -903,21 +903,20 @@ def interactive_version_filter(
if print_header: if print_header:
has_filter = version_filter != VersionList([":"]) has_filter = version_filter != VersionList([":"])
header = [] header = []
if not sorted_and_filtered: if len(orig_url_dict) > 0 and len(sorted_and_filtered) == len(orig_url_dict):
header.append("No versions selected")
elif len(sorted_and_filtered) == len(orig_url_dict):
header.append( header.append(
f"Selected {llnl.string.plural(len(sorted_and_filtered), 'version')}" f"Selected {llnl.string.plural(len(sorted_and_filtered), 'version')}"
) )
else: else:
header.append( header.append(
f"Selected {len(sorted_and_filtered)} of {len(orig_url_dict)} versions" f"Selected {len(sorted_and_filtered)} of "
f"{llnl.string.plural(len(orig_url_dict), 'version')}"
) )
if sorted_and_filtered and 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) 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')}") header.append(f"{llnl.string.plural(num_new, 'new version')}")
if has_filter: if has_filter:
header.append(colorize(f"Filtered by {VERSION_COLOR}{version_filter}@.")) header.append(colorize(f"Filtered by {VERSION_COLOR}@@{version_filter}@."))
version_with_url = [ version_with_url = [
colorize( colorize(