From 3f26e81710803d2625c4bdeaca75a4eb7dd90f01 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 20 Sep 2024 18:50:51 +0000 Subject: [PATCH 1/7] fix: add extra for aiohttp --- .github/workflows/unittest.yml | 2 +- google/api_core/rest_streaming_async.py | 2 +- noxfile.py | 48 ++++++++++++++-------- setup.py | 3 ++ testing/constraints-3.7.txt | 1 - testing/constraints-async-rest-3.7.txt | 17 ++++++++ tests/asyncio/test_rest_streaming_async.py | 2 +- 7 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 testing/constraints-async-rest-3.7.txt diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 5980f825..5a7c0359 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - option: ["", "_grpc_gcp", "_wo_grpc", "_with_prerelease_deps", "_with_auth_aio"] + option: ["", "_grpc_gcp", "_wo_grpc", "_with_prerelease_deps", "_with_async_rest_extra"] python: - "3.7" - "3.8" diff --git a/google/api_core/rest_streaming_async.py b/google/api_core/rest_streaming_async.py index 812854c5..7175c876 100644 --- a/google/api_core/rest_streaming_async.py +++ b/google/api_core/rest_streaming_async.py @@ -22,7 +22,7 @@ import google.auth.aio.transport except ImportError as e: # pragma: NO COVER raise ImportError( - "google-auth>=2.35.0 is required to use asynchronous rest streaming." + "google-api-core[async_rest] is required to use asynchronous rest streaming." ) from e import google.protobuf.message diff --git a/noxfile.py b/noxfile.py index 3fc4a722..6de68af6 100644 --- a/noxfile.py +++ b/noxfile.py @@ -38,7 +38,7 @@ "unit", "unit_grpc_gcp", "unit_wo_grpc", - "unit_with_auth_aio", + "unit_with_async_rest_extra", "cover", "pytype", "mypy", @@ -110,7 +110,7 @@ def install_prerelease_dependencies(session, constraints_path): session.install(*other_deps) -def default(session, install_grpc=True, prerelease=False, install_auth_aio=False): +def default(session, install_grpc=True, prerelease=False, install_async_rest=False): """Default unit test session. This is intended to be run **without** an interpreter set, so @@ -130,24 +130,40 @@ def default(session, install_grpc=True, prerelease=False, install_auth_aio=False ) constraints_dir = str(CURRENT_DIRECTORY / "testing") - + constraints_type = "async-rest-" if install_async_rest else "" if prerelease: install_prerelease_dependencies( - session, f"{constraints_dir}/constraints-{PYTHON_VERSIONS[0]}.txt" + session, + f"{constraints_dir}/constraints-{constraints_type}{PYTHON_VERSIONS[0]}.txt", ) # This *must* be the last install command to get the package from source. - session.install("-e", ".", "--no-deps") - else: session.install( - "-e", - ".[grpc]" if install_grpc else ".", - "-c", - f"{constraints_dir}/constraints-{session.python}.txt", + "-e", "." + ("[async_rest]" if install_async_rest else ""), "--no-deps" ) + else: + constraints_file = ( + f"{constraints_dir}/constraints-{constraints_type}{session.python}.txt" + ) + # fall back to standard constraints file + if not pathlib.Path(constraints_file).exists(): + constraints_file = f"{constraints_dir}/constraints-{session.python}.txt" - if install_auth_aio: session.install( - "google-auth @ git+https://git@github.com/googleapis/google-auth-library-python@8833ad6f92c3300d6645355994c7db2356bd30ad" + "-e", + "." + + ( + "[grpc,async_rest]" + if install_grpc and install_async_rest + else ( + "[grpc]" + if install_grpc + else "[async_rest]" + if install_async_rest + else "" + ) + ), + "-c", + constraints_file, ) # Print out package versions of dependencies @@ -236,9 +252,9 @@ def unit_wo_grpc(session): @nox.session(python=PYTHON_VERSIONS) -def unit_with_auth_aio(session): - """Run the unit test suite with google.auth.aio installed""" - default(session, install_auth_aio=True) +def unit_with_async_rest_extra(session): + """Run the unit test suite with the `async_rest` extra""" + default(session, install_async_rest=True) @nox.session(python=DEFAULT_PYTHON_VERSION) @@ -261,7 +277,7 @@ def mypy(session): """Run type-checking.""" # TODO(https://github.com/googleapis/python-api-core/issues/682): # Use the latest version of mypy instead of mypy<1.11.0 - session.install(".[grpc]", "mypy<1.11.0") + session.install(".[grpc,async_rest]", "mypy<1.11.0") session.install( "types-setuptools", "types-requests", diff --git a/setup.py b/setup.py index a9e01f49..d3c2a2b4 100644 --- a/setup.py +++ b/setup.py @@ -36,6 +36,9 @@ "requests >= 2.18.0, < 3.0.0.dev0", ] extras = { + "async_rest": [ + "google-auth[aiohttp] >= 2.35.0, < 3.0.dev0", + ], "grpc": [ "grpcio >= 1.33.2, < 2.0dev", "grpcio >= 1.49.1, < 2.0dev; python_version>='3.11'", diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt index fcc9831f..4ce1c899 100644 --- a/testing/constraints-3.7.txt +++ b/testing/constraints-3.7.txt @@ -9,7 +9,6 @@ googleapis-common-protos==1.56.2 protobuf==3.19.5 google-auth==2.14.1 requests==2.18.0 -packaging==14.3 grpcio==1.33.2 grpcio-status==1.33.2 grpcio-gcp==0.2.2 diff --git a/testing/constraints-async-rest-3.7.txt b/testing/constraints-async-rest-3.7.txt new file mode 100644 index 00000000..7aedeb1c --- /dev/null +++ b/testing/constraints-async-rest-3.7.txt @@ -0,0 +1,17 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List *all* library dependencies and extras in this file. +# Pin the version to the lower bound. +# +# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", +# Then this file should have foo==1.14.0 +googleapis-common-protos==1.56.2 +protobuf==3.19.5 +google-auth==2.35.0 +# from google-auth[aiohttp] +aiohttp==3.6.2 +requests==2.20.0 +grpcio==1.33.2 +grpcio-status==1.33.2 +grpcio-gcp==0.2.2 +proto-plus==1.22.3 diff --git a/tests/asyncio/test_rest_streaming_async.py b/tests/asyncio/test_rest_streaming_async.py index 35820de6..62413a25 100644 --- a/tests/asyncio/test_rest_streaming_async.py +++ b/tests/asyncio/test_rest_streaming_async.py @@ -35,7 +35,7 @@ if not AUTH_AIO_INSTALLED: # pragma: NO COVER pytest.skip( - "google-auth>=2.35.0 is required to use asynchronous rest streaming.", + "google-api-core[async_rest] is required to use asynchronous rest streaming.", allow_module_level=True, ) From a8af7912063eeaa09688051da2659a9badab9d08 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 21 Sep 2024 13:36:12 +0000 Subject: [PATCH 2/7] improve error message --- google/api_core/rest_streaming_async.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/google/api_core/rest_streaming_async.py b/google/api_core/rest_streaming_async.py index 7175c876..370c2b53 100644 --- a/google/api_core/rest_streaming_async.py +++ b/google/api_core/rest_streaming_async.py @@ -22,7 +22,9 @@ import google.auth.aio.transport except ImportError as e: # pragma: NO COVER raise ImportError( - "google-api-core[async_rest] is required to use asynchronous rest streaming." + "`google-api-core[async_rest]` is required to use asynchronous rest streaming. " + "Install the `async_rest` extra of `google-api-core` using " + "`pip install google-api-core[async_rest]`." ) from e import google.protobuf.message From 9f7d36c90ed2f4f287a9305e6b18431f04d616c6 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 21 Sep 2024 13:38:04 +0000 Subject: [PATCH 3/7] with -> w; apply same change to prerelease_deps --- .github/workflows/unittest.yml | 2 +- noxfile.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 5a7c0359..2d1193d6 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - option: ["", "_grpc_gcp", "_wo_grpc", "_with_prerelease_deps", "_with_async_rest_extra"] + option: ["", "_grpc_gcp", "_wo_grpc", "_w_prerelease_deps", "_w_async_rest_extra"] python: - "3.7" - "3.8" diff --git a/noxfile.py b/noxfile.py index 6de68af6..cd3129e1 100644 --- a/noxfile.py +++ b/noxfile.py @@ -38,7 +38,8 @@ "unit", "unit_grpc_gcp", "unit_wo_grpc", - "unit_with_async_rest_extra", + "unit_w_prerelease_deps", + "unit_w_async_rest_extra", "cover", "pytype", "mypy", @@ -221,7 +222,7 @@ def unit(session): @nox.session(python=PYTHON_VERSIONS) -def unit_with_prerelease_deps(session): +def unit_w_prerelease_deps(session): """Run the unit test suite.""" default(session, prerelease=True) @@ -252,7 +253,7 @@ def unit_wo_grpc(session): @nox.session(python=PYTHON_VERSIONS) -def unit_with_async_rest_extra(session): +def unit_w_async_rest_extra(session): """Run the unit test suite with the `async_rest` extra""" default(session, install_async_rest=True) From cc20eb8e3c20e9c6170020d4bf382fb1f115d07d Mon Sep 17 00:00:00 2001 From: ohmayr Date: Mon, 30 Sep 2024 15:22:09 +0000 Subject: [PATCH 4/7] move error to try block --- tests/asyncio/test_rest_streaming_async.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/asyncio/test_rest_streaming_async.py b/tests/asyncio/test_rest_streaming_async.py index 62413a25..da5b1c8d 100644 --- a/tests/asyncio/test_rest_streaming_async.py +++ b/tests/asyncio/test_rest_streaming_async.py @@ -28,14 +28,9 @@ try: from google.auth.aio.transport import Response - - AUTH_AIO_INSTALLED = True except ImportError: - AUTH_AIO_INSTALLED = False - -if not AUTH_AIO_INSTALLED: # pragma: NO COVER pytest.skip( - "google-api-core[async_rest] is required to use asynchronous rest streaming.", + "google-api-core[async_rest] is required to test asynchronous rest streaming.", allow_module_level=True, ) From ea1349201c3e5db794a447d6329d1e620dc9b5a4 Mon Sep 17 00:00:00 2001 From: ohmayr Date: Mon, 30 Sep 2024 20:34:31 +0000 Subject: [PATCH 5/7] address feedback --- noxfile.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/noxfile.py b/noxfile.py index cd3129e1..4d3c5ec0 100644 --- a/noxfile.py +++ b/noxfile.py @@ -130,8 +130,17 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal "pytest-xdist", ) + install_extras = [] + if install_grpc: + install_extras.append("grpc") + constraints_dir = str(CURRENT_DIRECTORY / "testing") - constraints_type = "async-rest-" if install_async_rest else "" + if install_async_rest: + install_extras.append("async_rest") + constraints_type = "async-rest-" + else: + constraints_type = "" + if prerelease: install_prerelease_dependencies( session, @@ -139,7 +148,7 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal ) # This *must* be the last install command to get the package from source. session.install( - "-e", "." + ("[async_rest]" if install_async_rest else ""), "--no-deps" + "-e", f".[{','.join(install_extras)}]", "--no-deps" ) else: constraints_file = ( @@ -151,18 +160,7 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal session.install( "-e", - "." - + ( - "[grpc,async_rest]" - if install_grpc and install_async_rest - else ( - "[grpc]" - if install_grpc - else "[async_rest]" - if install_async_rest - else "" - ) - ), + f".[{','.join(install_extras)}]", "-c", constraints_file, ) From 3174c46f335a3e34cf1cdc07aebe443d33fd3b44 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 30 Sep 2024 20:36:25 +0000 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- noxfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 4d3c5ec0..5ffea990 100644 --- a/noxfile.py +++ b/noxfile.py @@ -147,9 +147,7 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal f"{constraints_dir}/constraints-{constraints_type}{PYTHON_VERSIONS[0]}.txt", ) # This *must* be the last install command to get the package from source. - session.install( - "-e", f".[{','.join(install_extras)}]", "--no-deps" - ) + session.install("-e", f".[{','.join(install_extras)}]", "--no-deps") else: constraints_file = ( f"{constraints_dir}/constraints-{constraints_type}{session.python}.txt" From 4b7620bdc309ff2cd735bfdb64e2cc1c1546ecbf Mon Sep 17 00:00:00 2001 From: ohmayr Date: Mon, 30 Sep 2024 20:52:23 +0000 Subject: [PATCH 7/7] update noxfile --- noxfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/noxfile.py b/noxfile.py index 5ffea990..144e3e21 100644 --- a/noxfile.py +++ b/noxfile.py @@ -141,13 +141,14 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal else: constraints_type = "" + lib_with_extras = f".[{','.join(install_extras)}]" if len(install_extras) else "." if prerelease: install_prerelease_dependencies( session, f"{constraints_dir}/constraints-{constraints_type}{PYTHON_VERSIONS[0]}.txt", ) # This *must* be the last install command to get the package from source. - session.install("-e", f".[{','.join(install_extras)}]", "--no-deps") + session.install("-e", lib_with_extras, "--no-deps") else: constraints_file = ( f"{constraints_dir}/constraints-{constraints_type}{session.python}.txt" @@ -158,7 +159,7 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal session.install( "-e", - f".[{','.join(install_extras)}]", + lib_with_extras, "-c", constraints_file, )