Skip to content

Commit

Permalink
chore: pre-compute wrappers for mixins (#2186)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea authored Sep 24, 2024
1 parent c1c58bc commit bedbab8
Show file tree
Hide file tree
Showing 26 changed files with 276 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@

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

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

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

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

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

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

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

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

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

metadata = tuple(metadata)

Expand Down Expand Up @@ -369,11 +349,7 @@

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

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

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

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

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

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

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

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

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method.wrap_method(
self._transport.list_locations,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self._transport._wrapped_methods[self._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 @@ -391,6 +391,9 @@ def {{ name|snake_case }}(self):
return self._{{ name }}(self._session, self._host, self._interceptor) # type: ignore

class _{{ name }}(_Base{{ service.name }}RestTransport._Base{{name}}, {{ async_method_name_prefix }}{{service.name}}RestStub):
def __hash__(self):
return hash("{{ async_method_name_prefix }}{{ service.name }}RestTransport.{{ name }}")

{% set body_spec = api.mixin_http_options["{}".format(name)][0].body %}
{{ response_method(body_spec) | indent(4) }}

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

{% for name, sig in api.mixin_api_signatures.items() %}
class _Base{{ name }}:

{{ shared_macros.http_options_method(api.mixin_http_options["{}".format(name)])|indent(8)}}

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ class {{ service.name }}Transport(abc.ABC):
default_timeout={{ method.timeout }},
client_info=client_info,
),
{% endfor %} {# precomputed wrappers loop #}
{% endfor %}{# method in service.methods.values() #}
{% for method_name in api.mixin_api_methods.keys() %}
self.{{ method_name|snake_case }}: gapic_v1.method.wrap_method(
self.{{ method_name|snake_case }},
default_timeout=None,
client_info=client_info,
),
{% endfor %} {# method_name in api.mixin_api_methods.keys() #}
}

def close(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method.wrap_method(
self._transport.list_locations,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self._transport._wrapped_methods[self._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 @@ -384,6 +384,9 @@ def {{ name|snake_case }}(self):
return self._{{ name }}(self._session, self._host, self._interceptor) # type: ignore

class _{{ name }}(_Base{{ service.name }}RestTransport._Base{{name}}, {{ async_method_name_prefix }}{{service.name}}RestStub):
def __hash__(self):
return hash("{{ async_method_name_prefix }}{{ service.name }}RestTransport.{{ name }}")

{% set body_spec = api.mixin_http_options["{}".format(name)][0].body %}
{{ response_method(body_spec) | indent(4) }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

{% for name, sig in api.mixin_api_signatures.items() %}
class _Base{{ name }}:

def __hash__(self): # pragma: NO COVER
return NotImplementedError("__hash__ must be implemented.")

{{ shared_macros.http_options_method(api.mixin_http_options["{}".format(name)])|indent(8)}}

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ class {{ service.name }}Transport(abc.ABC):
default_timeout={{ method.timeout }},
client_info=client_info,
),
{% endfor %} {# precomputed wrappers loop #}
{% endfor %}{# method in service.methods.values() #}
{% for method_name in api.mixin_api_methods.keys() %}
self.{{ method_name|snake_case }}: gapic_v1.method.wrap_method(
self.{{ method_name|snake_case }},
default_timeout=None,
client_info=client_info,
),
{% endfor %} {# method_name in api.mixin_api_methods.keys() #}
}

def close(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3495,11 +3495,7 @@ def get_operation(

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method.wrap_method(
self._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
rpc = self._transport._wrapped_methods[self._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 @@ -306,6 +306,11 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=None,
client_info=client_info,
),
self.get_operation: gapic_v1.method.wrap_method(
self.get_operation,
default_timeout=None,
client_info=client_info,
),
}

def close(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2618,6 +2618,9 @@ def get_operation(self):
return self._GetOperation(self._session, self._host, self._interceptor) # type: ignore

class _GetOperation(_BaseAssetServiceRestTransport._BaseGetOperation, AssetServiceRestStub):
def __hash__(self):
return hash("AssetServiceRestTransport.GetOperation")

@staticmethod
def _get_response(
host,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,8 @@ def _get_query_params_json(transcoded_request):
return query_params

class _BaseGetOperation:
def __hash__(self): # pragma: NO COVER
return NotImplementedError("__hash__ must be implemented.")

@staticmethod
def _get_http_options():
Expand Down
Loading

0 comments on commit bedbab8

Please sign in to comment.