Skip to content

Commit

Permalink
feat: add common resource helpers; expose transport; remove gRPC send…
Browse files Browse the repository at this point in the history
…/recv limits (#100)

* changes without context

        autosynth cannot find the source of changes triggered by earlier changes in this
        repository, or by version upgrades to tools such as linters.

* feat: Add Java microgen rules to imports

Source-Author: Mira Leung <miraleung@users.noreply.github.com>
Source-Date: Mon Sep 21 18:04:02 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: aaac658367398e478d650768344b88acebad50d9
Source-Link: googleapis/googleapis@aaac658

* Update gapic-generator-python pin to 0.33.4

PiperOrigin-RevId: 333159182

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Sep 22 14:22:59 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 3dbeac0d54125b123c8dfd39c774b37473c36944
Source-Link: googleapis/googleapis@3dbeac0

* fix: naming style updates

Source-Author: Mira Leung <miraleung@google.com>
Source-Date: Wed Sep 23 16:33:18 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 3737889dafd012d7f7f724fa04390d42db496e6c
Source-Link: googleapis/googleapis@3737889

* Add Service Direcotry v1 protos and configs

PiperOrigin-RevId: 333502684

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Sep 24 06:33:53 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: d3697d47929f34c43bcc4de16c7c761a80e97cf1
Source-Link: googleapis/googleapis@d3697d4

* chore: upgrade to gapic-generator-python 0.35.6

PiperOrigin-RevId: 338157137

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Oct 20 16:08:47 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: c7331b75b0b7bbd614373b7d37085db1c80dd4be
Source-Link: googleapis/googleapis@c7331b7

* feat: Add Visual Inspection V1Beta1 API.

PiperOrigin-RevId: 338201056

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Oct 20 22:16:12 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 11fd1fb53d03cf4852d3f63d679292e3c7b6e7c8
Source-Link: googleapis/googleapis@11fd1fb

* chore: upgrade to gapic-generator-python 0.35.6

PiperOrigin-RevId: 338489505

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Oct 22 09:36:18 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 4b34a0869404af9d83ae89952d28712a4d29eba6
Source-Link: googleapis/googleapis@4b34a08

* fix: switch firestore/v1 to grpc_service_config

PiperOrigin-RevId: 338520351

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Oct 22 12:01:06 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: b448d7dce89eebc3a4066a9e979a0b96bdb66b62
Source-Link: googleapis/googleapis@b448d7d

* build(node): provide hint to npm

PiperOrigin-RevId: 339261149

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Oct 27 09:09:14 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: c9d7721bd4e22b3a25d914248fac126a5a91d3d9
Source-Link: googleapis/googleapis@c9d7721

* chore: upgrade to gapic-generator 0.35.9

PiperOrigin-RevId: 339292950

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Oct 27 11:32:46 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 07d41a7e5cade45aba6f0d277c89722b48f2c956
Source-Link: googleapis/googleapis@07d41a7

* chore: migrate firestore/admin to the Java microgenerator

Committer: @miraleung
PiperOrigin-RevId: 346387604

Source-Author: Google APIs <noreply@google.com>
Source-Date: Tue Dec 8 12:41:11 2020 -0800
Source-Repo: googleapis/googleapis
Source-Sha: 36e1a9a8e31eef72033033aa910be56a64a1793f
Source-Link: googleapis/googleapis@36e1a9a

* fix: remove client recv msg limit fix: add enums to `types/__init__.py`

PiperOrigin-RevId: 347055288

Source-Author: Google APIs <noreply@google.com>
Source-Date: Fri Dec 11 12:44:37 2020 -0800
Source-Repo: googleapis/googleapis
Source-Sha: dd372aa22ded7a8ba6f0e03a80e06358a3fa0907
Source-Link: googleapis/googleapis@dd372aa
  • Loading branch information
yoshi-automation authored Dec 23, 2020
1 parent f5acd87 commit fa27bc4
Show file tree
Hide file tree
Showing 22 changed files with 763 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Speech v1 API

.. automodule:: google.cloud.speech_v1.types
:members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Speech v1p1beta1 API

.. automodule:: google.cloud.speech_v1p1beta1.types
:members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@
from collections import OrderedDict
import functools
import re
from typing import Dict, AsyncIterable, AsyncIterator, Sequence, Tuple, Type, Union
from typing import (
Dict,
AsyncIterable,
Awaitable,
AsyncIterator,
Sequence,
Tuple,
Type,
Union,
)
import pkg_resources

import google.api_core.client_options as ClientOptions # type: ignore
Expand Down Expand Up @@ -46,9 +55,37 @@ class SpeechAsyncClient:
DEFAULT_ENDPOINT = SpeechClient.DEFAULT_ENDPOINT
DEFAULT_MTLS_ENDPOINT = SpeechClient.DEFAULT_MTLS_ENDPOINT

common_billing_account_path = staticmethod(SpeechClient.common_billing_account_path)
parse_common_billing_account_path = staticmethod(
SpeechClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(SpeechClient.common_folder_path)
parse_common_folder_path = staticmethod(SpeechClient.parse_common_folder_path)

common_organization_path = staticmethod(SpeechClient.common_organization_path)
parse_common_organization_path = staticmethod(
SpeechClient.parse_common_organization_path
)

common_project_path = staticmethod(SpeechClient.common_project_path)
parse_common_project_path = staticmethod(SpeechClient.parse_common_project_path)

common_location_path = staticmethod(SpeechClient.common_location_path)
parse_common_location_path = staticmethod(SpeechClient.parse_common_location_path)

from_service_account_file = SpeechClient.from_service_account_file
from_service_account_json = from_service_account_file

@property
def transport(self) -> SpeechTransport:
"""Return the transport used by the client instance.
Returns:
SpeechTransport: The transport used by the client instance.
"""
return self._client.transport

get_transport_class = functools.partial(
type(SpeechClient).get_transport_class, type(SpeechClient)
)
Expand Down Expand Up @@ -148,7 +185,8 @@ async def recognize(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([config, audio]):
has_flattened_params = any([config, audio])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -245,7 +283,8 @@ async def long_running_recognize(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([config, audio]):
has_flattened_params = any([config, audio])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -290,7 +329,7 @@ def streaming_recognize(
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> AsyncIterable[cloud_speech.StreamingRecognizeResponse]:
) -> Awaitable[AsyncIterable[cloud_speech.StreamingRecognizeResponse]]:
r"""Performs bidirectional streaming speech recognition:
receive results while sending audio. This method is only
available via the gRPC API (not REST).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,74 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):

from_service_account_json = from_service_account_file

@property
def transport(self) -> SpeechTransport:
"""Return the transport used by the client instance.
Returns:
SpeechTransport: The transport used by the client instance.
"""
return self._transport

@staticmethod
def common_billing_account_path(billing_account: str,) -> str:
"""Return a fully-qualified billing_account string."""
return "billingAccounts/{billing_account}".format(
billing_account=billing_account,
)

@staticmethod
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
"""Parse a billing_account path into its component segments."""
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_folder_path(folder: str,) -> str:
"""Return a fully-qualified folder string."""
return "folders/{folder}".format(folder=folder,)

@staticmethod
def parse_common_folder_path(path: str) -> Dict[str, str]:
"""Parse a folder path into its component segments."""
m = re.match(r"^folders/(?P<folder>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_organization_path(organization: str,) -> str:
"""Return a fully-qualified organization string."""
return "organizations/{organization}".format(organization=organization,)

@staticmethod
def parse_common_organization_path(path: str) -> Dict[str, str]:
"""Parse a organization path into its component segments."""
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_project_path(project: str,) -> str:
"""Return a fully-qualified project string."""
return "projects/{project}".format(project=project,)

@staticmethod
def parse_common_project_path(path: str) -> Dict[str, str]:
"""Parse a project path into its component segments."""
m = re.match(r"^projects/(?P<project>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_location_path(project: str, location: str,) -> str:
"""Return a fully-qualified location string."""
return "projects/{project}/locations/{location}".format(
project=project, location=location,
)

@staticmethod
def parse_common_location_path(path: str) -> Dict[str, str]:
"""Parse a location path into its component segments."""
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
return m.groupdict() if m else {}

def __init__(
self,
*,
Expand Down Expand Up @@ -175,10 +243,10 @@ def __init__(
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.
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
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
_transport_registry["grpc"] = SpeechGrpcTransport
_transport_registry["grpc_asyncio"] = SpeechGrpcAsyncIOTransport


__all__ = (
"SpeechTransport",
"SpeechGrpcTransport",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def __init__(
for grpc channel. It is ignored if ``channel`` is provided.
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
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:
Expand All @@ -103,13 +103,16 @@ def __init__(
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._ssl_channel_credentials = ssl_channel_credentials

if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
warnings.warn(
"api_mtls_endpoint and client_cert_source are deprecated",
Expand Down Expand Up @@ -145,7 +148,12 @@ def __init__(
ssl_credentials=ssl_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"

Expand All @@ -162,9 +170,14 @@ def __init__(
ssl_credentials=ssl_channel_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

self._stubs = {} # type: Dict[str, Callable]
self._operations_client = None

# Run the base constructor.
super().__init__(
Expand All @@ -188,7 +201,7 @@ def create_channel(
) -> grpc.Channel:
"""Create and return a gRPC channel object.
Args:
address (Optionsl[str]): The host for the channel to use.
address (Optional[str]): The host for the channel to use.
credentials (Optional[~.Credentials]): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If
Expand Down Expand Up @@ -223,12 +236,8 @@ def create_channel(

@property
def grpc_channel(self) -> grpc.Channel:
"""Create the channel designed to connect to this service.
This property caches on the instance; repeated calls return
the same channel.
"""Return the channel designed to connect to this service.
"""
# Return the channel from cache.
return self._grpc_channel

@property
Expand All @@ -239,13 +248,11 @@ def operations_client(self) -> operations_v1.OperationsClient:
client.
"""
# Sanity check: Only create a new client if we do not already have one.
if "operations_client" not in self.__dict__:
self.__dict__["operations_client"] = operations_v1.OperationsClient(
self.grpc_channel
)
if self._operations_client is None:
self._operations_client = operations_v1.OperationsClient(self.grpc_channel)

# Return the client from cache.
return self.__dict__["operations_client"]
return self._operations_client

@property
def recognize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,16 @@ def __init__(
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._ssl_channel_credentials = ssl_channel_credentials

if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
warnings.warn(
"api_mtls_endpoint and client_cert_source are deprecated",
Expand Down Expand Up @@ -190,7 +193,12 @@ def __init__(
ssl_credentials=ssl_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"

Expand All @@ -207,6 +215,10 @@ def __init__(
ssl_credentials=ssl_channel_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

# Run the base constructor.
Expand All @@ -220,6 +232,7 @@ def __init__(
)

self._stubs = {}
self._operations_client = None

@property
def grpc_channel(self) -> aio.Channel:
Expand All @@ -239,13 +252,13 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient:
client.
"""
# Sanity check: Only create a new client if we do not already have one.
if "operations_client" not in self.__dict__:
self.__dict__["operations_client"] = operations_v1.OperationsAsyncClient(
if self._operations_client is None:
self._operations_client = operations_v1.OperationsAsyncClient(
self.grpc_channel
)

# Return the client from cache.
return self.__dict__["operations_client"]
return self._operations_client

@property
def recognize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
WordInfo,
)


__all__ = (
"RecognizeRequest",
"LongRunningRecognizeRequest",
Expand Down
Loading

0 comments on commit fa27bc4

Please sign in to comment.