mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-13 15:28:27 +01:00
* pre-commit: update black to 21.5b1 also updated others, but black is more noticeable * remove magic trailing comma
40 lines
787 B
Python
40 lines
787 B
Python
from funcy import is_seq
|
|
|
|
|
|
def join(words):
|
|
words = list(words)
|
|
if not words:
|
|
return ""
|
|
|
|
return (
|
|
"{before} and {after}".format(
|
|
before=", ".join(words[:-1]), after=words[-1]
|
|
)
|
|
if len(words) > 1
|
|
else words[0]
|
|
)
|
|
|
|
|
|
def get_summary(stats):
|
|
status = (
|
|
(state, len(data) if is_seq(data) else data)
|
|
for state, data in stats
|
|
if data
|
|
)
|
|
return join(
|
|
"{} file{} {}".format(num, "s" if num > 1 else "", state)
|
|
for state, num in status
|
|
)
|
|
|
|
|
|
ELLIPSIS = "…"
|
|
|
|
|
|
def truncate_text(
|
|
text: str, max_length: int, with_ellipsis: bool = True
|
|
) -> str:
|
|
if with_ellipsis and len(text) > max_length:
|
|
return text[: max_length - 1] + ELLIPSIS
|
|
|
|
return text[:max_length]
|