buildcache.py: elide string not spec (#46074)

This commit is contained in:
Harmen Stoppels 2024-08-28 15:27:44 +02:00 committed by GitHub
parent fb4811ec3f
commit 85487f23bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 7 deletions

View File

@ -843,20 +843,19 @@ def uniq(sequence):
return uniq_list
def elide_list(line_list, max_num=10):
def elide_list(line_list: List[str], max_num: int = 10) -> List[str]:
"""Takes a long list and limits it to a smaller number of elements,
replacing intervening elements with '...'. For example::
elide_list([1,2,3,4,5,6], 4)
elide_list(["1", "2", "3", "4", "5", "6"], 4)
gives::
[1, 2, 3, '...', 6]
["1", "2", "3", "...", "6"]
"""
if len(line_list) > max_num:
return line_list[: max_num - 1] + ["..."] + line_list[-1:]
else:
return line_list
return [*line_list[: max_num - 1], "...", line_list[-1]]
return line_list
@contextlib.contextmanager

View File

@ -460,7 +460,7 @@ def push_fn(args):
"The following {} specs were skipped as they already exist in the buildcache:\n"
" {}\n"
" Use --force to overwrite them.".format(
len(skipped), ", ".join(elide_list(skipped, 5))
len(skipped), ", ".join(elide_list([_format_spec(s) for s in skipped], 5))
)
)