progress: ignore when set_size callback is called with None (#6612)

This commit is contained in:
Batuhan Taskaya
2021-09-21 03:34:17 +03:00
committed by GitHub
parent e81c88e501
commit a478a0ea98
3 changed files with 9 additions and 26 deletions
+2 -9
View File
@@ -6,7 +6,6 @@ from functools import partialmethod
from multiprocessing import cpu_count
from typing import Any, ClassVar, Dict, FrozenSet, Optional
from funcy import cached_property
from tqdm.utils import CallbackIOWrapper
from dvc.exceptions import DvcException
@@ -223,12 +222,6 @@ class BaseFileSystem:
return False
return hash_.endswith(cls.CHECKSUM_DIR_SUFFIX)
@cached_property
def _local_fs(self):
from dvc.fs import LocalFileSystem
return LocalFileSystem()
def upload(
self,
from_info,
@@ -260,7 +253,7 @@ class BaseFileSystem:
**pbar_args,
)
stack.enter_context(pbar)
callback = pbar.as_callback(self._local_fs, from_info)
callback = pbar.as_callback()
if total:
callback.set_size(total)
@@ -317,7 +310,7 @@ class BaseFileSystem:
**pbar_kwargs,
)
stack.enter_context(pbar)
callback = pbar.as_callback(self, from_info)
callback = pbar.as_callback()
with stack:
if download_dir:
-4
View File
@@ -8,7 +8,6 @@ from tqdm.utils import CallbackIOWrapper
from dvc.progress import DEFAULT_CALLBACK
from .base import BaseFileSystem
from .local import LocalFileSystem
# pylint: disable=no-member
@@ -238,9 +237,6 @@ class NoDirectoriesMixin:
raise NotImplementedError
_LOCAL_FS = LocalFileSystem()
class CallbackMixin:
"""Provides callback support for the filesystem that don't support yet."""
+7 -13
View File
@@ -136,8 +136,8 @@ class Tqdm(tqdm):
return wrapped
def as_callback(self, fs, path_info):
return FsspecCallback(fs, path_info, self)
def as_callback(self):
return FsspecCallback(self)
def close(self):
self.postfix["info"] = ""
@@ -167,21 +167,15 @@ class Tqdm(tqdm):
class FsspecCallback(fsspec.Callback):
def __init__(self, fs, path_info, progress_bar):
self.fs = fs
self.path_info = path_info
def __init__(self, progress_bar):
self.progress_bar = progress_bar
super().__init__()
def set_size(self, size):
"""``set_size()`` is an API that might be called with ``None`` if the
information is not already present on the caller. In that case, we'll
retrieve the size from an ``info()`` call."""
if size is None:
size = self.fs.info(self.path_info)["size"]
self.progress_bar.total = size
self.progress_bar.refresh()
super().set_size(size)
if size is not None:
self.progress_bar.total = size
self.progress_bar.refresh()
super().set_size(size)
def relative_update(self, inc=1):
self.progress_bar.update(inc)