Skip to content

Commit

Permalink
feat: implement async rest mixin methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmayr committed Sep 20, 2024
1 parent e9b6954 commit d2b45c9
Show file tree
Hide file tree
Showing 15 changed files with 979 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
TEMP_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=DEFAULT_CLIENT_INFO.gapic_version,
grpc_version=None,
rest_version=google.auth.__version__
)
rpc = self._client._transport._wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
client_info=TEMP_CLIENT_INFO,
) # type: ignore

# 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 @@ -304,8 +304,6 @@ class {{ async_method_name_prefix }}{{ service.name }}RestInterceptor:
{% endif %}{# if (not is_async) or (is_async and not method.lro and not method.extended_lro and not method.paged_result_field) #}
{% endfor %}

{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2148): Remove the condition below once mixins are supported for async rest transport. #}
{% if not is_async %}
{% for name, signature in api.mixin_api_signatures.items() %}
{{ async_prefix }}def pre_{{ name|snake_case }}(
self, request: {{signature.request_type}}, metadata: Sequence[Tuple[str, str]]
Expand All @@ -328,7 +326,6 @@ class {{ async_method_name_prefix }}{{ service.name }}RestInterceptor:
"""
return response
{% endfor %}
{% endif %}
{% endmacro %}

{% macro generate_mixin_call_method(service, api, name, sig, is_async) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from google.api_core.client_options import ClientOptions
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
return self._{{method.name}}(self._session, self._host, self._interceptor) # type: ignore

{% endfor %}
{% for name, sig in api.mixin_api_signatures.items() %}
{{ shared_macros.generate_mixin_call_method(service, api, name, sig, is_async=True) | indent(4) }}
{% endfor %}

@property
def kind(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1910,11 +1910,8 @@ def test_unsupported_parameter_rest_asyncio():
{% endfor %}{# for method in service.methods.values() #}
{% for name, sig in api.mixin_api_signatures.items() %}
{% if 'rest' in transport %}
{# TODO: Remove the following condition as we implement async mixins #}
{% if not is_async %}
{{ bad_request_mixins_test(service, api, name, sig, transport, is_async) }}
{{ call_success_mixins_test(service, api, name, sig, transport, is_async) }}
{% endif %}{# if not is_async #}
{% endif %}{# if 'rest' in transport #}
{% endfor %}
{{ initialize_client_with_transport_test(service, transport, is_async) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down Expand Up @@ -3100,11 +3101,16 @@ 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(
TEMP_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=DEFAULT_CLIENT_INFO.gapic_version,
grpc_version=None,
rest_version=google.auth.__version__
)
rpc = self._client._transport._wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
client_info=TEMP_CLIENT_INFO,
) # type: ignore

# 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 @@ -23,6 +23,7 @@
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down Expand Up @@ -2556,11 +2557,16 @@ 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(
TEMP_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=DEFAULT_CLIENT_INFO.gapic_version,
grpc_version=None,
rest_version=google.auth.__version__
)
rpc = self._client._transport._wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
client_info=TEMP_CLIENT_INFO,
) # type: ignore

# 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 @@ -23,6 +23,7 @@
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down Expand Up @@ -3876,11 +3877,16 @@ 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(
TEMP_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=DEFAULT_CLIENT_INFO.gapic_version,
grpc_version=None,
rest_version=google.auth.__version__
)
rpc = self._client._transport._wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
client_info=TEMP_CLIENT_INFO,
) # type: ignore

# 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 @@ -23,6 +23,7 @@
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down Expand Up @@ -1057,11 +1058,16 @@ 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(
TEMP_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=DEFAULT_CLIENT_INFO.gapic_version,
grpc_version=None,
rest_version=google.auth.__version__
)
rpc = self._client._transport._wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
client_info=TEMP_CLIENT_INFO,
) # type: ignore

# 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 @@ -23,6 +23,7 @@
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down Expand Up @@ -909,11 +910,16 @@ 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(
TEMP_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=DEFAULT_CLIENT_INFO.gapic_version,
grpc_version=None,
rest_version=google.auth.__version__
)
rpc = self._client._transport._wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
client_info=TEMP_CLIENT_INFO,
) # type: ignore

# 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 @@ -23,6 +23,7 @@
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry_async as retries
import google.auth
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand Down Expand Up @@ -1798,11 +1799,16 @@ 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(
TEMP_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=DEFAULT_CLIENT_INFO.gapic_version,
grpc_version=None,
rest_version=google.auth.__version__
)
rpc = self._client._transport._wrap_method(
self._client._transport.get_operation,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)
client_info=TEMP_CLIENT_INFO,
) # type: ignore

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

0 comments on commit d2b45c9

Please sign in to comment.