22
22
)
23
23
24
24
from fsspec .asyn import get_loop
25
- from funcy import once_per_args
26
25
27
26
from dvc_objects .executors import ThreadPoolExecutor , batch_coros
28
27
from dvc_objects .utils import cached_property
29
28
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
+ )
31
36
from .errors import RemoteMissingDepsError
32
37
33
38
if TYPE_CHECKING :
@@ -60,33 +65,6 @@ def __init__(self, link: str, fs: "FileSystem", path: str) -> None:
60
65
)
61
66
62
67
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
-
90
68
class FileSystem :
91
69
sep = "/"
92
70
@@ -176,7 +154,6 @@ def get_missing_deps(cls) -> List[str]:
176
154
def _check_requires (self , ** kwargs ):
177
155
from .scheme import Schemes
178
156
179
- check_required_version (pkg = "fsspec" )
180
157
missing = self .get_missing_deps ()
181
158
if not missing :
182
159
return
@@ -367,9 +344,10 @@ def exists(
367
344
loop ,
368
345
)
369
346
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 ))
373
351
374
352
def lexists (self , path : AnyFSPath ) -> bool :
375
353
return self .fs .lexists (path )
@@ -507,10 +485,11 @@ def info(self, path, callback=DEFAULT_CALLBACK, batch_size=None, **kwargs):
507
485
loop ,
508
486
)
509
487
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 ))
514
493
515
494
def mkdir (
516
495
self , path : AnyFSPath , create_parents : bool = True , ** kwargs : Any
@@ -531,7 +510,7 @@ def put_file(
531
510
if size :
532
511
callback .set_size (size )
533
512
if hasattr (from_file , "read" ):
534
- stream = callback . wrap_attr ( cast ("BinaryIO" , from_file ))
513
+ stream = cast ("BinaryIO" , CallbackStream ( from_file , callback ))
535
514
self .upload_fobj (stream , to_info , size = size )
536
515
else :
537
516
assert isinstance (from_file , str )
@@ -602,7 +581,7 @@ def put(
602
581
callback .set_size (len (from_infos ))
603
582
executor = ThreadPoolExecutor (max_workers = jobs , cancel_on_error = True )
604
583
with executor :
605
- put_file = callback . wrap_and_branch ( self .put_file )
584
+ put_file = wrap_and_branch_callback ( callback , self .put_file )
606
585
list (executor .imap_unordered (put_file , from_infos , to_infos ))
607
586
608
587
def get (
@@ -621,7 +600,7 @@ def get_file(rpath, lpath, **kwargs):
621
600
localfs .makedirs (localfs .path .parent (lpath ), exist_ok = True )
622
601
self .fs .get_file (rpath , lpath , ** kwargs )
623
602
624
- get_file = callback . wrap_and_branch ( get_file )
603
+ get_file = wrap_and_branch_callback ( callback , get_file )
625
604
626
605
if isinstance (from_info , list ) and isinstance (to_info , list ):
627
606
from_infos : List [AnyFSPath ] = from_info
0 commit comments