mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 07:18:27 +01:00
This PR gets rid of Tqdm progress bars inside `dvc.objects`. Those are replaced with multi-phase callback in `hashes_exist`, and simple callable that takes `completed` value in `odb._estimate_remote_size()`. The `odb.list_hashes_exists()` and `odb.all()` now return iterables, hence the caller has the responsibility of handling progress. This is now handled in `dvc.data` by using a custom `Tqdm` progressbar. This is ugly and is temporary, but my motivation is to remove tqdm from dvc.objects first. We can gradually get rid of these from `dvc.data` too, but that requires more knowledge about `dvc.data` and involves more design work. All in time, I guess. :)
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from dvc.progress import Tqdm
|
|
|
|
|
|
class QueryingProgress(Tqdm):
|
|
def __init__(self, iterable=None, total=None, name=None, phase="Querying"):
|
|
msg_part = "cache in " + f"'{name}'" if name else "remote cache"
|
|
msg_fmt = "{phase} " + msg_part
|
|
|
|
self._estimating_msg = msg_fmt.format(phase="Estimating size of")
|
|
self._listing_msg = msg_fmt.format(phase="Querying")
|
|
super().__init__(
|
|
iterable=iterable,
|
|
desc=msg_fmt.format(phase=phase),
|
|
total=total,
|
|
unit="files",
|
|
unit_scale=False,
|
|
bar_format=self.BAR_FMT_DEFAULT,
|
|
)
|
|
|
|
def callback(self, phase, *args):
|
|
total = args[0] if args else self.total
|
|
completed = args[1] if len(args) > 1 else self.n
|
|
desc = self.desc
|
|
if phase == "estimating":
|
|
desc = self._estimating_msg
|
|
elif phase == "querying":
|
|
desc = self._listing_msg
|
|
|
|
if desc != self.desc:
|
|
# let Tqdm take care of when to update
|
|
self.set_description_str(desc, refresh=False)
|
|
self.update_to(completed, total)
|