Skip to content

Commit 902b65c

Browse files
authored
2.0 release (#260)
* [breaking] utils: cleanup copyfile (#256) utils: cleanup copyfile * filesystem: remove fsspec version check (#257) dvc-objects cannot enforce a particular version of fsspec. It's upto dvc and dvc plugins to ensure this. * cleanup callbacks (#259) * rename to wrap_fn
1 parent b3a4b48 commit 902b65c

File tree

6 files changed

+146
-190
lines changed

6 files changed

+146
-190
lines changed

pyproject.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ classifiers = [
2222
requires-python = ">=3.8"
2323
dynamic = ["version"]
2424
dependencies = [
25-
"tqdm>=4.63.1,<5",
2625
"shortuuid>=0.5.0",
2726
"funcy>=1.14",
2827
"fsspec>=2022.10.0",
29-
"typing-extensions>=3.7.4",
30-
"packaging>=19",
3128
]
3229

3330
[project.urls]
@@ -42,11 +39,13 @@ tests = [
4239
"pytest-mock",
4340
"pytest-benchmark",
4441
"reflink",
42+
"tqdm>=4.63.1,<5",
4543
]
4644
dev = [
4745
"dvc-objects[tests]",
4846
"mypy==1.7.1",
4947
"types-tqdm",
48+
"typing-extensions>=3.7.4",
5049
]
5150

5251
[tool.setuptools.packages.find]

src/dvc_objects/fs/base.py

+19-40
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222
)
2323

2424
from fsspec.asyn import get_loop
25-
from funcy import once_per_args
2625

2726
from dvc_objects.executors import ThreadPoolExecutor, batch_coros
2827
from dvc_objects.utils import cached_property
2928

30-
from .callbacks import DEFAULT_CALLBACK, Callback
29+
from .callbacks import (
30+
DEFAULT_CALLBACK,
31+
Callback,
32+
CallbackStream,
33+
wrap_and_branch_callback,
34+
wrap_fn,
35+
)
3136
from .errors import RemoteMissingDepsError
3237

3338
if TYPE_CHECKING:
@@ -60,33 +65,6 @@ def __init__(self, link: str, fs: "FileSystem", path: str) -> None:
6065
)
6166

6267

63-
@once_per_args
64-
def check_required_version(
65-
pkg: str, dist: str = "dvc_objects", log_level=logging.WARNING
66-
):
67-
from importlib import metadata
68-
69-
from packaging.requirements import InvalidRequirement, Requirement
70-
71-
try:
72-
reqs = {
73-
r.name: r.specifier for r in map(Requirement, metadata.requires(dist) or [])
74-
}
75-
version = metadata.version(pkg)
76-
except (metadata.PackageNotFoundError, InvalidRequirement):
77-
return
78-
79-
specifier = reqs.get(pkg)
80-
if specifier and version and version not in specifier:
81-
logger.log(
82-
log_level,
83-
"'%s%s' is required, but you have %r installed which is incompatible.",
84-
pkg,
85-
specifier,
86-
version,
87-
)
88-
89-
9068
class FileSystem:
9169
sep = "/"
9270

@@ -176,7 +154,6 @@ def get_missing_deps(cls) -> List[str]:
176154
def _check_requires(self, **kwargs):
177155
from .scheme import Schemes
178156

179-
check_required_version(pkg="fsspec")
180157
missing = self.get_missing_deps()
181158
if not missing:
182159
return
@@ -367,9 +344,10 @@ def exists(
367344
loop,
368345
)
369346
return fut.result()
370-
executor = ThreadPoolExecutor(max_workers=jobs, cancel_on_error=True)
371-
with executor:
372-
return list(executor.map(callback.wrap_fn(self.fs.exists), path))
347+
348+
func = wrap_fn(callback, self.fs.exists)
349+
with ThreadPoolExecutor(max_workers=jobs, cancel_on_error=True) as executor:
350+
return list(executor.map(func, path))
373351

374352
def lexists(self, path: AnyFSPath) -> bool:
375353
return self.fs.lexists(path)
@@ -507,10 +485,11 @@ def info(self, path, callback=DEFAULT_CALLBACK, batch_size=None, **kwargs):
507485
loop,
508486
)
509487
return fut.result()
510-
executor = ThreadPoolExecutor(max_workers=jobs, cancel_on_error=True)
511-
with executor:
512-
func = partial(self.fs.info, **kwargs)
513-
return list(executor.map(callback.wrap_fn(func), path))
488+
489+
func = partial(self.fs.info, **kwargs)
490+
wrapped = wrap_fn(callback, func)
491+
with ThreadPoolExecutor(max_workers=jobs, cancel_on_error=True) as executor:
492+
return list(executor.map(wrapped, path))
514493

515494
def mkdir(
516495
self, path: AnyFSPath, create_parents: bool = True, **kwargs: Any
@@ -531,7 +510,7 @@ def put_file(
531510
if size:
532511
callback.set_size(size)
533512
if hasattr(from_file, "read"):
534-
stream = callback.wrap_attr(cast("BinaryIO", from_file))
513+
stream = cast("BinaryIO", CallbackStream(from_file, callback))
535514
self.upload_fobj(stream, to_info, size=size)
536515
else:
537516
assert isinstance(from_file, str)
@@ -602,7 +581,7 @@ def put(
602581
callback.set_size(len(from_infos))
603582
executor = ThreadPoolExecutor(max_workers=jobs, cancel_on_error=True)
604583
with executor:
605-
put_file = callback.wrap_and_branch(self.put_file)
584+
put_file = wrap_and_branch_callback(callback, self.put_file)
606585
list(executor.imap_unordered(put_file, from_infos, to_infos))
607586

608587
def get(
@@ -621,7 +600,7 @@ def get_file(rpath, lpath, **kwargs):
621600
localfs.makedirs(localfs.path.parent(lpath), exist_ok=True)
622601
self.fs.get_file(rpath, lpath, **kwargs)
623602

624-
get_file = callback.wrap_and_branch(get_file)
603+
get_file = wrap_and_branch_callback(callback, get_file)
625604

626605
if isinstance(from_info, list) and isinstance(to_info, list):
627606
from_infos: List[AnyFSPath] = from_info

0 commit comments

Comments
 (0)