fs: get rid of CallbackMixin in azure/gs/hdfs/webhdfs

No longer needed, as all of those filesystems already support callbacks.
This commit is contained in:
Ruslan Kuprieiev
2022-04-18 17:34:06 +03:00
parent 70b57d4703
commit 55219e9089
5 changed files with 8 additions and 47 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ from dvc.exceptions import DvcException
from dvc.scheme import Schemes
from dvc.utils import format_link
from .fsspec_wrapper import CallbackMixin, ObjectFSWrapper
from .fsspec_wrapper import ObjectFSWrapper
logger = logging.getLogger(__name__)
_DEFAULT_CREDS_STEPS = (
@@ -38,7 +38,7 @@ def _az_config():
# pylint:disable=abstract-method
class AzureFileSystem(CallbackMixin, ObjectFSWrapper):
class AzureFileSystem(ObjectFSWrapper):
scheme = Schemes.AZURE
PARAM_CHECKSUM = "etag"
REQUIRES = {
-39
View File
@@ -1,9 +1,7 @@
import os
import shutil
from typing import IO, TYPE_CHECKING, Any, Dict, Iterator, Optional, overload
from funcy import cached_property
from tqdm.utils import CallbackIOWrapper
from ._callback import DEFAULT_CALLBACK
from .base import FileSystem
@@ -218,40 +216,3 @@ class NoDirectoriesMixin:
def ls(self, *args, **kwargs):
raise NotImplementedError
class CallbackMixin:
"""Provides callback support for the filesystem that don't support yet."""
def put_file(
self,
from_file,
to_info,
callback=DEFAULT_CALLBACK,
**kwargs,
):
"""Add compatibility support for Callback."""
# pylint: disable=protected-access
self.makedirs(self.path.parent(to_info))
size = os.path.getsize(from_file)
with open(from_file, "rb") as fobj:
callback.set_size(size)
wrapped = CallbackIOWrapper(callback.relative_update, fobj)
self.upload_fobj(wrapped, to_info)
self.fs.invalidate_cache(self.path.parent(to_info))
def get_file(
self,
from_info,
to_info,
callback=DEFAULT_CALLBACK,
**kwargs,
):
# pylint: disable=protected-access
total: int = self.getsize(from_info)
if total:
callback.set_size(total)
with self.open(from_info, "rb") as fobj, open(to_info, "wb") as fdest:
wrapped = CallbackIOWrapper(callback.relative_update, fobj)
shutil.copyfileobj(wrapped, fdest, length=fobj.blocksize)
+2 -2
View File
@@ -5,10 +5,10 @@ from funcy import cached_property, wrap_prop
from dvc.scheme import Schemes
# pylint:disable=abstract-method
from .fsspec_wrapper import CallbackMixin, ObjectFSWrapper
from .fsspec_wrapper import ObjectFSWrapper
class GSFileSystem(CallbackMixin, ObjectFSWrapper):
class GSFileSystem(ObjectFSWrapper):
scheme = Schemes.GS
REQUIRES = {"gcsfs": "gcsfs"}
PARAM_CHECKSUM = "etag"
+2 -2
View File
@@ -8,13 +8,13 @@ from funcy import cached_property, wrap_prop
from dvc.scheme import Schemes
from dvc.utils import fix_env
from .fsspec_wrapper import CallbackMixin, FSSpecWrapper
from .fsspec_wrapper import FSSpecWrapper
CHECKSUM_REGEX = re.compile(r".*\t.*\t(?P<checksum>.*)")
# pylint: disable=abstract-method
class HDFSFileSystem(CallbackMixin, FSSpecWrapper):
class HDFSFileSystem(FSSpecWrapper):
scheme = Schemes.HDFS
REQUIRES = {"fsspec": "fsspec", "pyarrow": "pyarrow"}
PARAM_CHECKSUM = "checksum"
+2 -2
View File
@@ -5,10 +5,10 @@ from funcy import cached_property, wrap_prop
from dvc.scheme import Schemes
# pylint:disable=abstract-method
from .fsspec_wrapper import CallbackMixin, FSSpecWrapper
from .fsspec_wrapper import FSSpecWrapper
class WebHDFSFileSystem(CallbackMixin, FSSpecWrapper):
class WebHDFSFileSystem(FSSpecWrapper):
scheme = Schemes.WEBHDFS
REQUIRES = {"fsspec": "fsspec"}
PARAM_CHECKSUM = "checksum"