Skip to content

Commit

Permalink
FIX-#3549: make import botocore optional (#3550)
Browse files Browse the repository at this point in the history
Co-authored-by: Devin Petersohn <devin-petersohn@users.noreply.github.com>
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev and devin-petersohn authored Oct 19, 2021
1 parent b853c51 commit adc15c6
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions modin/core/io/file_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,21 @@ def __enter__(self):
fsspec.core.OpenFile
The opened file.
"""
from botocore.exceptions import NoCredentialsError
try:
from botocore.exceptions import NoCredentialsError

credential_error_type = (NoCredentialsError,)
except ModuleNotFoundError:
credential_error_type = ()

args = (self.file_path, self.mode, self.compression)

self.file = fsspec.open(*args, anon=False)
try:
self.file = fsspec.open(
self.file_path, self.mode, self.compression, anon=False
)
return self.file.open()
except NoCredentialsError:
self.file = fsspec.open(
self.file_path, self.mode, self.compression, anon=True
)
return self.file.open()
except credential_error_type:
self.file = fsspec.open(*args, anon=True)
return self.file.open()

def __exit__(self, *args):
"""
Expand Down

0 comments on commit adc15c6

Please sign in to comment.