3
3
4
4
from hf_xet import PyItemProgressUpdate , PyTotalProgressUpdate
5
5
6
+ from . import is_google_colab , is_notebook
6
7
from .tqdm import tqdm
7
8
8
9
9
10
class XetProgressReporter :
10
- def __init__ (self , n_lines : int = 10 , description_width : int = 40 ):
11
+ """
12
+ Reports on progress for Xet uploads.
13
+
14
+ Shows summary progress bars when running in notebooks or GUIs, and detailed per-file progress in console environments.
15
+ """
16
+
17
+ def __init__ (self , n_lines : int = 10 , description_width : int = 30 ):
11
18
self .n_lines = n_lines
12
19
self .description_width = description_width
13
20
21
+ self .per_file_progress = is_google_colab () or not is_notebook ()
22
+
14
23
self .tqdm_settings = {
15
24
"unit" : "B" ,
16
25
"unit_scale" : True ,
17
26
"leave" : True ,
18
27
"unit_divisor" : 1000 ,
19
- "nrows" : n_lines + 3 ,
28
+ "nrows" : n_lines + 3 if self . per_file_progress else 3 ,
20
29
"miniters" : 1 ,
21
30
"bar_format" : "{l_bar}{bar}| {n_fmt:>5}B / {total_fmt:>5}B{postfix:>12}" ,
22
31
}
@@ -40,8 +49,13 @@ def __init__(self, n_lines: int = 10, description_width: int = 40):
40
49
def format_desc (self , name : str , indent : bool ) -> str :
41
50
"""
42
51
if name is longer than width characters, prints ... at the start and then the last width-3 characters of the name, otherwise
43
- the whole name right justified into 20 characters. Also adds some padding.
52
+ the whole name right justified into description_width characters. Also adds some padding.
44
53
"""
54
+
55
+ if not self .per_file_progress :
56
+ # Here we just use the defaults.
57
+ return name
58
+
45
59
padding = " " if indent else ""
46
60
width = self .description_width - len (padding )
47
61
@@ -74,6 +88,10 @@ def update_progress(self, total_update: PyTotalProgressUpdate, item_updates: Lis
74
88
self .completed_items .add (name )
75
89
new_completed .append (name )
76
90
91
+ # If we're only showing summary information, then don't update the individual bars
92
+ if not self .per_file_progress :
93
+ continue
94
+
77
95
# If we've run out of bars to use, then collapse the last ones together.
78
96
if bar_idx >= len (self .current_bars ):
79
97
bar = self .current_bars [- 1 ]
@@ -111,10 +129,11 @@ def update_progress(self, total_update: PyTotalProgressUpdate, item_updates: Lis
111
129
112
130
del self .item_state [name ]
113
131
114
- # Now manually refresh each of the bars
115
- for bar in self .current_bars :
116
- if bar :
117
- bar .refresh ()
132
+ if self .per_file_progress :
133
+ # Now manually refresh each of the bars
134
+ for bar in self .current_bars :
135
+ if bar :
136
+ bar .refresh ()
118
137
119
138
# Update overall bars
120
139
def postfix (speed ):
@@ -136,6 +155,8 @@ def postfix(speed):
136
155
def close (self , _success ):
137
156
self .data_processing_bar .close ()
138
157
self .upload_bar .close ()
139
- for bar in self .current_bars :
140
- if bar :
141
- bar .close ()
158
+
159
+ if self .per_file_progress :
160
+ for bar in self .current_bars :
161
+ if bar :
162
+ bar .close ()
0 commit comments