Skip to content

Commit

Permalink
fs.utils.transfer: remove tqdm progress bars
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed May 3, 2022
1 parent 8a0c568 commit 5067e1f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
25 changes: 18 additions & 7 deletions dvc/data/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dvc import prompt
from dvc.exceptions import CacheLinkError, CheckoutError, ConfirmRemoveError
from dvc.fs._callback import FsspecCallback
from dvc.fs.utils import test_links, transfer
from dvc.ignore import DvcIgnoreFilter
from dvc.types import Optional
Expand Down Expand Up @@ -52,7 +53,6 @@ def _checkout_file(
change,
cache,
force,
progress_callback=None,
relink=False,
state=None,
):
Expand Down Expand Up @@ -92,9 +92,6 @@ def _checkout_file(
if state:
state.save(fs_path, fs, change.new.oid)

if progress_callback:
progress_callback(fs_path)

return modified


Expand Down Expand Up @@ -132,13 +129,26 @@ def __init__(self, links):
self._links = links

@slow_link_guard
def __call__(self, cache, from_path, to_fs, to_path):
def __call__(self, cache, from_path, to_fs, to_path, callback=None):
if to_fs.exists(to_path):
to_fs.remove(to_path) # broken symlink

cache.makedirs(cache.fs.path.parent(to_path))
try:
transfer(cache.fs, from_path, to_fs, to_path, links=self._links)
with FsspecCallback.as_tqdm_callback(
callback,
desc=cache.fs.path.name(from_path),
bytes=True,
total=-1,
) as cb:
transfer(
cache.fs,
from_path,
to_fs,
to_path,
links=self._links,
callback=cb,
)
except FileNotFoundError as exc:
raise CheckoutError([to_path]) from exc
except OSError as exc:
Expand Down Expand Up @@ -190,10 +200,11 @@ def _checkout(
change,
cache,
force,
progress_callback,
relink,
state=state,
)
if progress_callback:
progress_callback(entry_path)
except CheckoutError as exc:
failed.extend(exc.target_infos)

Expand Down
6 changes: 5 additions & 1 deletion dvc/data/db/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ..reference import ReferenceHashFile

if TYPE_CHECKING:
from dvc.fs._callback import FsspecCallback
from dvc.fs.base import AnyFSPath, FileSystem
from dvc.hash_info import HashInfo

Expand Down Expand Up @@ -57,16 +58,19 @@ def _add_file(
to_info: "AnyFSPath",
hash_info: "HashInfo",
hardlink: bool = False,
callback: "FsspecCallback" = None,
):
self.makedirs(self.fs.path.parent(to_info))
if hash_info.isdir:
return super()._add_file(
from_fs,
from_info,
to_info,
hash_info,
hardlink=hardlink,
callback=callback,
)

self.makedirs(self.fs.path.parent(to_info))
ref_file = ReferenceHashFile(from_info, from_fs, hash_info)
self._obj_cache[hash_info] = ref_file
try:
Expand Down
15 changes: 6 additions & 9 deletions dvc/fs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

from dvc.utils.fs import as_atomic

from ._callback import DEFAULT_CALLBACK, FsspecCallback
from ._callback import DEFAULT_CALLBACK
from .base import RemoteActionNotImplemented
from .local import LocalFileSystem

if TYPE_CHECKING:
from ._callback import FsspecCallback
from .base import AnyFSPath, FileSystem

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -93,7 +94,7 @@ def transfer(
to_path: "AnyFSPath",
hardlink: bool = False,
links: Optional[List["str"]] = None,
callback: "FsspecCallback" = None,
callback: "FsspecCallback" = DEFAULT_CALLBACK,
) -> None:
try:
assert not (hardlink and links)
Expand All @@ -102,13 +103,9 @@ def transfer(
else:
links = links or ["reflink", "copy"]

with FsspecCallback.as_tqdm_callback(
callback,
desc=from_fs.path.name(from_path),
bytes=True,
total=-1,
) as cb:
_try_links(links, from_fs, from_path, to_fs, to_path, callback=cb)
_try_links(
links, from_fs, from_path, to_fs, to_path, callback=callback
)
except OSError as exc:
# If the target file already exists, we are going to simply
# ignore the exception (#4992).
Expand Down
24 changes: 21 additions & 3 deletions dvc/objects/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
if TYPE_CHECKING:
from typing import Tuple

from dvc.fs._callback import FsspecCallback
from dvc.fs.base import AnyFSPath, FileSystem
from dvc.hash_info import HashInfo

Expand Down Expand Up @@ -91,8 +92,10 @@ def _add_file(
to_info: "AnyFSPath",
_hash_info: "HashInfo",
hardlink: bool = False,
callback: "FsspecCallback" = None,
):
from dvc import fs
from dvc.fs._callback import FsspecCallback

self.makedirs(self.fs.path.parent(to_info))
return fs.utils.transfer(
Expand All @@ -101,6 +104,7 @@ def _add_file(
self.fs,
to_info,
hardlink=hardlink,
callback=FsspecCallback.as_callback(callback),
)

def add(
Expand All @@ -110,7 +114,10 @@ def add(
hash_info: "HashInfo",
hardlink: bool = False,
verify: Optional[bool] = None,
callback: "FsspecCallback" = None,
):
from dvc.fs._callback import FsspecCallback

if self.read_only:
raise ObjectDBPermissionError("Cannot add to read-only ODB")

Expand All @@ -123,9 +130,20 @@ def add(
pass

cache_fs_path = self.hash_to_path(hash_info.value)
self._add_file(
fs, fs_path, cache_fs_path, hash_info, hardlink=hardlink
)
with FsspecCallback.as_tqdm_callback(
callback,
desc=fs.path.name(fs_path),
bytes=True,
total=-1,
) as cb:
self._add_file(
fs,
fs_path,
cache_fs_path,
hash_info,
hardlink=hardlink,
callback=cb,
)

try:
if verify:
Expand Down

0 comments on commit 5067e1f

Please sign in to comment.