add: fix progress bar on single target (#6288)

This commit is contained in:
Saugat Pachhai
2021-07-06 12:28:16 +05:45
committed by GitHub
parent 6bccb21af6
commit 4b6c6a0e79
2 changed files with 12 additions and 7 deletions
+7 -4
View File
@@ -51,7 +51,7 @@ class Tqdm(tqdm):
file=None,
total=None,
postfix=None,
**kwargs
**kwargs,
):
"""
bytes : shortcut for
@@ -90,7 +90,7 @@ class Tqdm(tqdm):
bar_format="!",
lock_args=(False,),
total=total,
**kwargs
**kwargs,
)
self.postfix = postfix or {"info": ""}
if bar_format is None:
@@ -106,13 +106,16 @@ class Tqdm(tqdm):
self.bar_format = bar_format
self.refresh()
def update_msg(self, msg, n=1):
def update_msg(self, msg: str, n: int = 1) -> None:
"""
Sets `msg` as a postfix and calls `update(n)`.
"""
self.postfix["info"] = " %s |" % msg
self.set_msg(msg)
self.update(n)
def set_msg(self, msg: str) -> None:
self.postfix["info"] = f" {msg} |"
def update_to(self, current, total=None):
if total:
self.total = total
+5 -3
View File
@@ -94,14 +94,16 @@ def translate_graph_error(stages: Stages) -> Iterator[None]:
def progress_iter(stages: Stages) -> Iterator["Stage"]:
total = len(stages)
desc = "Adding..."
with ui.progress(total=total, desc=desc, unit="file", leave=True) as pbar:
with ui.progress(
stages, total=total, desc=desc, unit="file", leave=True
) as pbar:
if total == 1:
pbar.bar_format = desc
pbar.refresh()
for stage in stages:
for stage in pbar:
if total > 1:
pbar.update_msg(f"{stage.outs[0]}")
pbar.set_msg(f"{stage.outs[0]}")
yield stage
if total == 1: # restore bar format for stats
# pylint: disable=no-member