From 06f920d138faf90e1f9b774a0cb81a4f015df07e Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 26 Aug 2019 01:25:50 +0100 Subject: [PATCH] fix unknown total progress - depends on https://github.com/tqdm/tqdm/pull/800 --- dvc/progress.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dvc/progress.py b/dvc/progress.py index c4ce7c6a2..e921677db 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -32,6 +32,11 @@ class Tqdm(tqdm): """ maximum-compatibility tqdm-based progressbars """ + BAR_FMT_DEFAULT = ( + "{percentage:3.0f}%|{bar:10}|{desc} {bar:-10b}{n}/{total}" + " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]" + ) + BAR_FMT_NOTOTAL = "{desc} {bar:b}{n} [{elapsed}11}{postfix}]" def __init__( self, @@ -40,10 +45,7 @@ class Tqdm(tqdm): bytes=False, # pylint: disable=W0622 desc_truncate=None, leave=None, - bar_format=( - "{percentage:3.0f}%|{bar:10}|{desc} {bar:-10b}{n}/{total}" - " [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]" - ), + bar_format=None, **kwargs ): """ @@ -66,6 +68,11 @@ class Tqdm(tqdm): logging.getLogger(__name__).getEffectiveLevel() >= logging.CRITICAL ) + if bar_format is None: + if kwargs.get('total', getattr(iterable, '__len__', None)) is None: + bar_format = self.BAR_FMT_NOTOTAL + else: + bar_format = self.BAR_FMT_DEFAULT super(Tqdm, self).__init__( iterable=iterable, disable=disable,