99from datetime import datetime
1010from enum import Enum
1111
12- import boto3
13- from boto3 .s3 .transfer import TransferConfig
14- from botocore .config import Config as BotocoreConfig
15-
1612# pylint: disable=unused-import
17- from botocore .exceptions import ClientError as CloudFileNotFoundError
1813from pydantic .v1 import BaseModel , Field
1914
2015from ..environment import Env
@@ -43,9 +38,14 @@ def __call__(self, bytes_chunk_transferred):
4338 pass
4439
4540
46- def _get_dynamic_upload_config (file_size ) -> TransferConfig :
41+ def _get_dynamic_upload_config (file_size ):
4742 # pylint: disable=invalid-name
4843 # Constant definition: https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html
44+
45+ from boto3 .s3 .transfer import ( # pylint: disable=import-outside-toplevel
46+ TransferConfig ,
47+ )
48+
4949 MIN_CHUNK_SIZE = 5 * 1024 * 1024
5050 MAX_PART_COUNT = 100000
5151
@@ -143,6 +143,10 @@ def get_client(self):
143143 Get s3 client.
144144 :return:
145145 """
146+ # pylint: disable=import-outside-toplevel
147+ from boto3 import client
148+ from botocore .config import Config as BotocoreConfig
149+
146150 # pylint: disable=no-member
147151 kwargs = {
148152 "region_name" : self .user_credential .region ,
@@ -155,7 +159,7 @@ def get_client(self):
155159 if Env .current .s3_endpoint_url is not None :
156160 kwargs ["endpoint_url" ] = Env .current .s3_endpoint_url
157161
158- return boto3 . client ("s3" , ** kwargs )
162+ return client ("s3" , ** kwargs )
159163
160164 def is_expired (self ):
161165 """
@@ -335,7 +339,7 @@ def _call_back(bytes_in_chunk):
335339 Config = _get_dynamic_upload_config (os .path .getsize (file_name )),
336340 )
337341
338- # pylint: disable=too-many-arguments
342+ # pylint: disable=too-many-arguments, too-many-locals
339343 def download_file (
340344 self ,
341345 resource_id : str ,
@@ -357,6 +361,8 @@ def download_file(
357361 :param progress_callback: provide custom callback for progress
358362 :return:
359363 """
364+ # pylint: disable=import-outside-toplevel
365+ from botocore .exceptions import ClientError as CloudFileNotFoundError
360366
361367 to_file = get_local_filename_and_create_folders (remote_file_name , to_file , to_folder )
362368 if os .path .exists (to_file ) and not overwrite :
0 commit comments