Skip to content

Commit

Permalink
chore: precompute wrappers for async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmayr committed Sep 24, 2024
1 parent bedbab8 commit 8696ed7
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _get_http_options():
{% endmacro %}


{% macro prep_wrapped_messages_async_method(service) %}
{% macro prep_wrapped_messages_async_method(api, service) %}
def _prep_wrapped_messages(self, client_info):
""" Precompute the wrapped methods, overriding the base class method to use async wrappers."""
self._wrapped_methods = {
Expand Down Expand Up @@ -265,6 +265,13 @@ def _prep_wrapped_messages(self, client_info):
client_info=client_info,
),
{% endfor %}{# service.methods.values() #}
{% for method_name in api.mixin_api_methods.keys() %}
self.{{ method_name|snake_case }}: self._wrap_method(
self.{{ method_name|snake_case }},
default_timeout=None,
client_info=client_info,
),
{% endfor %} {# method_name in api.mixin_api_methods.keys() #}
}
{% endmacro %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_operations,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.list_operations]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -91,11 +87,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -151,11 +143,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.delete_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.delete_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -206,11 +194,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.cancel_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.cancel_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -264,11 +248,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.wait_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.wait_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -390,12 +370,8 @@
request = iam_policy_pb2.SetIamPolicyRequest(**request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.set_iam_policy,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
# and friendly error handling
rpc = self.transport._wrapped_methods[self._client._transport.set_iam_policy]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -514,11 +490,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_iam_policy,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_iam_policy]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -575,11 +547,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.test_iam_permissions,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.test_iam_permissions]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -635,11 +603,8 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_location,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_location]


# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -691,11 +656,7 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_locations,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.list_locations]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _get_http_options():
{% endmacro %}


{% macro prep_wrapped_messages_async_method(service) %}
{% macro prep_wrapped_messages_async_method(api, service) %}
def _prep_wrapped_messages(self, client_info):
""" Precompute the wrapped methods, overriding the base class method to use async wrappers."""
self._wrapped_methods = {
Expand Down Expand Up @@ -258,6 +258,13 @@ def _prep_wrapped_messages(self, client_info):
client_info=client_info,
),
{% endfor %}{# service.methods.values() #}
{% for method_name in api.mixin_api_methods.keys() %}
self.{{ method_name|snake_case }}: self._wrap_method(
self.{{ method_name|snake_case }},
default_timeout=None,
client_info=client_info,
),
{% endfor %}{# method_name in api.mixin_api_methods.keys() #}
}
{% endmacro %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,7 @@ class {{ service.async_client_name }}:

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.set_iam_policy,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.set_iam_policy]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -632,11 +628,7 @@ class {{ service.async_client_name }}:

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_iam_policy,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_iam_policy]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -689,11 +681,7 @@ class {{ service.async_client_name }}:

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.test_iam_permissions,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.test_iam_permissions]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):
return self._stubs["test_iam_permissions"]
{% endif %}

{{ shared_macros.prep_wrapped_messages_async_method(service)|indent(4) }}
{{ shared_macros.prep_wrapped_messages_async_method(api, service)|indent(4) }}

{{ shared_macros.wrap_async_method_macro()|indent(4) }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
self._wrap_with_kind = True
self._prep_wrapped_messages(client_info)

{{ shared_macros.prep_wrapped_messages_async_method(service)|indent(4) }}
{{ shared_macros.prep_wrapped_messages_async_method(api, service)|indent(4) }}

{{ shared_macros.wrap_async_method_macro()|indent(4) }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3100,11 +3100,7 @@ async def get_operation(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,11 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=None,
client_info=client_info,
),
self.get_operation: self._wrap_method(
self.get_operation,
default_timeout=None,
client_info=client_info,
),
}

def _wrap_method(self, func, *args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2502,11 +2502,7 @@ async def list_operations(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_operations,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.list_operations]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -2556,11 +2552,7 @@ async def get_operation(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -2614,11 +2606,7 @@ async def delete_operation(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.delete_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.delete_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -2667,11 +2655,7 @@ async def cancel_operation(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.cancel_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.cancel_operation]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -2782,12 +2766,8 @@ async def set_iam_policy(
request = iam_policy_pb2.SetIamPolicyRequest(**request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.set_iam_policy,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
# and friendly error handling
rpc = self.transport._wrapped_methods[self._client._transport.set_iam_policy]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -2904,11 +2884,7 @@ async def get_iam_policy(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_iam_policy,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_iam_policy]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -2963,11 +2939,7 @@ async def test_iam_permissions(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.test_iam_permissions,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.test_iam_permissions]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -3017,11 +2989,7 @@ async def get_location(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.get_location,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.get_location]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down Expand Up @@ -3071,11 +3039,7 @@ async def list_locations(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_locations,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self.transport._wrapped_methods[self._client._transport.list_locations]

# Certain fields should be provided within the metadata header;
# add these here.
Expand Down
Loading

0 comments on commit 8696ed7

Please sign in to comment.