Skip to content

Commit

Permalink
update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmayr committed Sep 17, 2024
1 parent c452744 commit 279fc56
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ jobs:
strategy:
# Run showcase tests on the lowest and highest supported runtimes
matrix:
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121) Remove `showcase_w_rest_async` target when async rest is GA.
python: ["3.7", "3.12"]
target: [showcase, showcase_alternative_templates]
target: [showcase, showcase_w_rest_async]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121): Remove the following variable (and the condition later in this file) for async rest transport once support for it is GA. #}
{% set rest_async_io_enabled = api.all_library_settings[api.naming.proto_package].python_settings.experimental_features.rest_async_io_enabled %}
{% extends '_base.py.j2' %}

{% block content %}

from collections import OrderedDict
from typing import Dict, Type
from typing import Dict, Type{% if rest_async_io_enabled %}, Tuple{% endif +%}

from .base import {{ service.name }}Transport
{% if 'grpc' in opts.transport %}
Expand All @@ -13,6 +15,16 @@ from .grpc_asyncio import {{ service.name }}GrpcAsyncIOTransport
{% if 'rest' in opts.transport %}
from .rest import {{ service.name }}RestTransport
from .rest import {{ service.name }}RestInterceptor
{% if rest_async_io_enabled %}
ASYNC_REST_CLASSES: Tuple[str, ...]
try:
from .rest_asyncio import Async{{ service.name }}RestTransport
ASYNC_REST_CLASSES = ('Async{{ service.name }}RestTransport',)
HAS_REST_ASYNC = True
except ImportError: # pragma: NO COVER
ASYNC_REST_CLASSES = ()
HAS_REST_ASYNC = False
{% endif %}{# if rest_async_io_enabled #}
{% endif %}


Expand All @@ -25,6 +37,10 @@ _transport_registry['grpc_asyncio'] = {{ service.name }}GrpcAsyncIOTransport
{% endif %}
{% if 'rest' in opts.transport %}
_transport_registry['rest'] = {{ service.name }}RestTransport
{% if rest_async_io_enabled %}
if HAS_REST_ASYNC: # pragma: NO COVER
_transport_registry['rest_asyncio'] = Async{{ service.name }}RestTransport
{% endif %}{# if rest_async_io_enabled #}
{% endif %}

__all__ = (
Expand All @@ -37,5 +53,5 @@ __all__ = (
'{{ service.name }}RestTransport',
'{{ service.name }}RestInterceptor',
{% endif %}
)
){% if 'rest' in opts.transport and rest_async_io_enabled%} + ASYNC_REST_CLASSES{%endif%}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,35 @@
# limitations under the License.
#
from collections import OrderedDict
from typing import Dict, Type
from typing import Dict, Type, Tuple

from .base import CloudRedisTransport
from .grpc import CloudRedisGrpcTransport
from .grpc_asyncio import CloudRedisGrpcAsyncIOTransport
from .rest import CloudRedisRestTransport
from .rest import CloudRedisRestInterceptor
ASYNC_REST_CLASSES: Tuple[str, ...]
try:
from .rest_asyncio import AsyncCloudRedisRestTransport
ASYNC_REST_CLASSES = ('AsyncCloudRedisRestTransport',)
HAS_REST_ASYNC = True
except ImportError: # pragma: NO COVER
ASYNC_REST_CLASSES = ()
HAS_REST_ASYNC = False


# Compile a registry of transports.
_transport_registry = OrderedDict() # type: Dict[str, Type[CloudRedisTransport]]
_transport_registry['grpc'] = CloudRedisGrpcTransport
_transport_registry['grpc_asyncio'] = CloudRedisGrpcAsyncIOTransport
_transport_registry['rest'] = CloudRedisRestTransport
if HAS_REST_ASYNC: # pragma: NO COVER
_transport_registry['rest_asyncio'] = AsyncCloudRedisRestTransport

__all__ = (
'CloudRedisTransport',
'CloudRedisGrpcTransport',
'CloudRedisGrpcAsyncIOTransport',
'CloudRedisRestTransport',
'CloudRedisRestInterceptor',
)
) + ASYNC_REST_CLASSES
25 changes: 18 additions & 7 deletions tests/system/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@
from google.showcase import EchoAsyncClient
from google.showcase import IdentityAsyncClient
try:
import google.showcase.transports.rest_asyncio
SHOWCASE_ASYNC_TRANSPORTS = ["grpc_asyncio", "rest_asyncio"]
from google.showcase_v1beta1.services.echo.transports import AsyncEchoRestTransport
HAS_ASYNC_REST_ECHO_TRANSPORT = True
except:
SHOWCASE_ASYNC_TRANSPORTS = ["grpc_asyncio"]
HAS_ASYNC_REST_ECHO_TRANSPORT = False
try:
from google.showcase_v1beta1.services.identity.transports import AsyncIdentityRestTransport
HAS_ASYNC_REST_IDENTITY_TRANSPORT = True
except:
HAS_ASYNC_REST_IDENTITY_TRANSPORT = False

# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded.
# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107.
Expand All @@ -62,22 +67,28 @@ def async_anonymous_credentials():
def event_loop():
return asyncio.get_event_loop()

@pytest.fixture(params=SHOWCASE_ASYNC_TRANSPORTS)
@pytest.fixture(params=["grpc_asyncio", "rest_asyncio"])
def async_echo(use_mtls, request, event_loop):
transport = request.param
if transport == "rest_asyncio" and not HAS_ASYNC_REST_ECHO_TRANSPORT:
pytest.skip("Skipping test with async rest.")
return construct_client(
EchoAsyncClient,
use_mtls,
transport_name=request.param,
transport_name=transport,
channel_creator=aio.insecure_channel if request.param == "grpc_asyncio" else None,
credentials=async_anonymous_credentials(),
)

@pytest.fixture(params=SHOWCASE_ASYNC_TRANSPORTS)
@pytest.fixture(params=["grpc_asyncio", "rest_asyncio"])
def async_identity(use_mtls, request, event_loop):
transport = request.param
if transport == "rest_asyncio" and not HAS_ASYNC_REST_IDENTITY_TRANSPORT:
pytest.skip("Skipping test with async rest.")
return construct_client(
IdentityAsyncClient,
use_mtls,
transport_name=request.param,
transport_name=transport,
channel_creator=aio.insecure_channel if request.param == "grpc_asyncio" else None,
credentials=async_anonymous_credentials(),
)
Expand Down

0 comments on commit 279fc56

Please sign in to comment.