Skip to content

Commit

Permalink
spack.util.elide_list -> llnl.util.lang.elide_list
Browse files Browse the repository at this point in the history
  • Loading branch information
haampie committed Aug 19, 2021
1 parent 8a4d6e7 commit c501dc3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
16 changes: 16 additions & 0 deletions lib/spack/llnl/util/lang.py
Expand Up @@ -933,3 +933,19 @@ class Devnull(object):
"""
def write(self, *_):
pass


def elide_list(line_list, max_num=10):
"""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)
gives::
[1, 2, 3, '...', 6]
"""
if len(line_list) > max_num:
return line_list[:max_num - 1] + ['...'] + line_list[-1:]
else:
return line_list
4 changes: 2 additions & 2 deletions lib/spack/spack/stage.py
Expand Up @@ -18,6 +18,7 @@

from six import iteritems, string_types

import llnl.util.lang
import llnl.util.tty as tty
from llnl.util.filesystem import (
can_access,
Expand All @@ -34,7 +35,6 @@
import spack.fetch_strategy as fs
import spack.mirror
import spack.paths
import spack.util
import spack.util.lock
import spack.util.path as sup
import spack.util.pattern as pattern
Expand Down Expand Up @@ -857,7 +857,7 @@ def get_checksums_for_versions(
tty.msg('Found {0} version{1} of {2}:'.format(
num_ver, '' if num_ver == 1 else 's', name),
'',
*spack.util.elide_list(
*llnl.util.lang.elide_list(
['{0:{1}} {2}'.format(str(v), max_len, url_dict[v])
for v in sorted_versions]))
print()
Expand Down
16 changes: 0 additions & 16 deletions lib/spack/spack/util/__init__.py
Expand Up @@ -2,19 +2,3 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)


def elide_list(line_list, max_num=10):
"""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)
gives::
[1, 2, 3, '...', 6]
"""
if len(line_list) > max_num:
return line_list[:max_num - 1] + ['...'] + line_list[-1:]
else:
return line_list

0 comments on commit c501dc3

Please sign in to comment.