Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progress: add postfix info to avoid overwriting desc #3721

Merged
merged 3 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions dvc/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ class Tqdm(tqdm):

BAR_FMT_DEFAULT = (
"{percentage:3.0f}% {desc}|{bar}|"
"{n_fmt}/{total_fmt}"
" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]"
"{postfix[info]}{n_fmt}/{total_fmt}"
" [{elapsed}<{remaining}, {rate_fmt:>11}]"
)
# nested bars should have fixed bar widths to align nicely
BAR_FMT_DEFAULT_NESTED = (
"{percentage:3.0f}%|{bar:10}|{desc:{ncols_desc}.{ncols_desc}}"
"{n_fmt}/{total_fmt}"
" [{elapsed}<{remaining}, {rate_fmt:>11}{postfix}]"
"{postfix[info]}{n_fmt}/{total_fmt}"
" [{elapsed}<{remaining}, {rate_fmt:>11}]"
)
BAR_FMT_NOTOTAL = (
"{desc:{ncols_desc}.{ncols_desc}}{n_fmt}"
" [{elapsed}, {rate_fmt:>11}{postfix}]"
"{desc}{bar:b}|{postfix[info]}{n_fmt} [{elapsed}, {rate_fmt:>11}]"
)
BYTES_DEFAULTS = dict(
unit="B", unit_scale=True, unit_divisor=1024, miniters=1
Expand All @@ -47,6 +46,7 @@ def __init__(
bytes=False, # pylint: disable=W0622
file=None,
total=None,
postfix=None,
**kwargs
):
"""
Expand All @@ -68,7 +68,6 @@ def __init__(
kwargs.setdefault("unit_scale", total > 999 if total else True)
if file is None:
file = sys.stderr
self.desc_persist = desc
# auto-disable based on `logger.level`
if not disable:
disable = logger.getEffectiveLevel() > level
Expand All @@ -89,6 +88,7 @@ def __init__(
total=total,
**kwargs
)
self.postfix = postfix or {"info": ""}
if bar_format is None:
if self.__len__():
self.bar_format = (
Expand All @@ -102,11 +102,11 @@ def __init__(
self.bar_format = bar_format
self.refresh()

def update_desc(self, desc, n=1):
def update_msg(self, msg, n=1):
"""
Calls `set_description_str(desc)` and `update(n)`
Sets `msg` as a postfix and calls `update(n)`.
"""
self.set_description_str(desc, refresh=False)
self.postfix["info"] = " %s |" % msg
self.update(n)

def update_to(self, current, total=None):
Expand All @@ -130,25 +130,27 @@ def wrapped(*args, **kwargs):
return wrapped

def close(self):
if self.desc_persist is not None:
self.set_description_str(self.desc_persist, refresh=False)
# unknown/zero ETA
self.bar_format = self.bar_format.replace("<{remaining}", "")
# remove completed bar
self.bar_format = self.bar_format.replace("|{bar:10}|", " ")
self.postfix["info"] = ""
# remove ETA (either unknown or zero); remove completed bar
self.bar_format = self.bar_format.replace("<{remaining}", "").replace(
"|{bar:10}|", " "
)
super().close()

@property
def format_dict(self):
"""inject `ncols_desc` to fill the display width (`ncols`)"""
d = super().format_dict
ncols = d["ncols"] or 80
ncols_desc = ncols - len(self.format_meter(ncols_desc=1, **d)) + 1
ncols_desc = max(ncols_desc, 0)
if ncols_desc:
d["ncols_desc"] = ncols_desc
# assumes `bar_format` has max one of ("ncols_desc" & "ncols_info")
ncols_left = (
ncols - len(self.format_meter(ncols_desc=1, ncols_info=1, **d)) + 1
)
ncols_left = max(ncols_left, 0)
if ncols_left:
d["ncols_desc"] = d["ncols_info"] = ncols_left
else:
# work-around for zero-width description
d["ncols_desc"] = 1
d["ncols_desc"] = d["ncols_info"] = 1
d["prefix"] = ""
return d
2 changes: 1 addition & 1 deletion dvc/remote/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ def _cache_object_exists(self, checksums, jobs=None, name=None):

def exists_with_progress(path_info):
ret = self.exists(path_info)
pbar.update_desc(str(path_info))
pbar.update_msg(str(path_info))
return ret

with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor:
Expand Down
2 changes: 1 addition & 1 deletion dvc/remote/ssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def cache_exists(self, checksums, jobs=None, name=None):
) as pbar:

def exists_with_progress(chunks):
return self.batch_exists(chunks, callback=pbar.update_desc)
return self.batch_exists(chunks, callback=pbar.update_msg)

with ThreadPoolExecutor(max_workers=jobs or self.JOBS) as executor:
path_infos = [self.checksum_to_path_info(x) for x in checksums]
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ def _create_stages(repo, targets, fname, pbar=None):

stages.append(stage)
if pbar is not None:
pbar.update_desc(out)
pbar.update_msg(out)

return stages
2 changes: 1 addition & 1 deletion dvc/repo/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _checkout(
for stage, filter_info in pairs:
result = stage.checkout(
force=force,
progress_callback=pbar.update_desc,
progress_callback=pbar.update_msg,
relink=relink,
filter_info=filter_info,
)
Expand Down
4 changes: 2 additions & 2 deletions dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class TqdmGit(Tqdm):
def update_git(self, op_code, cur_count, max_count=None, message=""):
op_code = self.code2desc(op_code)
if op_code:
self.set_description_str(op_code, refresh=False)
message = (op_code + " | " + message) if message else op_code
if message:
self.set_postfix_str(message, refresh=False)
self.postfix["info"] = " {} | ".format(message)
self.update_to(cur_count, max_count)

@staticmethod
Expand Down