Skip to content
Permalink
Browse files
feat: support custom client info (#82)
  • Loading branch information
yoshi-automation committed Aug 24, 2020
1 parent 97b044d commit 06127932a920f6318db8f25d6430755b35d09bb5
@@ -30,7 +30,7 @@

from google.cloud.texttospeech_v1.types import cloud_tts

from .transports.base import TextToSpeechTransport
from .transports.base import TextToSpeechTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import TextToSpeechGrpcAsyncIOTransport
from .client import TextToSpeechClient

@@ -56,6 +56,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, TextToSpeechTransport] = "grpc_asyncio",
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the text to speech client.
@@ -88,7 +89,10 @@ def __init__(
"""

self._client = TextToSpeechClient(
credentials=credentials, transport=transport, client_options=client_options,
credentials=credentials,
transport=transport,
client_options=client_options,
client_info=client_info,
)

async def list_voices(
@@ -155,7 +159,7 @@ async def list_voices(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_voices,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Send the request.
@@ -239,7 +243,7 @@ async def synthesize_speech(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.synthesize_speech,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Send the request.
@@ -250,13 +254,13 @@ async def synthesize_speech(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
"google-cloud-texttospeech",
).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("TextToSpeechAsyncClient",)
@@ -32,7 +32,7 @@

from google.cloud.texttospeech_v1.types import cloud_tts

from .transports.base import TextToSpeechTransport
from .transports.base import TextToSpeechTransport, DEFAULT_CLIENT_INFO
from .transports.grpc import TextToSpeechGrpcTransport
from .transports.grpc_asyncio import TextToSpeechGrpcAsyncIOTransport

@@ -131,6 +131,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, TextToSpeechTransport] = None,
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the text to speech client.
@@ -156,6 +157,11 @@ def __init__(
(2) The ``client_cert_source`` property is used to provide client
SSL credentials for mutual TLS transport. If not provided, the
default SSL credentials will be used if present.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -213,6 +219,7 @@ def __init__(
api_mtls_endpoint=client_options.api_endpoint,
client_cert_source=client_options.client_cert_source,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
)

def list_voices(
@@ -378,13 +385,13 @@ def synthesize_speech(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
"google-cloud-texttospeech",
).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("TextToSpeechClient",)
@@ -29,13 +29,13 @@


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
"google-cloud-texttospeech",
).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


class TextToSpeechTransport(abc.ABC):
@@ -51,6 +51,7 @@ def __init__(
credentials_file: typing.Optional[str] = None,
scopes: typing.Optional[typing.Sequence[str]] = AUTH_SCOPES,
quota_project_id: typing.Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
**kwargs,
) -> None:
"""Instantiate the transport.
@@ -68,6 +69,11 @@ def __init__(
scope (Optional[Sequence[str]]): A list of scopes.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
"""
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
if ":" not in host:
@@ -95,16 +101,16 @@ def __init__(
self._credentials = credentials

# Lifted into its own function so it can be stubbed out during tests.
self._prep_wrapped_messages()
self._prep_wrapped_messages(client_info)

def _prep_wrapped_messages(self):
def _prep_wrapped_messages(self, client_info):
# Precompute the wrapped methods.
self._wrapped_methods = {
self.list_voices: gapic_v1.method.wrap_method(
self.list_voices, default_timeout=None, client_info=_client_info,
self.list_voices, default_timeout=None, client_info=client_info,
),
self.synthesize_speech: gapic_v1.method.wrap_method(
self.synthesize_speech, default_timeout=None, client_info=_client_info,
self.synthesize_speech, default_timeout=None, client_info=client_info,
),
}

@@ -18,6 +18,7 @@
from typing import Callable, Dict, Optional, Sequence, Tuple

from google.api_core import grpc_helpers # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google import auth # type: ignore
from google.auth import credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
@@ -27,7 +28,7 @@

from google.cloud.texttospeech_v1.types import cloud_tts

from .base import TextToSpeechTransport
from .base import TextToSpeechTransport, DEFAULT_CLIENT_INFO


class TextToSpeechGrpcTransport(TextToSpeechTransport):
@@ -55,7 +56,8 @@ def __init__(
channel: grpc.Channel = None,
api_mtls_endpoint: str = None,
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id: Optional[str] = None
quota_project_id: Optional[str] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the transport.
@@ -84,6 +86,11 @@ def __init__(
is None.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -139,6 +146,7 @@ def __init__(
credentials_file=credentials_file,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
client_info=client_info,
)

@classmethod
@@ -149,7 +157,7 @@ def create_channel(
credentials_file: str = None,
scopes: Optional[Sequence[str]] = None,
quota_project_id: Optional[str] = None,
**kwargs
**kwargs,
) -> grpc.Channel:
"""Create and return a gRPC channel object.
Args:
@@ -183,7 +191,7 @@ def create_channel(
credentials_file=credentials_file,
scopes=scopes,
quota_project_id=quota_project_id,
**kwargs
**kwargs,
)

@property
@@ -17,6 +17,7 @@

from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple

from google.api_core import gapic_v1 # type: ignore
from google.api_core import grpc_helpers_async # type: ignore
from google.auth import credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
@@ -26,7 +27,7 @@

from google.cloud.texttospeech_v1.types import cloud_tts

from .base import TextToSpeechTransport
from .base import TextToSpeechTransport, DEFAULT_CLIENT_INFO
from .grpc import TextToSpeechGrpcTransport


@@ -98,6 +99,7 @@ def __init__(
api_mtls_endpoint: str = None,
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id=None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the transport.
@@ -127,6 +129,11 @@ def __init__(
is None.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
@@ -175,6 +182,7 @@ def __init__(
credentials_file=credentials_file,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
client_info=client_info,
)

self._stubs = {}
@@ -30,7 +30,7 @@

from google.cloud.texttospeech_v1beta1.types import cloud_tts

from .transports.base import TextToSpeechTransport
from .transports.base import TextToSpeechTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import TextToSpeechGrpcAsyncIOTransport
from .client import TextToSpeechClient

@@ -56,6 +56,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, TextToSpeechTransport] = "grpc_asyncio",
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the text to speech client.
@@ -88,7 +89,10 @@ def __init__(
"""

self._client = TextToSpeechClient(
credentials=credentials, transport=transport, client_options=client_options,
credentials=credentials,
transport=transport,
client_options=client_options,
client_info=client_info,
)

async def list_voices(
@@ -155,7 +159,7 @@ async def list_voices(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_voices,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Send the request.
@@ -239,7 +243,7 @@ async def synthesize_speech(
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.synthesize_speech,
default_timeout=None,
client_info=_client_info,
client_info=DEFAULT_CLIENT_INFO,
)

# Send the request.
@@ -250,13 +254,13 @@ async def synthesize_speech(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
"google-cloud-texttospeech",
).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("TextToSpeechAsyncClient",)
@@ -32,7 +32,7 @@

from google.cloud.texttospeech_v1beta1.types import cloud_tts

from .transports.base import TextToSpeechTransport
from .transports.base import TextToSpeechTransport, DEFAULT_CLIENT_INFO
from .transports.grpc import TextToSpeechGrpcTransport
from .transports.grpc_asyncio import TextToSpeechGrpcAsyncIOTransport

@@ -131,6 +131,7 @@ def __init__(
credentials: credentials.Credentials = None,
transport: Union[str, TextToSpeechTransport] = None,
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the text to speech client.
@@ -156,6 +157,11 @@ def __init__(
(2) The ``client_cert_source`` property is used to provide client
SSL credentials for mutual TLS transport. If not provided, the
default SSL credentials will be used if present.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
@@ -213,6 +219,7 @@ def __init__(
api_mtls_endpoint=client_options.api_endpoint,
client_cert_source=client_options.client_cert_source,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
)

def list_voices(
@@ -378,13 +385,13 @@ def synthesize_speech(


try:
_client_info = gapic_v1.client_info.ClientInfo(
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
"google-cloud-texttospeech",
).version,
)
except pkg_resources.DistributionNotFound:
_client_info = gapic_v1.client_info.ClientInfo()
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = ("TextToSpeechClient",)
Loading

0 comments on commit 0612793

Please sign in to comment.