@@ -30,7 +30,12 @@ class RetryableHttpError(Exception):
30
30
"""An error that indicates a function should be retried."""
31
31
32
32
def __init__ (
33
- self , error : Union [aiohttp .ClientResponseError , aiohttp .ServerDisconnectedError , aiohttp .ClientConnectionError ]
33
+ self ,
34
+ error : Union [
35
+ aiohttp .ClientResponseError ,
36
+ aiohttp .ServerDisconnectedError ,
37
+ aiohttp .ClientConnectionError ,
38
+ ],
34
39
) -> None :
35
40
"""Store the original exception."""
36
41
self .error = error
@@ -76,7 +81,12 @@ def make_safe_file_name(file_name: str) -> str:
76
81
class S3 :
77
82
"""Client for S3 operations related to deepset Cloud uploads."""
78
83
79
- def __init__ (self , concurrency : int = 120 , rate_limit : Rate = Rate (3000 , Duration .SECOND ), max_attempts : int = 5 ):
84
+ def __init__ (
85
+ self ,
86
+ concurrency : int = 120 ,
87
+ rate_limit : Rate = Rate (3000 , Duration .SECOND ),
88
+ max_attempts : int = 5 ,
89
+ ):
80
90
"""
81
91
Initialize the client.
82
92
@@ -99,8 +109,15 @@ async def __aexit__(
99
109
) -> None :
100
110
"""Exit the context manager."""
101
111
await self .connector .close ()
102
- for bucket in self .limiter .buckets ():
103
- self .limiter .dispose (bucket )
112
+
113
+ # Handle limiter cleanup based on available methods
114
+ # Support both older and newer versions of pyrate_limiter
115
+ # In version 3.7.0, the dispose method was added to the Limiter class
116
+ # See diff here: https://github.com/vutran1710/PyrateLimiter/compare/v3.6.2...master
117
+ try :
118
+ list (map (self .limiter .dispose , self .limiter .buckets ()))
119
+ except AttributeError :
120
+ pass
104
121
105
122
async def _upload_file_with_retries (
106
123
self ,
@@ -257,7 +274,9 @@ async def upload_from_memory(
257
274
return S3UploadResult (file_name = file_name , success = False , exception = exception )
258
275
259
276
async def _process_results (
260
- self , tasks : List [Coroutine [Any , Any , S3UploadResult ]], show_progress : bool = True
277
+ self ,
278
+ tasks : List [Coroutine [Any , Any , S3UploadResult ]],
279
+ show_progress : bool = True ,
261
280
) -> S3UploadSummary :
262
281
"""Summarize the results of the uploads to S3.
263
282
@@ -297,7 +316,10 @@ async def _process_results(
297
316
return result_summary
298
317
299
318
async def upload_files_from_paths (
300
- self , upload_session : UploadSession , file_paths : List [Path ], show_progress : bool = True
319
+ self ,
320
+ upload_session : UploadSession ,
321
+ file_paths : List [Path ],
322
+ show_progress : bool = True ,
301
323
) -> S3UploadSummary :
302
324
"""Upload a set of files to the prefixed S3 namespace given a list of paths.
303
325
@@ -316,7 +338,10 @@ async def upload_files_from_paths(
316
338
return result_summary
317
339
318
340
async def upload_in_memory (
319
- self , upload_session : UploadSession , files : Sequence [DeepsetCloudFileBase ], show_progress : bool = True
341
+ self ,
342
+ upload_session : UploadSession ,
343
+ files : Sequence [DeepsetCloudFileBase ],
344
+ show_progress : bool = True ,
320
345
) -> S3UploadSummary :
321
346
"""Upload a set of files to the prefixed S3 namespace given a list of paths.
322
347
@@ -326,7 +351,8 @@ async def upload_in_memory(
326
351
:return: S3UploadSummary object.
327
352
"""
328
353
async with aiohttp .ClientSession (
329
- connector = self .connector , timeout = aiohttp .ClientTimeout (total = ASYNC_CLIENT_TIMEOUT )
354
+ connector = self .connector ,
355
+ timeout = aiohttp .ClientTimeout (total = ASYNC_CLIENT_TIMEOUT ),
330
356
) as client_session :
331
357
tasks = []
332
358
@@ -339,7 +365,12 @@ async def upload_in_memory(
339
365
if file .meta is not None :
340
366
meta_name = f"{ file_name } .meta.json"
341
367
tasks .append (
342
- self .upload_from_memory (meta_name , upload_session , file .meta_as_string (), client_session )
368
+ self .upload_from_memory (
369
+ meta_name ,
370
+ upload_session ,
371
+ file .meta_as_string (),
372
+ client_session ,
373
+ )
343
374
)
344
375
345
376
result_summary = await self ._process_results (tasks , show_progress = show_progress )
0 commit comments