Skip to content

Commit

Permalink
Add 'client_options' support, update list method docstrings (via synt…
Browse files Browse the repository at this point in the history
…h). (#8524)
  • Loading branch information
yoshi-automation authored and tseaver committed Jun 28, 2019
1 parent 1534ac4 commit 1ad94c2
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 32 deletions.
33 changes: 24 additions & 9 deletions tasks/google/cloud/tasks_v2/gapic/cloud_tasks_client.py
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -123,6 +124,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -153,6 +155,9 @@ def __init__(
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.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -171,6 +176,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -179,6 +193,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=cloud_tasks_grpc_transport.CloudTasksGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -189,7 +204,7 @@ def __init__(
self.transport = transport
else:
self.transport = cloud_tasks_grpc_transport.CloudTasksGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -280,10 +295,10 @@ def list_queues(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.tasks_v2.types.Queue` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.tasks_v2.types.Queue` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down Expand Up @@ -1245,10 +1260,10 @@ def list_tasks(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.tasks_v2.types.Task` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.tasks_v2.types.Task` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
33 changes: 24 additions & 9 deletions tasks/google/cloud/tasks_v2beta2/gapic/cloud_tasks_client.py
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -125,6 +126,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -155,6 +157,9 @@ def __init__(
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.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -173,6 +178,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -181,6 +195,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=cloud_tasks_grpc_transport.CloudTasksGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -191,7 +206,7 @@ def __init__(
self.transport = transport
else:
self.transport = cloud_tasks_grpc_transport.CloudTasksGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -282,10 +297,10 @@ def list_queues(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.tasks_v2beta2.types.Queue` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.tasks_v2beta2.types.Queue` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down Expand Up @@ -1247,10 +1262,10 @@ def list_tasks(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.tasks_v2beta2.types.Task` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.tasks_v2beta2.types.Task` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
33 changes: 24 additions & 9 deletions tasks/google/cloud/tasks_v2beta3/gapic/cloud_tasks_client.py
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -123,6 +124,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -153,6 +155,9 @@ def __init__(
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.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -171,6 +176,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -179,6 +193,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=cloud_tasks_grpc_transport.CloudTasksGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -189,7 +204,7 @@ def __init__(
self.transport = transport
else:
self.transport = cloud_tasks_grpc_transport.CloudTasksGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -280,10 +295,10 @@ def list_queues(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.tasks_v2beta3.types.Queue` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.tasks_v2beta3.types.Queue` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down Expand Up @@ -1263,10 +1278,10 @@ def list_tasks(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.tasks_v2beta3.types.Task` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.tasks_v2beta3.types.Task` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
10 changes: 5 additions & 5 deletions tasks/synth.metadata
@@ -1,19 +1,19 @@
{
"updateTime": "2019-06-18T12:31:27.002476Z",
"updateTime": "2019-06-28T12:37:20.592791Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.27.0",
"dockerImage": "googleapis/artman@sha256:b036a7f4278d9deb5796f065e5c7f608d47d75369985ca7ab5039998120e972d"
"version": "0.29.2",
"dockerImage": "googleapis/artman@sha256:45263333b058a4b3c26a8b7680a2710f43eae3d250f791a6cb66423991dcb2df"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "384aa843867c4d17756d14a01f047b6368494d32",
"internalRef": "253675319"
"sha": "84c8ad4e52f8eec8f08a60636cfa597b86969b5c",
"internalRef": "255474859"
}
},
{
Expand Down

0 comments on commit 1ad94c2

Please sign in to comment.