You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by xd...@apache.org on 2020/11/06 12:51:07 UTC

[airflow] branch master updated: Simplify string expressions (#12123)

This is an automated email from the ASF dual-hosted git repository.

xddeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new cf9437d  Simplify string expressions (#12123)
cf9437d is described below

commit cf9437d79f9658d1309e4bfe847fe63d52ec7b99
Author: Kaxil Naik <ka...@gmail.com>
AuthorDate: Fri Nov 6 12:49:48 2020 +0000

    Simplify string expressions (#12123)
    
    Black has trouble formatting strings that are too long and produces unusual sring expressions.
---
 airflow/cli/cli_parser.py                          | 10 ++++------
 airflow/cli/commands/dag_command.py                |  4 +---
 airflow/cli/commands/db_command.py                 |  2 +-
 airflow/cli/commands/user_command.py               |  2 +-
 airflow/cli/commands/webserver_command.py          |  2 +-
 airflow/providers/amazon/aws/hooks/sagemaker.py    |  2 +-
 airflow/providers/google/cloud/hooks/bigquery.py   |  4 ++--
 airflow/providers/google/cloud/hooks/cloud_sql.py  |  4 ++--
 airflow/providers/google/cloud/hooks/gcs.py        |  2 +-
 .../providers/google/cloud/operators/functions.py  |  4 +---
 .../google/cloud/operators/test_compute.py         |  2 +-
 .../marketing_platform/hooks/test_analytics.py     | 22 ++++++++++------------
 .../marketing_platform/hooks/test_display_video.py |  4 ++--
 .../marketing_platform/hooks/test_search_ads.py    | 16 ++++------------
 .../sensors/test_display_video.py                  | 12 ++++--------
 15 files changed, 36 insertions(+), 56 deletions(-)

diff --git a/airflow/cli/cli_parser.py b/airflow/cli/cli_parser.py
index 33c6a97..6868408 100644
--- a/airflow/cli/cli_parser.py
+++ b/airflow/cli/cli_parser.py
@@ -304,9 +304,7 @@ ARG_IMGCAT_DAGRUN = Arg(
 )
 ARG_SAVE_DAGRUN = Arg(
     ("--save-dagrun",),
-    help=(
-        "After completing the backfill, saves the diagram for current DAG Run to the indicated file.\n" "\n"
-    ),
+    help=("After completing the backfill, saves the diagram for current DAG Run to the indicated file.\n\n"),
 )
 
 # list_tasks
@@ -453,12 +451,12 @@ ARG_DEBUG = Arg(
 ARG_ACCESS_LOGFILE = Arg(
     ("-A", "--access-logfile"),
     default=conf.get('webserver', 'ACCESS_LOGFILE'),
-    help="The logfile to store the webserver access log. Use '-' to print to " "stderr",
+    help="The logfile to store the webserver access log. Use '-' to print to stderr",
 )
 ARG_ERROR_LOGFILE = Arg(
     ("-E", "--error-logfile"),
     default=conf.get('webserver', 'ERROR_LOGFILE'),
-    help="The logfile to store the webserver error log. Use '-' to print to " "stderr",
+    help="The logfile to store the webserver error log. Use '-' to print to stderr",
 )
 
 # scheduler
@@ -493,7 +491,7 @@ ARG_CONCURRENCY = Arg(
 )
 ARG_CELERY_HOSTNAME = Arg(
     ("-H", "--celery-hostname"),
-    help=("Set the hostname of celery worker " "if you have multiple workers on a single machine"),
+    help=("Set the hostname of celery worker if you have multiple workers on a single machine"),
 )
 ARG_UMASK = Arg(
     ("-u", "--umask"),
diff --git a/airflow/cli/commands/dag_command.py b/airflow/cli/commands/dag_command.py
index a3d1fe1..c02dd9e 100644
--- a/airflow/cli/commands/dag_command.py
+++ b/airflow/cli/commands/dag_command.py
@@ -158,9 +158,7 @@ def dag_delete(args):
     api_client = get_current_api_client()
     if (
         args.yes
-        or input(
-            "This will drop all existing records related to the specified DAG. " "Proceed? (y/n)"
-        ).upper()
+        or input("This will drop all existing records related to the specified DAG. Proceed? (y/n)").upper()
         == "Y"
     ):
         try:
diff --git a/airflow/cli/commands/db_command.py b/airflow/cli/commands/db_command.py
index 1b05bd0..cf05b03 100644
--- a/airflow/cli/commands/db_command.py
+++ b/airflow/cli/commands/db_command.py
@@ -35,7 +35,7 @@ def initdb(args):
 def resetdb(args):
     """Resets the metadata database"""
     print("DB: " + repr(settings.engine.url))
-    if args.yes or input("This will drop existing tables " "if they exist. Proceed? " "(y/n)").upper() == "Y":
+    if args.yes or input("This will drop existing tables if they exist. Proceed? (y/n)").upper() == "Y":
         db.resetdb()
     else:
         print("Cancelled")
diff --git a/airflow/cli/commands/user_command.py b/airflow/cli/commands/user_command.py
index 7536ce6..e9d5ade 100644
--- a/airflow/cli/commands/user_command.py
+++ b/airflow/cli/commands/user_command.py
@@ -189,7 +189,7 @@ def _import_users(users_list):  # pylint: disable=redefined-outer-name
         required_fields = ['username', 'firstname', 'lastname', 'email', 'roles']
         for field in required_fields:
             if not user.get(field):
-                print("Error: '{}' is a required field, but was not " "specified".format(field))
+                print(f"Error: '{field}' is a required field, but was not specified")
                 sys.exit(1)
 
         existing_user = appbuilder.sm.find_user(email=user['email'])
diff --git a/airflow/cli/commands/webserver_command.py b/airflow/cli/commands/webserver_command.py
index 1b3f913..9e82620 100644
--- a/airflow/cli/commands/webserver_command.py
+++ b/airflow/cli/commands/webserver_command.py
@@ -250,7 +250,7 @@ class GunicornMonitor(LoggingMixin):
         # to increase number of workers
         if num_workers_running < self.num_workers_expected:
             self.log.error(
-                "[%d / %d] Some workers seem to have died and gunicorn did not restart " "them as expected",
+                "[%d / %d] Some workers seem to have died and gunicorn did not restart them as expected",
                 num_ready_workers_running,
                 num_workers_running,
             )
diff --git a/airflow/providers/amazon/aws/hooks/sagemaker.py b/airflow/providers/amazon/aws/hooks/sagemaker.py
index f235816..deec6c2 100644
--- a/airflow/providers/amazon/aws/hooks/sagemaker.py
+++ b/airflow/providers/amazon/aws/hooks/sagemaker.py
@@ -215,7 +215,7 @@ class SageMakerHook(AwsBaseHook):  # pylint: disable=too-many-public-methods
             # or if s3 prefix exists in the case user provides multiple files in
             # a prefix
             raise AirflowException(
-                "The input S3 Key " "or Prefix {} does not exist in the Bucket {}".format(s3url, bucket)
+                f"The input S3 Key or Prefix {s3url} does not exist in the Bucket {bucket}"
             )
         return True
 
diff --git a/airflow/providers/google/cloud/hooks/bigquery.py b/airflow/providers/google/cloud/hooks/bigquery.py
index 3ee6008..5dde7e5 100644
--- a/airflow/providers/google/cloud/hooks/bigquery.py
+++ b/airflow/providers/google/cloud/hooks/bigquery.py
@@ -2139,7 +2139,7 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
             _validate_value(param_name, configuration['query'][param_name], param_type)
 
             if param_name == 'schemaUpdateOptions' and param:
-                self.log.info("Adding experimental 'schemaUpdateOptions': " "%s", schema_update_options)
+                self.log.info("Adding experimental 'schemaUpdateOptions': %s", schema_update_options)
 
             if param_name != 'destinationTable':
                 continue
@@ -2167,7 +2167,7 @@ class BigQueryHook(GoogleBaseHook, DbApiHook):
             and configuration['query']['useLegacySql']
             and 'queryParameters' in configuration['query']
         ):
-            raise ValueError("Query parameters are not allowed " "when using legacy SQL")
+            raise ValueError("Query parameters are not allowed when using legacy SQL")
 
         if labels:
             _api_resource_configs_duplication_check('labels', labels, configuration)
diff --git a/airflow/providers/google/cloud/hooks/cloud_sql.py b/airflow/providers/google/cloud/hooks/cloud_sql.py
index cc6d572..dca25e9 100644
--- a/airflow/providers/google/cloud/hooks/cloud_sql.py
+++ b/airflow/providers/google/cloud/hooks/cloud_sql.py
@@ -646,10 +646,10 @@ CONNECTION_URIS = {
     "mysql": {
         "proxy": {
             "tcp": "mysql://{user}:{password}@127.0.0.1:{proxy_port}/{database}",
-            "socket": "mysql://{user}:{password}@localhost/{database}?" "unix_socket={socket_path}",
+            "socket": "mysql://{user}:{password}@localhost/{database}?unix_socket={socket_path}",
         },
         "public": {
-            "ssl": "mysql://{user}:{password}@{public_ip}:{public_port}/{database}?" "ssl={ssl_spec}",
+            "ssl": "mysql://{user}:{password}@{public_ip}:{public_port}/{database}?ssl={ssl_spec}",
             "non-ssl": "mysql://{user}:{password}@{public_ip}:{public_port}/{database}",
         },
     },
diff --git a/airflow/providers/google/cloud/hooks/gcs.py b/airflow/providers/google/cloud/hooks/gcs.py
index f59ff8e..d1b253c 100644
--- a/airflow/providers/google/cloud/hooks/gcs.py
+++ b/airflow/providers/google/cloud/hooks/gcs.py
@@ -383,7 +383,7 @@ class GCSHook(GoogleBaseHook):
             blob.upload_from_string(data, content_type=mime_type)
             self.log.info('Data stream uploaded to %s in %s bucket', object_name, bucket_name)
         else:
-            raise ValueError("'filename' and 'data' parameter missing. " "One is required to upload to gcs.")
+            raise ValueError("'filename' and 'data' parameter missing. One is required to upload to gcs.")
 
     def exists(self, bucket_name: str, object_name: str) -> bool:
         """
diff --git a/airflow/providers/google/cloud/operators/functions.py b/airflow/providers/google/cloud/operators/functions.py
index 15bd2d5..c2ea87d 100644
--- a/airflow/providers/google/cloud/operators/functions.py
+++ b/airflow/providers/google/cloud/operators/functions.py
@@ -198,9 +198,7 @@ class CloudFunctionDeployFunctionOperator(BaseOperator):
     def _check_if_function_exists(self, hook) -> bool:
         name = self.body.get('name')
         if not name:
-            raise GcpFieldValidationException(
-                "The 'name' field should be present in " "body: '{}'.".format(self.body)
-            )
+            raise GcpFieldValidationException(f"The 'name' field should be present in body: '{self.body}'.")
         try:
             hook.get_function(name)
         except HttpError as e:
diff --git a/tests/providers/google/cloud/operators/test_compute.py b/tests/providers/google/cloud/operators/test_compute.py
index d4cb1eb..4f0b40e 100644
--- a/tests/providers/google/cloud/operators/test_compute.py
+++ b/tests/providers/google/cloud/operators/test_compute.py
@@ -786,7 +786,7 @@ class TestGceInstanceTemplateCopy(unittest.TestCase):
             )
             op.execute(None)
         err = cm.exception
-        self.assertIn("should contain at least name for the new operator " "in the 'name' field", str(err))
+        self.assertIn("should contain at least name for the new operator in the 'name' field", str(err))
         mock_hook.assert_not_called()
 
 
diff --git a/tests/providers/google/marketing_platform/hooks/test_analytics.py b/tests/providers/google/marketing_platform/hooks/test_analytics.py
index da74258..abd20b0 100644
--- a/tests/providers/google/marketing_platform/hooks/test_analytics.py
+++ b/tests/providers/google/marketing_platform/hooks/test_analytics.py
@@ -54,9 +54,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
         )
         self.assertEqual(hook.api_version, API_VERSION)
 
-    @mock.patch(
-        "airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook._authorize"
-    )
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook._authorize")
     @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.build")
     def test_gen_conn(self, mock_build, mock_authorize):
         result = self.hook.get_conn()
@@ -68,7 +66,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
         )
         self.assertEqual(mock_build.return_value, result)
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
     def test_list_accounts(self, get_conn_mock):
         mock_accounts = get_conn_mock.return_value.management.return_value.accounts
         mock_list = mock_accounts.return_value.list
@@ -77,7 +75,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
         list_accounts = self.hook.list_accounts()
         self.assertEqual(list_accounts, ["a", "b"])
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
     def test_list_accounts_for_multiple_pages(self, get_conn_mock):
         mock_accounts = get_conn_mock.return_value.management.return_value.accounts
         mock_list = mock_accounts.return_value.list
@@ -89,7 +87,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
         list_accounts = self.hook.list_accounts()
         self.assertEqual(list_accounts, ["a", "b"])
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
     def test_get_ad_words_links_call(self, get_conn_mock):
         num_retries = 5
         self.hook.get_ad_words_link(
@@ -111,7 +109,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
             )
         # fmt: on
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
     def test_list_ad_words_links(self, get_conn_mock):
         mock_ads_links = get_conn_mock.return_value.management.return_value.webPropertyAdWordsLinks
         mock_list = mock_ads_links.return_value.list
@@ -120,7 +118,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
         list_ads_links = self.hook.list_ad_words_links(account_id=ACCOUNT_ID, web_property_id=WEB_PROPERTY_ID)
         self.assertEqual(list_ads_links, ["a", "b"])
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
     def test_list_ad_words_links_for_multiple_pages(self, get_conn_mock):
         mock_ads_links = get_conn_mock.return_value.management.return_value.webPropertyAdWordsLinks
         mock_list = mock_ads_links.return_value.list
@@ -132,8 +130,8 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
         list_ads_links = self.hook.list_ad_words_links(account_id=ACCOUNT_ID, web_property_id=WEB_PROPERTY_ID)
         self.assertEqual(list_ads_links, ["a", "b"])
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.MediaFileUpload")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.MediaFileUpload")
     def test_upload_data(self, media_mock, get_conn_mock):
         temp_name = "temp/file"
         self.hook.upload_data(
@@ -155,7 +153,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
             )
         # fmt: on
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
     def test_delete_upload_data(self, get_conn_mock):
         body = {"key": "temp/file"}
         self.hook.delete_upload_data(
@@ -174,7 +172,7 @@ class TestGoogleAnalyticsHook(unittest.TestCase):
             )
         # fmt: on
 
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "analytics.GoogleAnalyticsHook.get_conn")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.analytics.GoogleAnalyticsHook.get_conn")
     def test_list_upload(self, get_conn_mock):
         uploads = get_conn_mock.return_value.management.return_value.uploads.return_value
         uploads.list.return_value.execute.return_value = {
diff --git a/tests/providers/google/marketing_platform/hooks/test_display_video.py b/tests/providers/google/marketing_platform/hooks/test_display_video.py
index 70e560f..2a14ac5 100644
--- a/tests/providers/google/marketing_platform/hooks/test_display_video.py
+++ b/tests/providers/google/marketing_platform/hooks/test_display_video.py
@@ -36,7 +36,7 @@ class TestGoogleDisplayVideo360Hook(TestCase):
         "airflow.providers.google.marketing_platform.hooks."
         "display_video.GoogleDisplayVideo360Hook._authorize"
     )
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "display_video.build")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.display_video.build")
     def test_gen_conn(self, mock_build, mock_authorize):
         result = self.hook.get_conn()
         mock_build.assert_called_once_with(
@@ -51,7 +51,7 @@ class TestGoogleDisplayVideo360Hook(TestCase):
         "airflow.providers.google.marketing_platform.hooks."
         "display_video.GoogleDisplayVideo360Hook._authorize"
     )
-    @mock.patch("airflow.providers.google.marketing_platform.hooks." "display_video.build")
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.display_video.build")
     def test_get_conn_to_display_video(self, mock_build, mock_authorize):
         result = self.hook.get_conn_to_display_video()
         mock_build.assert_called_once_with(
diff --git a/tests/providers/google/marketing_platform/hooks/test_search_ads.py b/tests/providers/google/marketing_platform/hooks/test_search_ads.py
index db770ad..a3ad3d3 100644
--- a/tests/providers/google/marketing_platform/hooks/test_search_ads.py
+++ b/tests/providers/google/marketing_platform/hooks/test_search_ads.py
@@ -32,9 +32,7 @@ class TestSearchAdsHook(TestCase):
         ):
             self.hook = GoogleSearchAdsHook(gcp_conn_id=GCP_CONN_ID)
 
-    @mock.patch(
-        "airflow.providers.google.marketing_platform.hooks." "search_ads.GoogleSearchAdsHook._authorize"
-    )
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.search_ads.GoogleSearchAdsHook._authorize")
     @mock.patch("airflow.providers.google.marketing_platform.hooks.search_ads.build")
     def test_gen_conn(self, mock_build, mock_authorize):
         result = self.hook.get_conn()
@@ -46,9 +44,7 @@ class TestSearchAdsHook(TestCase):
         )
         self.assertEqual(mock_build.return_value, result)
 
-    @mock.patch(
-        "airflow.providers.google.marketing_platform.hooks." "search_ads.GoogleSearchAdsHook.get_conn"
-    )
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.search_ads.GoogleSearchAdsHook.get_conn")
     def test_insert(self, get_conn_mock):
         report = {"report": "test"}
 
@@ -63,9 +59,7 @@ class TestSearchAdsHook(TestCase):
 
         self.assertEqual(return_value, result)
 
-    @mock.patch(
-        "airflow.providers.google.marketing_platform.hooks." "search_ads.GoogleSearchAdsHook.get_conn"
-    )
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.search_ads.GoogleSearchAdsHook.get_conn")
     def test_get(self, get_conn_mock):
         report_id = "REPORT_ID"
 
@@ -78,9 +72,7 @@ class TestSearchAdsHook(TestCase):
 
         self.assertEqual(return_value, result)
 
-    @mock.patch(
-        "airflow.providers.google.marketing_platform.hooks." "search_ads.GoogleSearchAdsHook.get_conn"
-    )
+    @mock.patch("airflow.providers.google.marketing_platform.hooks.search_ads.GoogleSearchAdsHook.get_conn")
     def test_get_file(self, get_conn_mock):
         report_fragment = 42
         report_id = "REPORT_ID"
diff --git a/tests/providers/google/marketing_platform/sensors/test_display_video.py b/tests/providers/google/marketing_platform/sensors/test_display_video.py
index 5827117..803258d 100644
--- a/tests/providers/google/marketing_platform/sensors/test_display_video.py
+++ b/tests/providers/google/marketing_platform/sensors/test_display_video.py
@@ -28,10 +28,8 @@ GCP_CONN_ID = "google_cloud_default"
 
 
 class TestGoogleDisplayVideo360ReportSensor(TestCase):
-    @mock.patch(
-        "airflow.providers.google.marketing_platform.sensors." "display_video.GoogleDisplayVideo360Hook"
-    )
-    @mock.patch("airflow.providers.google.marketing_platform.sensors." "display_video.BaseSensorOperator")
+    @mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.GoogleDisplayVideo360Hook")
+    @mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.BaseSensorOperator")
     def test_poke(self, mock_base_op, hook_mock):
         report_id = "REPORT_ID"
         op = GoogleDisplayVideo360ReportSensor(
@@ -48,10 +46,8 @@ class TestGoogleDisplayVideo360ReportSensor(TestCase):
 
 
 class TestGoogleDisplayVideo360Sensor(TestCase):
-    @mock.patch(
-        "airflow.providers.google.marketing_platform.sensors." "display_video.GoogleDisplayVideo360Hook"
-    )
-    @mock.patch("airflow.providers.google.marketing_platform.sensors." "display_video.BaseSensorOperator")
+    @mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.GoogleDisplayVideo360Hook")
+    @mock.patch("airflow.providers.google.marketing_platform.sensors.display_video.BaseSensorOperator")
     def test_poke(self, mock_base_op, hook_mock):
         operation_name = "operation_name"
         op = GoogleDisplayVideo360GetSDFDownloadOperationSensor(