@@ -91,8 +91,12 @@ def batch_run(
91
91
stdout_write : Optional [Callable ] = None ,
92
92
stderr_write : Optional [Callable ] = None ,
93
93
wrap_errs : Optional [list [Exception ]] = None ,
94
+ tqdm_position : Optional [int ] = 0 ,
95
+ tqdm_desc : Optional [str ] = None ,
94
96
** kwargs ,
95
97
):
98
+ if tqdm_position is None :
99
+ tqdm_position = 0
96
100
if len (images ) > batchsize :
97
101
return [
98
102
batch_run (
@@ -102,9 +106,17 @@ def batch_run(
102
106
post_args = post_args ,
103
107
check = check ,
104
108
wrap_errs = wrap_errs ,
109
+ tqdm_position = tqdm_position + 1 ,
110
+ tqdm_desc = tqdm_desc ,
111
+ stdout_write = stdout_write or partial (tqdm .write , file = sys .stdout ),
112
+ stderr_write = stderr_write or partial (tqdm .write , file = sys .stderr ),
105
113
** kwargs ,
106
114
)
107
- for i in range (0 , len (images ), batchsize )
115
+ for i in tqdm (
116
+ range (0 , len (images ), batchsize ),
117
+ desc = f"Batch{ ' for {tqdm_desc}' if tqdm_desc else '' } " ,
118
+ position = tqdm_position ,
119
+ )
108
120
]
109
121
110
122
if stdout_write is None :
@@ -166,6 +178,7 @@ def ect(
166
178
stdout_write : Optional [Callable ] = None ,
167
179
stderr_write : Optional [Callable ] = None ,
168
180
wrap_errs : Optional [list [Exception ]] = None ,
181
+ tqdm_position : Optional [int ] = None ,
169
182
):
170
183
if not images :
171
184
return
@@ -186,6 +199,7 @@ def ect(
186
199
stdout_write = stdout_write ,
187
200
stderr_write = stderr_write ,
188
201
wrap_errs = wrap_errs ,
202
+ tqdm_position = tqdm_position ,
189
203
)
190
204
191
205
@@ -209,6 +223,7 @@ def optipng(
209
223
stdout_write : Optional [Callable ] = None ,
210
224
stderr_write : Optional [Callable ] = None ,
211
225
wrap_errs : Optional [list [Exception ]] = None ,
226
+ tqdm_position : Optional [int ] = None ,
212
227
):
213
228
if not images :
214
229
return
@@ -225,6 +240,7 @@ def optipng(
225
240
stdout_write = stdout_write ,
226
241
stderr_write = stderr_write ,
227
242
wrap_errs = wrap_errs ,
243
+ tqdm_position = tqdm_position ,
228
244
)
229
245
230
246
@@ -241,6 +257,7 @@ def pngcrush(
241
257
stdout_write : Optional [Callable ] = None ,
242
258
stderr_write : Optional [Callable ] = None ,
243
259
wrap_errs : Optional [list [Exception ]] = None ,
260
+ tqdm_position : Optional [int ] = None ,
244
261
):
245
262
if not images :
246
263
return
@@ -276,6 +293,7 @@ def pngcrush(
276
293
stdout_write = stdout_write ,
277
294
stderr_write = stderr_write ,
278
295
wrap_errs = wrap_errs ,
296
+ tqdm_position = tqdm_position ,
279
297
)
280
298
281
299
# Replace original images with crushed images if they are smaller
@@ -296,7 +314,7 @@ def optimize(
296
314
tmpdir : Optional [Union [str , Path ]] = None ,
297
315
cleanup : Optional [bool ] = None ,
298
316
trim_printout : bool = False ,
299
- tqdm_position : Optional [ int ] = None ,
317
+ tqdm_position : int = 0 ,
300
318
tqdm_leave : Optional [bool ] = None ,
301
319
stdout_write : Optional [Callable ] = None ,
302
320
stderr_write : Optional [Callable ] = None ,
@@ -316,6 +334,7 @@ def optimize(
316
334
stdout_write = partial (tqdm .write , file = sys .stdout ),
317
335
stderr_write = partial (tqdm .write , file = sys .stderr ),
318
336
wrap_errs = wrap_errs ,
337
+ tqdm_position = tqdm_position + 1 ,
319
338
)
320
339
optipng (
321
340
* cur_images ,
@@ -324,6 +343,7 @@ def optimize(
324
343
stdout_write = stdout_write ,
325
344
stderr_write = stderr_write ,
326
345
wrap_errs = wrap_errs ,
346
+ tqdm_position = tqdm_position ,
327
347
)
328
348
pngcrush (
329
349
* cur_images ,
@@ -334,6 +354,7 @@ def optimize(
334
354
stdout_write = stdout_write ,
335
355
stderr_write = stderr_write ,
336
356
wrap_errs = wrap_errs ,
357
+ tqdm_position = tqdm_position ,
337
358
)
338
359
new_sizes = [Path (image ).stat ().st_size for image in cur_images ]
339
360
cur_images = [
0 commit comments