KevinGG commented on a change in pull request #16601:
URL: https://github.com/apache/beam/pull/16601#discussion_r794971249
##########
File path:
sdks/python/apache_beam/runners/interactive/interactive_environment.py
##########
@@ -29,15 +29,22 @@
import logging
import os
import tempfile
+import warnings
from collections.abc import Iterable
+from pathlib import PurePath
import apache_beam as beam
+from apache_beam.pipeline import Pipeline
+from apache_beam.runners import DataflowRunner
from apache_beam.runners import runner
+from apache_beam.runners.direct import direct_runner
from apache_beam.runners.interactive import cache_manager as cache
+from apache_beam.runners.interactive.interactive_runner import
InteractiveRunner
Review comment:
I would recommend moving this import to where it's used instead of
putting it at the top of the module to avoid a dependency loop between this
module and the interactive_runner module.
##########
File path: sdks/python/apache_beam/runners/interactive/utils.py
##########
@@ -427,3 +430,34 @@ def create_var_in_main(name: str,
from apache_beam.runners.interactive import interactive_environment as ie
ie.current_env().watch({name: value})
return name, value
+
+
+def assert_bucket_exists(bucket_name):
+ # type: (str) -> None
+
+ """Asserts whether the specified GCS bucket with the name
+ bucket_name exists.
+
+ Logs an error and raises a ValueError if the bucket does not exist.
+
+ Logs a warning if the bucket cannot be verified to exist.
+ """
+ try:
+ from apitools.base.py.exceptions import HttpError
+ storage_client = storage.StorageV1(
+ credentials=auth.get_service_credentials(),
+ get_credentials=False,
+ http=get_new_http(),
+ response_encoding='utf8')
+ request = storage.StorageBucketsGetRequest(bucket=bucket_name)
+ storage_client.buckets.Get(request)
+ except HttpError as e:
+ if e.status_code == 404:
+ _LOGGER.error('%s bucket does not exist!', bucket_name)
+ raise ValueError('Invalid GCS bucket provided!')
+ else:
+ _LOGGER.warning(
+ 'HttpError - unable to verify whether bucket %s exists', bucket_name)
+ except ImportError as e:
+ _LOGGER.warning(
+ 'HttpError - unable to verify whether bucket %s exists', bucket_name)
Review comment:
Make this ImportError so that it's differentiated from the other
execution route.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]