Skip to content

Commit

Permalink
Logging loading filesystems failures. (#31219)
Browse files Browse the repository at this point in the history
* Logging loading  filesystems failures.

---------

Co-authored-by: tvalentyn <[email protected]>
  • Loading branch information
RyuSA and tvalentyn authored May 21, 2024
1 parent 675dab2 commit 1a52285
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions sdks/python/apache_beam/io/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# pytype: skip-file

import logging
import re
from typing import BinaryIO # pylint: disable=unused-import

Expand All @@ -27,6 +28,8 @@
from apache_beam.io.filesystem import FileSystem
from apache_beam.options.value_provider import RuntimeValueProvider

_LOGGER = logging.getLogger(__name__)

# All filesystem implements should be added here as
# best effort imports. We don't want to force loading
# a module if the user doesn't supply the correct
Expand All @@ -35,28 +38,60 @@
# pylint: disable=wrong-import-position, unused-import
try:
from apache_beam.io.hadoopfilesystem import HadoopFileSystem
except ImportError:
except ModuleNotFoundError:
# optional file system packages are not installed.
pass
except ImportError as e:
_LOGGER.warning(
'Failed to import HadoopFileSystem; '
'loading of this filesystem will be skipped. '
'Error details: %s',
e)

try:
from apache_beam.io.localfilesystem import LocalFileSystem
except ImportError:
except ModuleNotFoundError:
pass
except ImportError as e:
# optional file system packages are installed but failed to load.
_LOGGER.warning(
'Failed to import LocalFileSystem; '
'loading of this filesystem will be skipped. '
'Error details: %s',
e)

try:
from apache_beam.io.gcp.gcsfilesystem import GCSFileSystem
except ImportError:
except ModuleNotFoundError:
pass
except ImportError as e:
_LOGGER.warning(
'Failed to import GCSFileSystem; '
'loading of this filesystem will be skipped. '
'Error details: %s',
e)

try:
from apache_beam.io.aws.s3filesystem import S3FileSystem
except ImportError:
except ModuleNotFoundError:
pass
except ImportError as e:
_LOGGER.warning(
'Failed to import S3FileSystem; '
'loading of this filesystem will be skipped. '
'Error details: %s',
e)

try:
from apache_beam.io.azure.blobstoragefilesystem import BlobStorageFileSystem
except ImportError:
except ModuleNotFoundError:
pass
except ImportError as e:
_LOGGER.warning(
'Failed to import BlobStorageFileSystem; '
'loading of this filesystem will be skipped. '
'Error details: %s',
e)

# pylint: enable=wrong-import-position, unused-import

Expand Down

0 comments on commit 1a52285

Please sign in to comment.