From 0b2b1559e0c401e3d3975fc3e9009a36572d98fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?micha=C5=82=20s=C5=82owikowski?= Date: Wed, 23 Oct 2019 11:38:49 +0200 Subject: [PATCH 1/3] rename GCPSpeechToTextHook to CloudSpeechToTextHook --- airflow/contrib/hooks/gcp_speech_to_text_hook.py | 2 +- airflow/gcp/hooks/speech_to_text.py | 2 +- airflow/gcp/operators/speech_to_text.py | 4 ++-- airflow/gcp/operators/translate_speech.py | 4 ++-- tests/gcp/hooks/test_speech_to_text.py | 10 +++++----- tests/gcp/operators/test_speech_to_text.py | 6 +++--- tests/gcp/operators/test_translate_speech.py | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/airflow/contrib/hooks/gcp_speech_to_text_hook.py b/airflow/contrib/hooks/gcp_speech_to_text_hook.py index ce33f0e0aee01..01db8ca2686c2 100644 --- a/airflow/contrib/hooks/gcp_speech_to_text_hook.py +++ b/airflow/contrib/hooks/gcp_speech_to_text_hook.py @@ -23,7 +23,7 @@ import warnings # pylint: disable=unused-import -from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook # noqa +from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook # noqa warnings.warn( "This module is deprecated. Please use `airflow.gcp.hooks.speech_to_text`", diff --git a/airflow/gcp/hooks/speech_to_text.py b/airflow/gcp/hooks/speech_to_text.py index 390c538763fc4..68b344b07e75b 100644 --- a/airflow/gcp/hooks/speech_to_text.py +++ b/airflow/gcp/hooks/speech_to_text.py @@ -28,7 +28,7 @@ from airflow.gcp.hooks.base import GoogleCloudBaseHook -class GCPSpeechToTextHook(GoogleCloudBaseHook): +class CloudSpeechToTextHook(GoogleCloudBaseHook): """ Hook for Google Cloud Speech API. diff --git a/airflow/gcp/operators/speech_to_text.py b/airflow/gcp/operators/speech_to_text.py index 7cb8e8f6d6fd2..58d07da9e9345 100644 --- a/airflow/gcp/operators/speech_to_text.py +++ b/airflow/gcp/operators/speech_to_text.py @@ -25,7 +25,7 @@ from google.cloud.speech_v1.types import RecognitionConfig from airflow import AirflowException -from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook, RecognitionAudio +from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook, RecognitionAudio from airflow.models import BaseOperator from airflow.utils.decorators import apply_defaults @@ -90,7 +90,7 @@ def _validate_inputs(self): raise AirflowException("The required parameter 'config' is empty") def execute(self, context): - hook = GCPSpeechToTextHook(gcp_conn_id=self.gcp_conn_id) + hook = CloudSpeechToTextHook(gcp_conn_id=self.gcp_conn_id) return hook.recognize_speech( config=self.config, audio=self.audio, retry=self.retry, timeout=self.timeout ) diff --git a/airflow/gcp/operators/translate_speech.py b/airflow/gcp/operators/translate_speech.py index 331ca08c6cabd..6ca7661fe10df 100644 --- a/airflow/gcp/operators/translate_speech.py +++ b/airflow/gcp/operators/translate_speech.py @@ -25,7 +25,7 @@ from google.protobuf.json_format import MessageToDict from airflow import AirflowException -from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook +from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook from airflow.gcp.hooks.translate import CloudTranslateHook from airflow.models import BaseOperator from airflow.utils.decorators import apply_defaults @@ -127,7 +127,7 @@ def __init__( self.gcp_conn_id = gcp_conn_id def execute(self, context): - speech_to_text_hook = GCPSpeechToTextHook(gcp_conn_id=self.gcp_conn_id) + speech_to_text_hook = CloudSpeechToTextHook(gcp_conn_id=self.gcp_conn_id) translate_hook = CloudTranslateHook(gcp_conn_id=self.gcp_conn_id) recognize_result = speech_to_text_hook.recognize_speech( diff --git a/tests/gcp/hooks/test_speech_to_text.py b/tests/gcp/hooks/test_speech_to_text.py index bc15f7d603b0f..1ff85dbb04903 100644 --- a/tests/gcp/hooks/test_speech_to_text.py +++ b/tests/gcp/hooks/test_speech_to_text.py @@ -20,7 +20,7 @@ import unittest -from airflow.gcp.hooks.speech_to_text import GCPSpeechToTextHook +from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook from tests.compat import PropertyMock, patch from tests.gcp.utils.base_gcp_mock import mock_base_gcp_hook_default_project_id @@ -35,10 +35,10 @@ def setUp(self): "airflow.gcp.hooks.base.GoogleCloudBaseHook.__init__", new=mock_base_gcp_hook_default_project_id, ): - self.gcp_speech_to_text_hook = GCPSpeechToTextHook(gcp_conn_id="test") + self.gcp_speech_to_text_hook = CloudSpeechToTextHook(gcp_conn_id="test") - @patch("airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook.client_info", new_callable=PropertyMock) - @patch("airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook._get_credentials") + @patch("airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook.client_info", new_callable=PropertyMock) + @patch("airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook._get_credentials") @patch("airflow.gcp.hooks.speech_to_text.SpeechClient") def test_speech_client_creation(self, mock_client, mock_get_creds, mock_client_info): result = self.gcp_speech_to_text_hook.get_conn() @@ -49,7 +49,7 @@ def test_speech_client_creation(self, mock_client, mock_get_creds, mock_client_i self.assertEqual(mock_client.return_value, result) self.assertEqual(self.gcp_speech_to_text_hook._client, result) - @patch("airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook.get_conn") + @patch("airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook.get_conn") def test_synthesize_speech(self, get_conn): recognize_method = get_conn.return_value.recognize recognize_method.return_value = None diff --git a/tests/gcp/operators/test_speech_to_text.py b/tests/gcp/operators/test_speech_to_text.py index 3e196be723c33..f54adfd07d608 100644 --- a/tests/gcp/operators/test_speech_to_text.py +++ b/tests/gcp/operators/test_speech_to_text.py @@ -30,7 +30,7 @@ class TestCloudSql(unittest.TestCase): - @patch("airflow.gcp.operators.speech_to_text.GCPSpeechToTextHook") + @patch("airflow.gcp.operators.speech_to_text.CloudSpeechToTextHook") def test_recognize_speech_green_path(self, mock_hook): mock_hook.return_value.recognize_speech.return_value = True @@ -43,7 +43,7 @@ def test_recognize_speech_green_path(self, mock_hook): config=CONFIG, audio=AUDIO, retry=None, timeout=None ) - @patch("airflow.gcp.operators.speech_to_text.GCPSpeechToTextHook") + @patch("airflow.gcp.operators.speech_to_text.CloudSpeechToTextHook") def test_missing_config(self, mock_hook): mock_hook.return_value.recognize_speech.return_value = True @@ -56,7 +56,7 @@ def test_missing_config(self, mock_hook): self.assertIn("config", str(err)) mock_hook.assert_not_called() - @patch("airflow.gcp.operators.speech_to_text.GCPSpeechToTextHook") + @patch("airflow.gcp.operators.speech_to_text.CloudSpeechToTextHook") def test_missing_audio(self, mock_hook): mock_hook.return_value.recognize_speech.return_value = True diff --git a/tests/gcp/operators/test_translate_speech.py b/tests/gcp/operators/test_translate_speech.py index 68a22e89cbf84..4558b33558a05 100644 --- a/tests/gcp/operators/test_translate_speech.py +++ b/tests/gcp/operators/test_translate_speech.py @@ -31,7 +31,7 @@ class TestCloudTranslateSpeech(unittest.TestCase): - @mock.patch('airflow.gcp.operators.translate_speech.GCPSpeechToTextHook') + @mock.patch('airflow.gcp.operators.translate_speech.CloudSpeechToTextHook') @mock.patch('airflow.gcp.operators.translate_speech.CloudTranslateHook') def test_minimal_green_path(self, mock_translate_hook, mock_speech_hook): mock_speech_hook.return_value.recognize_speech.return_value = RecognizeResponse( @@ -89,7 +89,7 @@ def test_minimal_green_path(self, mock_translate_hook, mock_speech_hook): return_value, ) - @mock.patch('airflow.gcp.operators.translate_speech.GCPSpeechToTextHook') + @mock.patch('airflow.gcp.operators.translate_speech.CloudSpeechToTextHook') @mock.patch('airflow.gcp.operators.translate_speech.CloudTranslateHook') def test_bad_recognition_response(self, mock_translate_hook, mock_speech_hook): mock_speech_hook.return_value.recognize_speech.return_value = RecognizeResponse( From 478028d291a756dc4cc1280b7f5ca5f79405edc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?micha=C5=82=20s=C5=82owikowski?= Date: Wed, 23 Oct 2019 11:57:32 +0200 Subject: [PATCH 2/3] added to gcp_speech_to_text_hook.py deprecation warning --- airflow/contrib/hooks/gcp_speech_to_text_hook.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/airflow/contrib/hooks/gcp_speech_to_text_hook.py b/airflow/contrib/hooks/gcp_speech_to_text_hook.py index 01db8ca2686c2..fed8203aff4b7 100644 --- a/airflow/contrib/hooks/gcp_speech_to_text_hook.py +++ b/airflow/contrib/hooks/gcp_speech_to_text_hook.py @@ -29,3 +29,17 @@ "This module is deprecated. Please use `airflow.gcp.hooks.speech_to_text`", DeprecationWarning, stacklevel=2 ) + + +class GCPSpeechToTextHook(CloudSpeechToTextHook): + """ + This class is deprecated. Please use `airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook`. + """ + + def __init__(self, *args, **kwargs): + warnings.warn( + "This class is deprecated. Please use `airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook`.", + DeprecationWarning, stacklevel=2 + ) + + super().__init__(*args, **kwargs) From 0d1936c8bf8c93d420506e312db40eefc59f8ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?micha=C5=82=20s=C5=82owikowski?= Date: Wed, 23 Oct 2019 12:00:36 +0200 Subject: [PATCH 3/3] Updated UPDATING.md --- UPDATING.md | 7 ++++--- airflow/contrib/hooks/gcp_speech_to_text_hook.py | 3 +-- tests/test_core_to_contrib.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/UPDATING.md b/UPDATING.md index 932fb708d3144..f54150cfae69a 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -218,17 +218,18 @@ The following table shows changes in import paths. |airflow.contrib.hooks.gcp_dataflow_hook.DataFlowHook |airflow.gcp.hooks.dataflow.DataFlowHook | |airflow.contrib.hooks.gcp_dataproc_hook.DataProcHook |airflow.gcp.hooks.dataproc.DataprocHook | |airflow.contrib.hooks.gcp_dlp_hook.CloudDLPHook |airflow.gcp.hooks.dlp.CloudDLPHook | -|airflow.contrib.hooks.gcp_function_hook.GcfHook |airflow.gcp.hooks.functions.CloudFunctionsHook | +|airflow.contrib.hooks.gcp_function_hook.GcfHook |airflow.gcp.hooks.functions.CloudFunctionsHook | |airflow.contrib.hooks.gcp_kms_hook.GoogleCloudKMSHook |airflow.gcp.hooks.kms.GoogleCloudKMSHook | |airflow.contrib.hooks.gcp_mlengine_hook.MLEngineHook |airflow.gcp.hooks.mlengine.MLEngineHook | |airflow.contrib.hooks.gcp_natural_language_hook.CloudNaturalLanguageHook |airflow.gcp.hooks.natural_language.CloudNaturalLanguageHook | |airflow.contrib.hooks.gcp_pubsub_hook.PubSubHook |airflow.gcp.hooks.pubsub.PubSubHook | -|airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook |airflow.gcp.hooks.spanner.SpannerHook | +|airflow.contrib.hooks.gcp_speech_to_text_hook.GCPSpeechToTextHook |airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook | +|airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook |airflow.gcp.hooks.spanner.SpannerHook | |airflow.contrib.hooks.gcp_speech_to_text_hook.GCPSpeechToTextHook |airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook | |airflow.contrib.hooks.gcp_sql_hook.CloudSqlDatabaseHook |airflow.gcp.hooks.cloud_sql.CloudSqlDatabaseHook | |airflow.contrib.hooks.gcp_sql_hook.CloudSqlHook |airflow.gcp.hooks.cloud_sql.CloudSqlHook | |airflow.contrib.hooks.gcp_tasks_hook.CloudTasksHook |airflow.gcp.hooks.tasks.CloudTasksHook | -|airflow.contrib.hooks.gcp_text_to_speech_hook.GCPTextToSpeechHook |airflow.gcp.hooks.text_to_speech.CloudTextToSpeechHook | +|airflow.contrib.hooks.gcp_text_to_speech_hook.GCPTextToSpeechHook |airflow.gcp.hooks.text_to_speech.CloudTextToSpeechHook | |airflow.contrib.hooks.gcp_transfer_hook.GCPTransferServiceHook |airflow.gcp.hooks.cloud_storage_transfer_service.GCPTransferServiceHook | |airflow.contrib.hooks.gcp_translate_hook.CloudTranslateHook |airflow.gcp.hooks.translate.CloudTranslateHook | |airflow.contrib.hooks.gcp_video_intelligence_hook.CloudVideoIntelligenceHook |airflow.gcp.hooks.video_intelligence.CloudVideoIntelligenceHook | diff --git a/airflow/contrib/hooks/gcp_speech_to_text_hook.py b/airflow/contrib/hooks/gcp_speech_to_text_hook.py index fed8203aff4b7..ed3a981f09d04 100644 --- a/airflow/contrib/hooks/gcp_speech_to_text_hook.py +++ b/airflow/contrib/hooks/gcp_speech_to_text_hook.py @@ -22,8 +22,7 @@ import warnings -# pylint: disable=unused-import -from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook # noqa +from airflow.gcp.hooks.speech_to_text import CloudSpeechToTextHook warnings.warn( "This module is deprecated. Please use `airflow.gcp.hooks.speech_to_text`", diff --git a/tests/test_core_to_contrib.py b/tests/test_core_to_contrib.py index d42a548bf1bef..dcde43b42fb41 100644 --- a/tests/test_core_to_contrib.py +++ b/tests/test_core_to_contrib.py @@ -61,7 +61,7 @@ "airflow.contrib.hooks.gcp_spanner_hook.CloudSpannerHook", ), ( - "airflow.gcp.hooks.speech_to_text.GCPSpeechToTextHook", + "airflow.gcp.hooks.speech_to_text.CloudSpeechToTextHook", "airflow.contrib.hooks.gcp_speech_to_text_hook.GCPSpeechToTextHook", ), (