diff --git a/dvc/commands/ls/__init__.py b/dvc/commands/ls/__init__.py index f871e0cc6..8c9fe421a 100644 --- a/dvc/commands/ls/__init__.py +++ b/dvc/commands/ls/__init__.py @@ -12,13 +12,13 @@ logger = logging.getLogger(__name__) def _format_entry(entry, fmt): - from humanize import naturalsize + from dvc.utils.humanize import naturalsize size = entry.get("size") if size is None: size = "" else: - size = naturalsize(size, gnu=True) + size = naturalsize(size) return size, fmt(entry) diff --git a/dvc/utils/humanize.py b/dvc/utils/humanize.py index e70d889f1..d7803a999 100644 --- a/dvc/utils/humanize.py +++ b/dvc/utils/humanize.py @@ -31,3 +31,11 @@ def truncate_text(text: str, max_length: int, with_ellipsis: bool = True) -> str return text[: max_length - 1] + ELLIPSIS return text[:max_length] + + +def naturalsize(value: float, base: int = 1024) -> str: + from tqdm import tqdm + + if value < base: + return f"{value:.0f}" + return tqdm.format_sizeof(value, divisor=base) diff --git a/pyproject.toml b/pyproject.toml index 8022e39f6..52257ec60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,7 +65,6 @@ dependencies = [ "tqdm<5,>=4.63.1", "voluptuous>=0.11.7", "zc.lockfile>=1.2.1", - "humanize", ] [project.optional-dependencies]