1
1
from functools import wraps
2
- from typing import TYPE_CHECKING , BinaryIO , Optional , Type , cast
3
-
4
- import fsspec
5
- from fsspec .callbacks import DEFAULT_CALLBACK , Callback , NoOpCallback
2
+ from typing import TYPE_CHECKING , BinaryIO , cast
6
3
7
4
if TYPE_CHECKING :
8
- from typing import Union
9
-
10
- from tqdm import tqdm
11
-
12
-
13
- __all__ = ["Callback" , "NoOpCallback" , "TqdmCallback" , "DEFAULT_CALLBACK" ]
5
+ import fsspec
14
6
15
7
16
8
class CallbackStream :
17
- def __init__ (self , stream , callback : Callback ):
9
+ def __init__ (self , stream , callback : "fsspec. Callback" ):
18
10
self .stream = stream
19
11
20
12
@wraps (stream .read )
@@ -29,28 +21,5 @@ def __getattr__(self, attr):
29
21
return getattr (self .stream , attr )
30
22
31
23
32
- class TqdmCallback (fsspec .callbacks .TqdmCallback ):
33
- def __init__ (
34
- self ,
35
- size : Optional [int ] = None ,
36
- value : int = 0 ,
37
- progress_bar : Optional ["tqdm" ] = None ,
38
- tqdm_cls : Optional [Type ["tqdm" ]] = None ,
39
- ** tqdm_kwargs ,
40
- ):
41
- from dvc_objects ._tqdm import Tqdm
42
-
43
- tqdm_kwargs .pop ("total" , None )
44
- super ().__init__ (
45
- tqdm_kwargs = tqdm_kwargs , tqdm_cls = tqdm_cls or Tqdm , size = size , value = value
46
- )
47
- if progress_bar is not None :
48
- self .tqdm = progress_bar
49
-
50
- def branched (self , path_1 : "Union[str, BinaryIO]" , path_2 : str , ** kwargs ):
51
- desc = path_1 if isinstance (path_1 , str ) else path_2
52
- return TqdmCallback (bytes = True , desc = desc )
53
-
54
-
55
- def wrap_file (file , callback : Callback ) -> BinaryIO :
24
+ def wrap_file (file , callback : "fsspec.Callback" ) -> BinaryIO :
56
25
return cast (BinaryIO , CallbackStream (file , callback ))
0 commit comments