11"""Amazon S3 Describe Module (INTERNAL)."""
22
3- import concurrent .futures
43import datetime
54import itertools
65import logging
98import boto3
109
1110from awswrangler import _utils
11+ from awswrangler ._distributed import engine
12+ from awswrangler ._threading import _get_executor
13+ from awswrangler .distributed .ray import ray_get
1214from awswrangler .s3 import _fs
1315from awswrangler .s3 ._list import _path2list
1416
1517_logger : logging .Logger = logging .getLogger (__name__ )
1618
1719
20+ @engine .dispatch_on_engine
1821def _describe_object (
19- path : str ,
2022 boto3_session : boto3 .Session ,
23+ path : str ,
2124 s3_additional_kwargs : Optional [Dict [str , Any ]],
2225 version_id : Optional [str ] = None ,
2326) -> Tuple [str , Dict [str , Any ]]:
@@ -40,18 +43,6 @@ def _describe_object(
4043 return path , desc
4144
4245
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-
5546def describe_objects (
5647 path : Union [str , List [str ]],
5748 version_id : Optional [Union [str , Dict [str , str ]]] = None ,
@@ -127,41 +118,22 @@ def describe_objects(
127118 last_modified_end = last_modified_end ,
128119 s3_additional_kwargs = s3_additional_kwargs ,
129120 )
121+
130122 if len (paths ) < 1 :
131123 return {}
132124 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+
165137 desc_dict : Dict [str , Dict [str , Any ]] = dict (resp_list )
166138 return desc_dict
167139
0 commit comments