From a6c178965f0e7864866626c47bd3f677675ebaac Mon Sep 17 00:00:00 2001 From: ohmayr Date: Tue, 24 Sep 2024 17:59:47 +0000 Subject: [PATCH] feat: add async rest option in setup --- gapic/templates/setup.py.j2 | 6 ++++++ gapic/templates/testing/_default_constraints.j2 | 5 +++++ gapic/templates/testing/constraints-3.7.txt.j2 | 7 +++++++ noxfile.py | 4 ---- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gapic/templates/setup.py.j2 b/gapic/templates/setup.py.j2 index 48427184f9..9813f50e12 100644 --- a/gapic/templates/setup.py.j2 +++ b/gapic/templates/setup.py.j2 @@ -46,6 +46,12 @@ dependencies = [ {% endif %} {% endfor %} ] +extras = { + "async_rest": [ + "google-api-core[grpc] >= 2.20.0, < 3.0.0dev", + "google-auth[aiohttp] >= 2.35.0, <3.0.0dev" + ], +} url = "https://github.com/googleapis/google-cloud-python/tree/main/packages/{{ api.naming.warehouse_package_name }}" package_root = os.path.abspath(os.path.dirname(__file__)) diff --git a/gapic/templates/testing/_default_constraints.j2 b/gapic/templates/testing/_default_constraints.j2 index 6a62cfc52d..4554c454db 100644 --- a/gapic/templates/testing/_default_constraints.j2 +++ b/gapic/templates/testing/_default_constraints.j2 @@ -1,7 +1,12 @@ +{# 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 %} {% from '_pypi_packages.j2' import pypi_packages %} # This constraints file is required for unit tests. # List all library dependencies and extras in this file. google-api-core +{% if rest_async_io_enabled %} +google-auth[aiohttp]==2.35.0 +{% endif %} proto-plus protobuf {% for package_tuple, package_info in pypi_packages.items() %} diff --git a/gapic/templates/testing/constraints-3.7.txt.j2 b/gapic/templates/testing/constraints-3.7.txt.j2 index 3dbaa6f382..cd38adef97 100644 --- a/gapic/templates/testing/constraints-3.7.txt.j2 +++ b/gapic/templates/testing/constraints-3.7.txt.j2 @@ -1,3 +1,5 @@ +{# 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 %} {% from '_pypi_packages.j2' import pypi_packages %} # This constraints file is used to check that lower bounds # are correct in setup.py @@ -5,8 +7,13 @@ # Pin the version to the lower bound. # e.g., if setup.py has "google-cloud-foo >= 1.14.0, < 2.0.0dev", # Then this file should have google-cloud-foo==1.14.0 +{% if rest_async_io_enabled %} +google-api-core==2.20.0 +google-auth[aiohttp]==2.35.0 +{% else %} google-api-core==1.34.1 google-auth==2.14.1 +{% endif %} proto-plus==1.22.3 protobuf==3.20.2 {% for package_tuple, package_info in pypi_packages.items() %} diff --git a/noxfile.py b/noxfile.py index b1eea2b5cd..8d52c97a7b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -363,8 +363,6 @@ def showcase_w_rest_async( ignore_path = test_directory / ignore_file pytest_command.extend(["--ignore", str(ignore_path)]) - # Note: google-auth is re-installed here with aiohttp option to override the version installed in constraints. - session.install('--no-cache-dir', '--force-reinstall', "google-auth[aiohttp]") session.run( *pytest_command, env=env, @@ -485,8 +483,6 @@ def showcase_unit_w_rest_async( """Run the generated unit tests with async rest transport against the Showcase library.""" with showcase_library(session, templates=templates, other_opts=other_opts, rest_async_io_enabled=True) as lib: session.chdir(lib) - # Note: google-auth is re-installed here with aiohttp option to override the version installed in constraints. - session.install('--no-cache-dir', '--force-reinstall', "google-auth[aiohttp]") run_showcase_unit_tests(session, rest_async_io_enabled=True)