Skip to content

Commit

Permalink
Merge branch 'master' into fix-exceptions-port
Browse files Browse the repository at this point in the history
  • Loading branch information
busunkim96 authored May 12, 2021
2 parents 67e456e + 29c201b commit d0731a5
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 76 deletions.
8 changes: 4 additions & 4 deletions gapic/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_response(
sample_templates, client_templates = utils.partition(
lambda fname: os.path.basename(
fname) == samplegen.DEFAULT_TEMPLATE_NAME,
self._env.loader.list_templates(),
self._env.loader.list_templates(), # type: ignore
)

# Iterate over each template and add the appropriate output files
Expand All @@ -113,7 +113,7 @@ def get_response(
sample_output = self._generate_samples_and_manifest(
api_schema, self._env.get_template(sample_templates[0]),
opts=opts,
)
)
output_files.update(sample_output)

# Return the CodeGeneratorResponse output.
Expand Down Expand Up @@ -286,10 +286,10 @@ def _render_template(
for service in api_schema.services.values():
if (
(skip_subpackages
and service.meta.address.subpackage != api_schema.subpackage_view)
and service.meta.address.subpackage != api_schema.subpackage_view)
or
('transport' in template_name
and not self._is_desired_transport(template_name, opts))
and not self._is_desired_transport(template_name, opts))
or
# TODO(yon-mg) - remove when rest async implementation resolved
# temporarily stop async client gen while rest async is unkown
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '_base.py.j2' %}
{% extends "_base.py.j2" %}

{% block content %}

Expand Down Expand Up @@ -51,7 +51,8 @@ class {{ service.async_client_name }}:

@classmethod
def from_service_account_info(cls, info: dict, *args, **kwargs):
"""Creates an instance of this client using the provided credentials info.
"""Creates an instance of this client using the provided credentials
info.

Args:
info (dict): The service account private key info.
Expand All @@ -66,7 +67,7 @@ class {{ service.async_client_name }}:
@classmethod
def from_service_account_file(cls, filename: str, *args, **kwargs):
"""Creates an instance of this client using the provided credentials
file.
file.

Args:
filename (str): The path to the service account private key json
Expand All @@ -83,7 +84,7 @@ class {{ service.async_client_name }}:

@property
def transport(self) -> {{ service.name }}Transport:
"""Return the transport used by the client instance.
"""Returns the transport used by the client instance.

Returns:
{{ service.name }}Transport: The transport used by the client instance.
Expand All @@ -95,11 +96,11 @@ class {{ service.async_client_name }}:

def __init__(self, *,
credentials: ga_credentials.Credentials = None,
transport: Union[str, {{ service.name }}Transport] = 'grpc_asyncio',
transport: Union[str, {{ service.name }}Transport] = "grpc_asyncio",
client_options: ClientOptions = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the {{ (service.client_name|snake_case).replace('_', ' ') }}.
"""Instantiates the {{ (service.client_name|snake_case).replace("_", " ") }}.

Args:
credentials (Optional[google.auth.credentials.Credentials]): The
Expand Down Expand Up @@ -165,7 +166,7 @@ class {{ service.async_client_name }}:
Args:
{% if not method.client_streaming %}
request (:class:`{{ method.input.ident.sphinx }}`):
The request object.{{ ' ' }}
The request object.{{ " " }}
{{- method.input.meta.doc|wrap(width=72, offset=36, indent=16) }}
{% for key, field in method.flattened_fields.items() %}
{{ field.name }} (:class:`{{ field.ident.sphinx }}`):
Expand All @@ -176,7 +177,7 @@ class {{ service.async_client_name }}:
{% endfor %}
{% else %}
requests (AsyncIterator[`{{ method.input.ident.sphinx }}`]):
The request object AsyncIterator.{{ ' ' }}
The request object AsyncIterator.{{ " " }}
{{- method.input.meta.doc|wrap(width=72, offset=36, indent=16) }}
{% endif %}
retry (google.api_core.retry.Retry): Designation of what errors, if any,
Expand All @@ -200,10 +201,10 @@ class {{ service.async_client_name }}:
{% if method.flattened_fields %}
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([{{ method.flattened_fields.values()|join(', ', attribute='name') }}])
has_flattened_params = any([{{ method.flattened_fields.values()|join(", ", attribute="name") }}])
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.')
raise ValueError("If the `request` argument is set, then none of "
"the individual field arguments should be set.")

{% endif %}
{% if method.input.ident.package != method.ident.package %} {# request lives in a different package, so there is no proto wrapper #}
Expand Down Expand Up @@ -251,7 +252,7 @@ class {{ service.async_client_name }}:
{% if method.retry.max_backoff %}maximum={{ method.retry.max_backoff }},{% endif %}
{% if method.retry.backoff_multiplier %}multiplier={{ method.retry.backoff_multiplier }},{% endif %}
predicate=retries.if_exception_type(
{% for ex in method.retry.retryable_exceptions|sort(attribute='__name__') %}
{% for ex in method.retry.retryable_exceptions|sort(attribute="__name__") %}
core_exceptions.{{ ex.__name__ }},
{% endfor %}
),
Expand All @@ -269,7 +270,7 @@ class {{ service.async_client_name }}:
gapic_v1.routing_header.to_grpc_metadata((
{% for field_header in method.field_headers %}
{% if not method.client_streaming %}
('{{ field_header }}', request.{{ field_header }}),
("{{ field_header }}", request.{{ field_header }}),
{% endif %}
{% endfor %}
)),
Expand Down Expand Up @@ -313,7 +314,7 @@ class {{ service.async_client_name }}:
# Done; return the response.
return response
{% endif %}
{{ '\n' }}
{{ "\n" }}
{% endfor %}


Expand All @@ -326,8 +327,10 @@ class {{ service.async_client_name }}:
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
r"""Sets the IAM access control policy on the specified
function. Replaces any existing policy.
r"""Sets the IAM access control policy on the specified function.

Replaces any existing policy.

Args:
request (:class:`~.policy_pb2.SetIamPolicyRequest`):
The request object. Request message for `SetIamPolicy`
Expand Down Expand Up @@ -433,8 +436,10 @@ class {{ service.async_client_name }}:
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
r"""Gets the IAM access control policy for a function.

Returns an empty policy if the function exists and does
not have a policy set.

Args:
request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`):
The request object. Request message for `GetIamPolicy`
Expand Down Expand Up @@ -540,8 +545,11 @@ class {{ service.async_client_name }}:
metadata: Sequence[Tuple[str, str]] = (),
) -> iam_policy_pb2.TestIamPermissionsResponse:
r"""Tests the specified permissions against the IAM access control
policy for a function. If the function does not exist, this will
policy for a function.

If the function does not exist, this will
return an empty set of permissions, not a NOT_FOUND error.

Args:
request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`):
The request object. Request message for
Expand Down Expand Up @@ -586,14 +594,14 @@ class {{ service.async_client_name }}:
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution(
'{{ api.naming.warehouse_package_name }}',
"{{ api.naming.warehouse_package_name }}",
).version,
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()


__all__ = (
'{{ service.async_client_name }}',
"{{ service.async_client_name }}",
)
{% endblock %}
Loading

0 comments on commit d0731a5

Please sign in to comment.