Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
chore: use gapic-generator-python 0.53.4 (#128)
Browse files Browse the repository at this point in the history
- [ ] 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: googleapis/googleapis@83d81b0

Source-Link: googleapis/googleapis-gen@2ff001f
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9
  • Loading branch information
gcf-owl-bot[bot] committed Nov 1, 2021
1 parent 046edff commit b40537e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 125 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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]]:
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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]:
Expand Down
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions google/cloud/mediatranslation_v1beta1/types/media_translation.py
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Expand Up @@ -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=[
Expand Down
4 changes: 1 addition & 3 deletions testing/constraints-3.6.txt
Expand Up @@ -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
Expand Up @@ -15,7 +15,6 @@
#
import os
import mock
import packaging.version

import grpc
from grpc.experimental import aio
Expand All @@ -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"

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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:
Expand All @@ -779,26 +739,13 @@ 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",
[
transports.SpeechTranslationServiceGrpcTransport,
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.
Expand All @@ -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",
[
Expand Down

0 comments on commit b40537e

Please sign in to comment.