From b40537ea4240cd8e91120ed158094b3c3346f8ee Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 11:30:12 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#128) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../async_client.py | 6 +- .../speech_translation_service/client.py | 4 +- .../transports/base.py | 35 +------ .../transports/grpc_asyncio.py | 1 - .../types/media_translation.py | 13 +++ setup.py | 3 +- testing/constraints-3.6.txt | 4 +- .../test_speech_translation_service.py | 91 ++----------------- 8 files changed, 32 insertions(+), 125 deletions(-) diff --git a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py index e8b324b..ff1ae3f 100644 --- a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py +++ b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/async_client.py @@ -28,13 +28,15 @@ ) import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.mediatranslation_v1beta1.types import media_translation from google.rpc import status_pb2 # type: ignore from .transports.base import SpeechTranslationServiceTransport, DEFAULT_CLIENT_INFO @@ -179,7 +181,7 @@ def streaming_translate_speech( media_translation.StreamingTranslateSpeechRequest ] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[media_translation.StreamingTranslateSpeechResponse]]: diff --git a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py index 1991f37..7e899a5 100644 --- a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py +++ b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.mediatranslation_v1beta1.types import media_translation from google.rpc import status_pb2 # type: ignore from .transports.base import SpeechTranslationServiceTransport, DEFAULT_CLIENT_INFO @@ -337,7 +339,7 @@ def streaming_translate_speech( self, requests: Iterator[media_translation.StreamingTranslateSpeechRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[media_translation.StreamingTranslateSpeechResponse]: diff --git a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py index e29b876..bb66fa8 100644 --- a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py +++ b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -37,15 +36,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class SpeechTranslationServiceTransport(abc.ABC): """Abstract transport class for SpeechTranslationService.""" @@ -95,7 +85,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -128,29 +118,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { diff --git a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py index 4e3e5dd..f8aadad 100644 --- a/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py +++ b/google/cloud/mediatranslation_v1beta1/services/speech_translation_service/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/cloud/mediatranslation_v1beta1/types/media_translation.py b/google/cloud/mediatranslation_v1beta1/types/media_translation.py index 419c5a3..d93b65f 100644 --- a/google/cloud/mediatranslation_v1beta1/types/media_translation.py +++ b/google/cloud/mediatranslation_v1beta1/types/media_translation.py @@ -149,12 +149,20 @@ class StreamingTranslateSpeechRequest(proto.Message): ``audio_content`` data and must not contain a ``streaming_config`` message. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: streaming_config (google.cloud.mediatranslation_v1beta1.types.StreamingTranslateSpeechConfig): Provides information to the recognizer that specifies how to process the request. The first ``StreamingTranslateSpeechRequest`` message must contain a ``streaming_config`` message. + This field is a member of `oneof`_ ``streaming_request``. audio_content (bytes): The audio data to be translated. Sequential chunks of audio data are sent in sequential @@ -166,6 +174,7 @@ class StreamingTranslateSpeechRequest(proto.Message): specified in ``StreamingTranslateSpeechConfig``. Note: as with all bytes fields, protobuffers use a pure binary representation (not base64). + This field is a member of `oneof`_ ``streaming_request``. """ streaming_config = proto.Field( @@ -181,9 +190,13 @@ class StreamingTranslateSpeechResult(proto.Message): r"""A streaming speech translation result corresponding to a portion of the audio that is currently being processed. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: text_translation_result (google.cloud.mediatranslation_v1beta1.types.StreamingTranslateSpeechResult.TextTranslationResult): Text translation result. + This field is a member of `oneof`_ ``result``. """ class TextTranslationResult(proto.Message): diff --git a/setup.py b/setup.py index 6ae3920..982e32c 100644 --- a/setup.py +++ b/setup.py @@ -42,9 +42,8 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", "proto-plus >= 1.10.0", - "packaging >= 14.3", ), python_requires=">=3.6", classifiers=[ diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 021afb9..da8c573 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,7 +5,5 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 proto-plus==1.10.0 -packaging==14.3 -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is transitively required through google-api-core diff --git a/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py b/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py index c086157..cf3b83b 100644 --- a/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py +++ b/tests/unit/gapic/mediatranslation_v1beta1/test_speech_translation_service.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -41,29 +40,12 @@ from google.cloud.mediatranslation_v1beta1.services.speech_translation_service import ( transports, ) -from google.cloud.mediatranslation_v1beta1.services.speech_translation_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.mediatranslation_v1beta1.types import media_translation from google.oauth2 import service_account from google.rpc import status_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -231,7 +213,7 @@ def test_speech_translation_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -248,7 +230,7 @@ def test_speech_translation_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -265,7 +247,7 @@ def test_speech_translation_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -294,7 +276,7 @@ def test_speech_translation_service_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -363,7 +345,7 @@ def test_speech_translation_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -405,7 +387,7 @@ def test_speech_translation_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -427,7 +409,7 @@ def test_speech_translation_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -462,7 +444,7 @@ def test_speech_translation_service_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -497,7 +479,7 @@ def test_speech_translation_service_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -714,7 +696,6 @@ def test_speech_translation_service_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_speech_translation_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -735,26 +716,6 @@ def test_speech_translation_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_speech_translation_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.mediatranslation_v1beta1.services.speech_translation_service.transports.SpeechTranslationServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SpeechTranslationServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_speech_translation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -766,7 +727,6 @@ def test_speech_translation_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_speech_translation_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -779,18 +739,6 @@ def test_speech_translation_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_speech_translation_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - SpeechTranslationServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -798,7 +746,6 @@ def test_speech_translation_service_auth_adc_old_google_auth(): transports.SpeechTranslationServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_speech_translation_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -812,26 +759,6 @@ def test_speech_translation_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SpeechTranslationServiceGrpcTransport, - transports.SpeechTranslationServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_speech_translation_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [