1
1
"""Amazon S3 Describe Module (INTERNAL)."""
2
2
3
- import concurrent .futures
4
3
import datetime
5
4
import itertools
6
5
import logging
9
8
import boto3
10
9
11
10
from awswrangler import _utils
11
+ from awswrangler ._distributed import engine
12
+ from awswrangler ._threading import _get_executor
13
+ from awswrangler .distributed .ray import ray_get
12
14
from awswrangler .s3 import _fs
13
15
from awswrangler .s3 ._list import _path2list
14
16
15
17
_logger : logging .Logger = logging .getLogger (__name__ )
16
18
17
19
20
+ @engine .dispatch_on_engine
18
21
def _describe_object (
19
- path : str ,
20
22
boto3_session : boto3 .Session ,
23
+ path : str ,
21
24
s3_additional_kwargs : Optional [Dict [str , Any ]],
22
25
version_id : Optional [str ] = None ,
23
26
) -> Tuple [str , Dict [str , Any ]]:
@@ -40,18 +43,6 @@ def _describe_object(
40
43
return path , desc
41
44
42
45
43
- def _describe_object_concurrent (
44
- path : str ,
45
- boto3_primitives : _utils .Boto3PrimitivesType ,
46
- s3_additional_kwargs : Optional [Dict [str , Any ]],
47
- version_id : Optional [str ] = None ,
48
- ) -> Tuple [str , Dict [str , Any ]]:
49
- boto3_session = _utils .boto3_from_primitives (primitives = boto3_primitives )
50
- return _describe_object (
51
- path = path , boto3_session = boto3_session , s3_additional_kwargs = s3_additional_kwargs , version_id = version_id
52
- )
53
-
54
-
55
46
def describe_objects (
56
47
path : Union [str , List [str ]],
57
48
version_id : Optional [Union [str , Dict [str , str ]]] = None ,
@@ -127,41 +118,22 @@ def describe_objects(
127
118
last_modified_end = last_modified_end ,
128
119
s3_additional_kwargs = s3_additional_kwargs ,
129
120
)
121
+
130
122
if len (paths ) < 1 :
131
123
return {}
132
124
resp_list : List [Tuple [str , Dict [str , Any ]]]
133
- if len (paths ) == 1 :
134
- resp_list = [
135
- _describe_object (
136
- path = paths [0 ],
137
- version_id = version_id .get (paths [0 ]) if isinstance (version_id , dict ) else version_id ,
138
- boto3_session = boto3_session ,
139
- s3_additional_kwargs = s3_additional_kwargs ,
140
- )
141
- ]
142
- elif use_threads is False :
143
- resp_list = [
144
- _describe_object (
145
- path = p ,
146
- version_id = version_id .get (p ) if isinstance (version_id , dict ) else version_id ,
147
- boto3_session = boto3_session ,
148
- s3_additional_kwargs = s3_additional_kwargs ,
149
- )
150
- for p in paths
151
- ]
152
- else :
153
- cpus : int = _utils .ensure_cpu_count (use_threads = use_threads )
154
- versions = [version_id .get (p ) if isinstance (version_id , dict ) else version_id for p in paths ]
155
- with concurrent .futures .ThreadPoolExecutor (max_workers = cpus ) as executor :
156
- resp_list = list (
157
- executor .map (
158
- _describe_object_concurrent ,
159
- paths ,
160
- versions ,
161
- itertools .repeat (_utils .boto3_to_primitives (boto3_session = boto3_session )),
162
- itertools .repeat (s3_additional_kwargs ),
163
- )
164
- )
125
+
126
+ executor = _get_executor (use_threads = use_threads )
127
+ resp_list = ray_get (
128
+ executor .map (
129
+ _describe_object ,
130
+ boto3_session ,
131
+ paths ,
132
+ itertools .repeat (s3_additional_kwargs ),
133
+ [version_id .get (p ) if isinstance (version_id , dict ) else version_id for p in paths ],
134
+ )
135
+ )
136
+
165
137
desc_dict : Dict [str , Dict [str , Any ]] = dict (resp_list )
166
138
return desc_dict
167
139
0 commit comments