From 2e7f459f6ee484eb9d7db27cec864b3718531e43 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:10:11 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#279) - [ ] 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 --- .../speech_v1/services/speech/async_client.py | 18 ++-- .../cloud/speech_v1/services/speech/client.py | 8 +- .../services/speech/transports/base.py | 37 +------- .../services/speech/transports/grpc.py | 2 +- .../speech/transports/grpc_asyncio.py | 3 +- .../cloud/speech_v1/types/cloud_speech.py | 22 +++++ .../services/adaptation/async_client.py | 64 +++++++------- .../services/adaptation/client.py | 22 ++--- .../services/adaptation/transports/base.py | 35 +------- .../adaptation/transports/grpc_asyncio.py | 1 - .../services/speech/async_client.py | 18 ++-- .../services/speech/client.py | 8 +- .../services/speech/transports/base.py | 37 +------- .../services/speech/transports/grpc.py | 2 +- .../speech/transports/grpc_asyncio.py | 3 +- .../speech_v1p1beta1/types/cloud_speech.py | 22 +++++ packages/google-cloud-speech/setup.py | 3 +- .../testing/constraints-3.6.txt | 3 +- .../tests/unit/gapic/speech_v1/test_speech.py | 86 ++---------------- .../gapic/speech_v1p1beta1/test_adaptation.py | 88 ++----------------- .../gapic/speech_v1p1beta1/test_speech.py | 88 ++----------------- 21 files changed, 157 insertions(+), 413 deletions(-) diff --git a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/async_client.py b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/async_client.py index b4019fcb103b..e3f4ae1da93f 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/async_client.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.speech_v1.types import cloud_speech @@ -163,11 +165,11 @@ def __init__( async def recognize( self, - request: cloud_speech.RecognizeRequest = None, + request: Union[cloud_speech.RecognizeRequest, dict] = None, *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: @@ -175,7 +177,7 @@ async def recognize( results after all audio has been sent and processed. Args: - request (:class:`google.cloud.speech_v1.types.RecognizeRequest`): + request (Union[google.cloud.speech_v1.types.RecognizeRequest, dict]): The request object. The top-level message sent by the client for the `Recognize` method. config (:class:`google.cloud.speech_v1.types.RecognitionConfig`): @@ -251,11 +253,11 @@ async def recognize( async def long_running_recognize( self, - request: cloud_speech.LongRunningRecognizeRequest = None, + request: Union[cloud_speech.LongRunningRecognizeRequest, dict] = None, *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -267,7 +269,7 @@ async def long_running_recognize( `how-to `__. Args: - request (:class:`google.cloud.speech_v1.types.LongRunningRecognizeRequest`): + request (Union[google.cloud.speech_v1.types.LongRunningRecognizeRequest, dict]): The request object. The top-level message sent by the client for the `LongRunningRecognize` method. config (:class:`google.cloud.speech_v1.types.RecognitionConfig`): @@ -348,7 +350,7 @@ def streaming_recognize( self, requests: AsyncIterator[cloud_speech.StreamingRecognizeRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[cloud_speech.StreamingRecognizeResponse]]: diff --git a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/client.py b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/client.py index fbc6ecc12e61..4b380d1d73d4 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/client.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.speech_v1.types import cloud_speech @@ -338,7 +340,7 @@ def recognize( *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: @@ -416,7 +418,7 @@ def long_running_recognize( *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -509,7 +511,7 @@ def streaming_recognize( self, requests: Iterator[cloud_speech.StreamingRecognizeRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[cloud_speech.StreamingRecognizeResponse]: diff --git a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/base.py b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/base.py index aeb6f3fb3f5e..cc80dec6f2f0 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/base.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/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 SpeechTransport(abc.ABC): """Abstract transport class for Speech.""" @@ -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 = { @@ -201,7 +168,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc.py b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc.py index eaa1445b25b6..c3c6aa43f6df 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc.py @@ -112,7 +112,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py index 45bba730fd38..68e2e27e4ba8 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1/services/speech/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -159,7 +158,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/packages/google-cloud-speech/google/cloud/speech_v1/types/cloud_speech.py b/packages/google-cloud-speech/google/cloud/speech_v1/types/cloud_speech.py index ec2148225068..408b9e1c2d22 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1/types/cloud_speech.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1/types/cloud_speech.py @@ -89,12 +89,16 @@ class TranscriptOutputConfig(proto.Message): r"""Specifies an optional destination for the recognition results. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_uri (str): Specifies a Cloud Storage URI for the recognition results. Must be specified in the format: ``gs://bucket_name/object_name``, and the bucket must already exist. + This field is a member of `oneof`_ ``output_type``. """ gcs_uri = proto.Field(proto.STRING, number=1, oneof="output_type",) @@ -109,11 +113,19 @@ class StreamingRecognizeRequest(proto.Message): ``audio_content`` 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.speech_v1.types.StreamingRecognitionConfig): Provides information to the recognizer that specifies how to process the request. The first ``StreamingRecognizeRequest`` message must contain a ``streaming_config`` message. + This field is a member of `oneof`_ ``streaming_request``. audio_content (bytes): The audio data to be recognized. Sequential chunks of audio data are sent in sequential ``StreamingRecognizeRequest`` @@ -125,6 +137,7 @@ class StreamingRecognizeRequest(proto.Message): fields, proto buffers use a pure binary representation (not base64). See `content limits `__. + This field is a member of `oneof`_ ``streaming_request``. """ streaming_config = proto.Field( @@ -531,12 +544,20 @@ class RecognitionAudio(proto.Message): See `content limits `__. + 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: content (bytes): The audio data bytes encoded as specified in ``RecognitionConfig``. Note: as with all bytes fields, proto buffers use a pure binary representation, whereas JSON representations use base64. + This field is a member of `oneof`_ ``audio_source``. uri (str): URI that points to a file that contains audio data bytes as specified in ``RecognitionConfig``. The file must not be @@ -547,6 +568,7 @@ class RecognitionAudio(proto.Message): [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see `Request URIs `__. + This field is a member of `oneof`_ ``audio_source``. """ content = proto.Field(proto.BYTES, number=1, oneof="audio_source",) diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py index d06d900b0242..e6a9f829c972 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/async_client.py @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union 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.speech_v1p1beta1.services.adaptation import pagers from google.cloud.speech_v1p1beta1.types import cloud_speech_adaptation from google.cloud.speech_v1p1beta1.types import resource @@ -161,12 +163,12 @@ def __init__( async def create_phrase_set( self, - request: cloud_speech_adaptation.CreatePhraseSetRequest = None, + request: Union[cloud_speech_adaptation.CreatePhraseSetRequest, dict] = None, *, parent: str = None, phrase_set: resource.PhraseSet = None, phrase_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: @@ -176,7 +178,7 @@ async def create_phrase_set( when you send a call that includes the PhraseSet. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.CreatePhraseSetRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.CreatePhraseSetRequest, dict]): The request object. Message sent by the client for the `CreatePhraseSet` method. parent (:class:`str`): @@ -259,17 +261,17 @@ async def create_phrase_set( async def get_phrase_set( self, - request: cloud_speech_adaptation.GetPhraseSetRequest = None, + request: Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Get a phrase set. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.GetPhraseSetRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.GetPhraseSetRequest, dict]): The request object. Message sent by the client for the `GetPhraseSet` method. name (:class:`str`): @@ -332,17 +334,17 @@ async def get_phrase_set( async def list_phrase_set( self, - request: cloud_speech_adaptation.ListPhraseSetRequest = None, + request: Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetAsyncPager: r"""List phrase sets. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.ListPhraseSetRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.ListPhraseSetRequest, dict]): The request object. Message sent by the client for the `ListPhraseSet` method. parent (:class:`str`): @@ -413,18 +415,18 @@ async def list_phrase_set( async def update_phrase_set( self, - request: cloud_speech_adaptation.UpdatePhraseSetRequest = None, + request: Union[cloud_speech_adaptation.UpdatePhraseSetRequest, dict] = None, *, phrase_set: resource.PhraseSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: r"""Update a phrase set. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.UpdatePhraseSetRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.UpdatePhraseSetRequest, dict]): The request object. Message sent by the client for the `UpdatePhraseSet` method. phrase_set (:class:`google.cloud.speech_v1p1beta1.types.PhraseSet`): @@ -498,17 +500,17 @@ async def update_phrase_set( async def delete_phrase_set( self, - request: cloud_speech_adaptation.DeletePhraseSetRequest = None, + request: Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a phrase set. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.DeletePhraseSetRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.DeletePhraseSetRequest, dict]): The request object. Message sent by the client for the `DeletePhraseSet` method. name (:class:`str`): @@ -562,19 +564,19 @@ async def delete_phrase_set( async def create_custom_class( self, - request: cloud_speech_adaptation.CreateCustomClassRequest = None, + request: Union[cloud_speech_adaptation.CreateCustomClassRequest, dict] = None, *, parent: str = None, custom_class: resource.CustomClass = None, custom_class_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Create a custom class. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.CreateCustomClassRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.CreateCustomClassRequest, dict]): The request object. Message sent by the client for the `CreateCustomClass` method. parent (:class:`str`): @@ -661,17 +663,17 @@ async def create_custom_class( async def get_custom_class( self, - request: cloud_speech_adaptation.GetCustomClassRequest = None, + request: Union[cloud_speech_adaptation.GetCustomClassRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Get a custom class. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.GetCustomClassRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.GetCustomClassRequest, dict]): The request object. Message sent by the client for the `GetCustomClass` method. name (:class:`str`): @@ -738,17 +740,17 @@ async def get_custom_class( async def list_custom_classes( self, - request: cloud_speech_adaptation.ListCustomClassesRequest = None, + request: Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesAsyncPager: r"""List custom classes. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.ListCustomClassesRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.ListCustomClassesRequest, dict]): The request object. Message sent by the client for the `ListCustomClasses` method. parent (:class:`str`): @@ -819,18 +821,18 @@ async def list_custom_classes( async def update_custom_class( self, - request: cloud_speech_adaptation.UpdateCustomClassRequest = None, + request: Union[cloud_speech_adaptation.UpdateCustomClassRequest, dict] = None, *, custom_class: resource.CustomClass = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: r"""Update a custom class. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.UpdateCustomClassRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.UpdateCustomClassRequest, dict]): The request object. Message sent by the client for the `UpdateCustomClass` method. custom_class (:class:`google.cloud.speech_v1p1beta1.types.CustomClass`): @@ -908,17 +910,17 @@ async def update_custom_class( async def delete_custom_class( self, - request: cloud_speech_adaptation.DeleteCustomClassRequest = None, + request: Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Delete a custom class. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.DeleteCustomClassRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.DeleteCustomClassRequest, dict]): The request object. Message sent by the client for the `DeleteCustomClass` method. name (:class:`str`): diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/client.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/client.py index 931f086b16b9..7d01c840bdd1 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/client.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/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.speech_v1p1beta1.services.adaptation import pagers from google.cloud.speech_v1p1beta1.types import cloud_speech_adaptation from google.cloud.speech_v1p1beta1.types import resource @@ -370,7 +372,7 @@ def create_phrase_set( parent: str = None, phrase_set: resource.PhraseSet = None, phrase_set_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: @@ -466,7 +468,7 @@ def get_phrase_set( request: Union[cloud_speech_adaptation.GetPhraseSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: @@ -539,7 +541,7 @@ def list_phrase_set( request: Union[cloud_speech_adaptation.ListPhraseSetRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPhraseSetPager: @@ -621,7 +623,7 @@ def update_phrase_set( *, phrase_set: resource.PhraseSet = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.PhraseSet: @@ -705,7 +707,7 @@ def delete_phrase_set( request: Union[cloud_speech_adaptation.DeletePhraseSetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -771,7 +773,7 @@ def create_custom_class( parent: str = None, custom_class: resource.CustomClass = None, custom_class_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: @@ -868,7 +870,7 @@ def get_custom_class( request: Union[cloud_speech_adaptation.GetCustomClassRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: @@ -945,7 +947,7 @@ def list_custom_classes( request: Union[cloud_speech_adaptation.ListCustomClassesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomClassesPager: @@ -1027,7 +1029,7 @@ def update_custom_class( *, custom_class: resource.CustomClass = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> resource.CustomClass: @@ -1115,7 +1117,7 @@ def delete_custom_class( request: Union[cloud_speech_adaptation.DeleteCustomClassRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py index 0a624e1fa1e1..69be021d2a4c 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/base.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/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 AdaptationTransport(abc.ABC): """Abstract transport class for Adaptation.""" @@ -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/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py index 99e2e4dfbc37..b929c3eed4f2 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/transports/grpc_asyncio.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/adaptation/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/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/async_client.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/async_client.py index bf15aaf825d8..4b74e25940d0 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/async_client.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.speech_v1p1beta1.types import cloud_speech @@ -167,11 +169,11 @@ def __init__( async def recognize( self, - request: cloud_speech.RecognizeRequest = None, + request: Union[cloud_speech.RecognizeRequest, dict] = None, *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: @@ -179,7 +181,7 @@ async def recognize( results after all audio has been sent and processed. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.RecognizeRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.RecognizeRequest, dict]): The request object. The top-level message sent by the client for the `Recognize` method. config (:class:`google.cloud.speech_v1p1beta1.types.RecognitionConfig`): @@ -255,11 +257,11 @@ async def recognize( async def long_running_recognize( self, - request: cloud_speech.LongRunningRecognizeRequest = None, + request: Union[cloud_speech.LongRunningRecognizeRequest, dict] = None, *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -271,7 +273,7 @@ async def long_running_recognize( `how-to `__. Args: - request (:class:`google.cloud.speech_v1p1beta1.types.LongRunningRecognizeRequest`): + request (Union[google.cloud.speech_v1p1beta1.types.LongRunningRecognizeRequest, dict]): The request object. The top-level message sent by the client for the `LongRunningRecognize` method. config (:class:`google.cloud.speech_v1p1beta1.types.RecognitionConfig`): @@ -352,7 +354,7 @@ def streaming_recognize( self, requests: AsyncIterator[cloud_speech.StreamingRecognizeRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[cloud_speech.StreamingRecognizeResponse]]: diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/client.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/client.py index 91c017c710bd..60503d005260 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/client.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/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.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.speech_v1p1beta1.types import cloud_speech @@ -370,7 +372,7 @@ def recognize( *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> cloud_speech.RecognizeResponse: @@ -448,7 +450,7 @@ def long_running_recognize( *, config: cloud_speech.RecognitionConfig = None, audio: cloud_speech.RecognitionAudio = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -541,7 +543,7 @@ def streaming_recognize( self, requests: Iterator[cloud_speech.StreamingRecognizeRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[cloud_speech.StreamingRecognizeResponse]: diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/base.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/base.py index 640df196717a..60030be81af9 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/base.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/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 SpeechTransport(abc.ABC): """Abstract transport class for Speech.""" @@ -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 = { @@ -201,7 +168,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py index b8c4d603c505..28c0f5401c07 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc.py @@ -112,7 +112,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py index cae9aeff6e6f..aeac245829e4 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/services/speech/transports/grpc_asyncio.py @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # 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 @@ -159,7 +158,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py index f037137aa8f0..c913e147c82b 100644 --- a/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py +++ b/packages/google-cloud-speech/google/cloud/speech_v1p1beta1/types/cloud_speech.py @@ -91,12 +91,16 @@ class TranscriptOutputConfig(proto.Message): r"""Specifies an optional destination for the recognition results. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_uri (str): Specifies a Cloud Storage URI for the recognition results. Must be specified in the format: ``gs://bucket_name/object_name``, and the bucket must already exist. + This field is a member of `oneof`_ ``output_type``. """ gcs_uri = proto.Field(proto.STRING, number=1, oneof="output_type",) @@ -111,11 +115,19 @@ class StreamingRecognizeRequest(proto.Message): ``audio_content`` 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.speech_v1p1beta1.types.StreamingRecognitionConfig): Provides information to the recognizer that specifies how to process the request. The first ``StreamingRecognizeRequest`` message must contain a ``streaming_config`` message. + This field is a member of `oneof`_ ``streaming_request``. audio_content (bytes): The audio data to be recognized. Sequential chunks of audio data are sent in sequential ``StreamingRecognizeRequest`` @@ -127,6 +139,7 @@ class StreamingRecognizeRequest(proto.Message): fields, proto buffers use a pure binary representation (not base64). See `content limits `__. + This field is a member of `oneof`_ ``streaming_request``. """ streaming_config = proto.Field( @@ -628,12 +641,20 @@ class RecognitionAudio(proto.Message): See `content limits `__. + 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: content (bytes): The audio data bytes encoded as specified in ``RecognitionConfig``. Note: as with all bytes fields, proto buffers use a pure binary representation, whereas JSON representations use base64. + This field is a member of `oneof`_ ``audio_source``. uri (str): URI that points to a file that contains audio data bytes as specified in ``RecognitionConfig``. The file must not be @@ -644,6 +665,7 @@ class RecognitionAudio(proto.Message): [google.rpc.Code.INVALID_ARGUMENT][google.rpc.Code.INVALID_ARGUMENT]). For more information, see `Request URIs `__. + This field is a member of `oneof`_ ``audio_source``. """ content = proto.Field(proto.BYTES, number=1, oneof="audio_source",) diff --git a/packages/google-cloud-speech/setup.py b/packages/google-cloud-speech/setup.py index 20cde2314aca..5c449752c6c5 100644 --- a/packages/google-cloud-speech/setup.py +++ b/packages/google-cloud-speech/setup.py @@ -32,10 +32,9 @@ # 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", "libcst >= 0.2.5", "proto-plus >= 1.4.0", - "packaging >= 14.3", ] extras = {} diff --git a/packages/google-cloud-speech/testing/constraints-3.6.txt b/packages/google-cloud-speech/testing/constraints-3.6.txt index bab82048624f..96d36040bdfe 100644 --- a/packages/google-cloud-speech/testing/constraints-3.6.txt +++ b/packages/google-cloud-speech/testing/constraints-3.6.txt @@ -5,7 +5,6 @@ # # 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 libcst==0.2.5 proto-plus==1.4.0 -google-auth==1.24.0 # TODO: Remove when google-auth >= 1.25.0 is required transitively through google-api-core diff --git a/packages/google-cloud-speech/tests/unit/gapic/speech_v1/test_speech.py b/packages/google-cloud-speech/tests/unit/gapic/speech_v1/test_speech.py index 595962f283d3..e9a78bb6ce3b 100644 --- a/packages/google-cloud-speech/tests/unit/gapic/speech_v1/test_speech.py +++ b/packages/google-cloud-speech/tests/unit/gapic/speech_v1/test_speech.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -38,7 +37,6 @@ from google.cloud.speech_v1.services.speech import SpeechAsyncClient from google.cloud.speech_v1.services.speech import SpeechClient from google.cloud.speech_v1.services.speech import transports -from google.cloud.speech_v1.services.speech.transports.base import _GOOGLE_AUTH_VERSION from google.cloud.speech_v1.types import cloud_speech from google.longrunning import operations_pb2 from google.oauth2 import service_account @@ -47,20 +45,6 @@ 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" @@ -195,7 +179,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -212,7 +196,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -229,7 +213,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -258,7 +242,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -313,7 +297,7 @@ def test_speech_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 @@ -355,7 +339,7 @@ def test_speech_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, @@ -377,7 +361,7 @@ def test_speech_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, @@ -404,7 +388,7 @@ def test_speech_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, @@ -431,7 +415,7 @@ def test_speech_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", @@ -989,7 +973,6 @@ def test_speech_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_speech_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1010,26 +993,6 @@ def test_speech_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_speech_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.speech_v1.services.speech.transports.SpeechTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SpeechTransport( - 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_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( @@ -1041,7 +1004,6 @@ def test_speech_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_speech_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1054,23 +1016,10 @@ def test_speech_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_speech_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) - SpeechClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.SpeechGrpcTransport, transports.SpeechGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_speech_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1084,23 +1033,6 @@ def test_speech_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.SpeechGrpcTransport, transports.SpeechGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_speech_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", [ diff --git a/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_adaptation.py b/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_adaptation.py index c31dd38f81eb..9e1b9a6f325f 100644 --- a/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_adaptation.py +++ b/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_adaptation.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -36,9 +35,6 @@ from google.cloud.speech_v1p1beta1.services.adaptation import AdaptationClient from google.cloud.speech_v1p1beta1.services.adaptation import pagers from google.cloud.speech_v1p1beta1.services.adaptation import transports -from google.cloud.speech_v1p1beta1.services.adaptation.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.speech_v1p1beta1.types import cloud_speech_adaptation from google.cloud.speech_v1p1beta1.types import resource from google.oauth2 import service_account @@ -46,20 +42,6 @@ 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" @@ -207,7 +189,7 @@ def test_adaptation_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, @@ -224,7 +206,7 @@ def test_adaptation_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, @@ -241,7 +223,7 @@ def test_adaptation_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, @@ -270,7 +252,7 @@ def test_adaptation_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, @@ -327,7 +309,7 @@ def test_adaptation_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 @@ -369,7 +351,7 @@ def test_adaptation_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, @@ -391,7 +373,7 @@ def test_adaptation_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, @@ -422,7 +404,7 @@ def test_adaptation_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, @@ -453,7 +435,7 @@ def test_adaptation_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", @@ -3043,7 +3025,6 @@ def test_adaptation_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_adaptation_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -3064,26 +3045,6 @@ def test_adaptation_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_adaptation_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.speech_v1p1beta1.services.adaptation.transports.AdaptationTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.AdaptationTransport( - 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_adaptation_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( @@ -3095,7 +3056,6 @@ def test_adaptation_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_adaptation_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3108,23 +3068,10 @@ def test_adaptation_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_adaptation_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) - AdaptationClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.AdaptationGrpcTransport, transports.AdaptationGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_adaptation_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3138,23 +3085,6 @@ def test_adaptation_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.AdaptationGrpcTransport, transports.AdaptationGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_adaptation_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", [ diff --git a/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py b/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py index 6e205910a84b..86cb799a4131 100644 --- a/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py +++ b/packages/google-cloud-speech/tests/unit/gapic/speech_v1p1beta1/test_speech.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -38,9 +37,6 @@ from google.cloud.speech_v1p1beta1.services.speech import SpeechAsyncClient from google.cloud.speech_v1p1beta1.services.speech import SpeechClient from google.cloud.speech_v1p1beta1.services.speech import transports -from google.cloud.speech_v1p1beta1.services.speech.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.speech_v1p1beta1.types import cloud_speech from google.cloud.speech_v1p1beta1.types import resource from google.longrunning import operations_pb2 @@ -51,20 +47,6 @@ 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" @@ -199,7 +181,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -216,7 +198,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -233,7 +215,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -262,7 +244,7 @@ def test_speech_client_client_options(client_class, transport_class, transport_n 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, @@ -317,7 +299,7 @@ def test_speech_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 @@ -359,7 +341,7 @@ def test_speech_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, @@ -381,7 +363,7 @@ def test_speech_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, @@ -408,7 +390,7 @@ def test_speech_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, @@ -435,7 +417,7 @@ def test_speech_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", @@ -993,7 +975,6 @@ def test_speech_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_speech_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1014,26 +995,6 @@ def test_speech_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_speech_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.speech_v1p1beta1.services.speech.transports.SpeechTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SpeechTransport( - 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_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( @@ -1045,7 +1006,6 @@ def test_speech_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_speech_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1058,23 +1018,10 @@ def test_speech_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_speech_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) - SpeechClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.SpeechGrpcTransport, transports.SpeechGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_speech_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1088,23 +1035,6 @@ def test_speech_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.SpeechGrpcTransport, transports.SpeechGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_speech_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", [