-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement async rest transport constructor #2123
Conversation
5f258b8
to
9b45d08
Compare
90999f3
to
7d58f1f
Compare
b90b18f
to
7124af4
Compare
097aa19
to
9f9471d
Compare
9f9471d
to
f4f941c
Compare
fbceb22
to
dd34d55
Compare
2c28ab3
to
6cad5b9
Compare
dd34d55
to
aa4bfa6
Compare
aa4bfa6
to
d9f8d2b
Compare
6cad5b9
to
fcc89de
Compare
.github/workflows/tests.yaml
Outdated
@@ -140,7 +140,7 @@ jobs: | |||
strategy: | |||
matrix: | |||
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] | |||
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins] | |||
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, "_w_rest_async"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the previous entries were a comprehensive listing of various combinations (on/off along two axes: alternate_templates, mixins). Now it seems like you're adding another axis, async_rest, so we should have 8 entries to test all combinations. (In other words, with _w_rest_async
, what are we using for template type and for mixins?
Ideally, we would have a 2x2x2 matrix here of (template-type, mixins, rest_async). That said, we don't want to get too distracted from the async work right now, so maybe simply a comment about what this variant includes/excludes is fine for now.
gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2
Outdated
Show resolved
Hide resolved
{% if rest_async_io_enabled %} | ||
from .transports.rest_asyncio import Async{{ service.name }}RestTransport | ||
{% endif %}{# if rest_async_io_enabled #} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% if rest_async_io_enabled %} | |
from .transports.rest_asyncio import Async{{ service.name }}RestTransport | |
{% endif %}{# if rest_async_io_enabled #} | |
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121): Remove this condition (and the variable set at the top of this file) for async rest transport once support for it is GA #} | |
{% if rest_async_io_enabled %} | |
from .transports.rest_asyncio import Async{{ service.name }}RestTransport | |
{% endif %}{# if rest_async_io_enabled #} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also use the same format for these GA-TODOs in the other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed.
@@ -79,6 +87,9 @@ class {{ service.client_name }}Meta(type): | |||
{% endif %} | |||
{% if "rest" in opts.transport %} | |||
_transport_registry["rest"] = {{ service.name }}RestTransport | |||
{% if rest_async_io_enabled %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{# TODO(#2121): Remove this condition when async rest is GA #}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL. GitHub shortened and hyperlinked the full URL I intended here.
{% macro transport_kind_test(service, transport_name) %} | ||
{%- set named_clients = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% macro transport_kind_test(service, transport_name) %} | |
{%- set named_clients = { | |
{% macro transport_kind_test(service, transport_name) %} | |
{# Look-up tables for parameter values corresponding to each possible transport-name #} | |
{%- set named_clients = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up removing this dict since there's only two possible clients that we can have i.e. sync or async. Added a separate macro for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@contextmanager | ||
def showcase_library( | ||
session, templates="DEFAULT", other_opts: typing.Iterable[str] = (), | ||
include_service_yaml=True, | ||
retry_config=True, | ||
rest_async_io_enabled=False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should also have a TODO to remove the param once async REST is GA?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed.
gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2
Outdated
Show resolved
Hide resolved
gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Show resolved
Hide resolved
{% macro get_client(service, is_async) %} | ||
{{-service.async_client_name if is_async else service.client_name-}} | ||
{% endmacro %} | ||
|
||
{% macro transport_kind_test(service, transport_name, is_async) %} | ||
def test_transport_kind_{{transport_name}}(): | ||
transport = {{ get_client(service, is_async) }}.get_transport_class("{{transport_name}}")( | ||
credentials={{get_credentials(is_async)}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{% macro get_client(service, is_async) %} | |
{{-service.async_client_name if is_async else service.client_name-}} | |
{% endmacro %} | |
{% macro transport_kind_test(service, transport_name, is_async) %} | |
def test_transport_kind_{{transport_name}}(): | |
transport = {{ get_client(service, is_async) }}.get_transport_class("{{transport_name}}")( | |
credentials={{get_credentials(is_async)}} | |
{% macro get_client(service, is_async) %} | |
{{- service.async_client_name if is_async else service.client_name -}} | |
{% endmacro %} | |
{% macro transport_kind_test(service, transport_name, is_async) %} | |
def test_transport_kind_{{ transport_name }}(): | |
transport = {{ get_client(service, is_async) }}.get_transport_class("{{ transport_name }}")( | |
credentials={{ get_credentials(is_async) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed.
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Outdated
Show resolved
Hide resolved
gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2
Outdated
Show resolved
Hide resolved
@@ -79,6 +87,9 @@ class {{ service.client_name }}Meta(type): | |||
{% endif %} | |||
{% if "rest" in opts.transport %} | |||
_transport_registry["rest"] = {{ service.name }}RestTransport | |||
{% if rest_async_io_enabled %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL. GitHub shortened and hyperlinked the full URL I intended here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! Looks great!
This PR introduces an async rest transport with minimal parameters and a
kind
property. It also sets up the testing infra for async rest i.e: