From ac9cad8f868533f8e887206a2deb2de401c8cdad Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 27 Apr 2024 13:19:30 +0000 Subject: [PATCH 01/10] fix: add support for protobuf 5.x --- .github/workflows/docs.yml | 6 + .github/workflows/lint.yml | 3 + .github/workflows/mypy.yml | 3 + .github/workflows/unittest.yml | 15 ++- .../api_core/operations_v1/transports/rest.py | 91 ++++++++++----- noxfile.py | 105 +++++++++++++++--- setup.py | 2 +- 7 files changed, 182 insertions(+), 43 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 698fbc5c..13d359b6 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -17,6 +17,9 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox + - name: Install pytest + run: | + python -m pip install pytest - name: Run docs run: | nox -s docs @@ -33,6 +36,9 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox + - name: Install pytest + run: | + python -m pip install pytest - name: Run docfx run: | nox -s docfx diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1051da0b..29499a8b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,6 +17,9 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox + - name: Install pytest + run: | + python -m pip install pytest - name: Run lint run: | nox -s lint diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index e6a79291..85f2db3e 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -17,6 +17,9 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox + - name: Install pytest + run: | + python -m pip install pytest - name: Run mypy run: | nox -s mypy diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 2cfaada3..20ccd9c3 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"] + option: ["", "_grpc_gcp", "_wo_grpc", "_prerelease"] python: - "3.7" - "3.8" @@ -26,6 +26,16 @@ jobs: python: 3.8 - option: "_wo_grpc" python: 3.9 + - option: "_prerelease" + python: 3.7 + - option: "_prerelease" + python: 3.8 + - option: "_prerelease" + python: 3.9 + - option: "_prerelease" + python: 3.10 + - option: "_prerelease" + python: 3.11 steps: - name: Checkout uses: actions/checkout@v4 @@ -37,6 +47,9 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox + - name: Install pytest + run: | + python -m pip install pytest - name: Run unit tests env: COVERAGE_FILE: .coverage${{ matrix.option }}-${{matrix.python }} diff --git a/google/api_core/operations_v1/transports/rest.py b/google/api_core/operations_v1/transports/rest.py index 49f99d21..03870465 100644 --- a/google/api_core/operations_v1/transports/rest.py +++ b/google/api_core/operations_v1/transports/rest.py @@ -29,9 +29,13 @@ from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf import json_format # type: ignore +import google.protobuf + import grpc from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO, OperationsTransport +PROTOBUF_VERSION = google.protobuf.__version__ + OptionalRetry = Union[retries.Retry, object] DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -184,11 +188,22 @@ def _list_operations( "google.longrunning.Operations.ListOperations" ] - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, - ) + # For backwards compatibility with protobuf 3.x 4.x + # Remove once support for protobuf 3.x and 4.x is dropped + # https://github.com/googleapis/python-api-core/issues/643 + if PROTOBUF_VERSION[0:2] in ["3.", "4."]: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + including_default_value_fields=True, # type: ignore # backward compatibility + ) + else: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + always_print_fields_with_no_presence=True, + ) + transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] @@ -199,7 +214,6 @@ def _list_operations( json_format.ParseDict(transcoded_request["query_params"], query_params_request) query_params = json_format.MessageToDict( query_params_request, - including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) @@ -265,11 +279,22 @@ def _get_operation( "google.longrunning.Operations.GetOperation" ] - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, - ) + # For backwards compatibility with protobuf 3.x 4.x + # Remove once support for protobuf 3.x and 4.x is dropped + # https://github.com/googleapis/python-api-core/issues/643 + if PROTOBUF_VERSION[0:2] in ["3.", "4."]: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + including_default_value_fields=True, # type: ignore # backward compatibility + ) + else: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + always_print_fields_with_no_presence=True, + ) + transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] @@ -280,7 +305,6 @@ def _get_operation( json_format.ParseDict(transcoded_request["query_params"], query_params_request) query_params = json_format.MessageToDict( query_params_request, - including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) @@ -339,11 +363,21 @@ def _delete_operation( "google.longrunning.Operations.DeleteOperation" ] - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, - ) + # For backwards compatibility with protobuf 3.x 4.x + # Remove once support for protobuf 3.x and 4.x is dropped + # https://github.com/googleapis/python-api-core/issues/643 + if PROTOBUF_VERSION[0:2] in ["3.", "4."]: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + including_default_value_fields=True, # type: ignore # backward compatibility + ) + else: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + always_print_fields_with_no_presence=True, + ) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] @@ -354,7 +388,6 @@ def _delete_operation( json_format.ParseDict(transcoded_request["query_params"], query_params_request) query_params = json_format.MessageToDict( query_params_request, - including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) @@ -411,11 +444,21 @@ def _cancel_operation( "google.longrunning.Operations.CancelOperation" ] - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, - ) + # For backwards compatibility with protobuf 3.x 4.x + # Remove once support for protobuf 3.x and 4.x is dropped + # https://github.com/googleapis/python-api-core/issues/643 + if PROTOBUF_VERSION[0:2] in ["3.", "4."]: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + including_default_value_fields=True, # type: ignore # backward compatibility + ) + else: + request_kwargs = json_format.MessageToDict( + request, + preserving_proto_field_name=True, + always_print_fields_with_no_presence=True, + ) transcoded_request = path_template.transcode(http_options, **request_kwargs) # Jsonify the request body @@ -423,7 +466,6 @@ def _cancel_operation( json_format.ParseDict(transcoded_request["body"], body_request) body = json_format.MessageToDict( body_request, - including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) @@ -435,7 +477,6 @@ def _cancel_operation( json_format.ParseDict(transcoded_request["query_params"], query_params_request) query_params = json_format.MessageToDict( query_params_request, - including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) diff --git a/noxfile.py b/noxfile.py index 2c7ec6c7..64e72177 100644 --- a/noxfile.py +++ b/noxfile.py @@ -15,6 +15,8 @@ from __future__ import absolute_import import os import pathlib +import pytest +import re import shutil # https://github.com/google/importlab/issues/25 @@ -26,6 +28,8 @@ # Black and flake8 clash on the syntax for ignoring flake8's F401 in this file. BLACK_EXCLUDES = ["--exclude", "^/google/api_core/operations_v1/__init__.py"] +PYTHON_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + DEFAULT_PYTHON_VERSION = "3.10" CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() @@ -72,7 +76,37 @@ def blacken(session): session.run("black", *BLACK_EXCLUDES, *BLACK_PATHS) -def default(session, install_grpc=True): +def install_prerelease_dependencies(session, constraints_path): + with open(constraints_path, encoding="utf-8") as constraints_file: + constraints_text = constraints_file.read() + # Ignore leading whitespace and comment lines. + constraints_deps = [ + match.group(1) + for match in re.finditer( + r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE + ) + ] + session.install(*constraints_deps) + prerel_deps = [ + "google-auth", + "googleapis-common-protos", + "grpcio", + "grpcio-status", + "proto-plus", + "protobuf", + ] + + for dep in prerel_deps: + session.install("--pre", "--no-deps", "--upgrade", dep) + + # Remaining dependencies + other_deps = [ + "requests", + ] + session.install(*other_deps) + + +def default(session, install_grpc=True, prerelease=False): """Default unit test session. This is intended to be run **without** an interpreter set, so @@ -80,9 +114,8 @@ def default(session, install_grpc=True): Python corresponding to the ``nox`` binary the ``PATH`` can run the tests. """ - constraints_path = str( - CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" - ) + if prerelease and not install_grpc: + pytest.skip("The pre-release session cannot be run without grpc") session.install( "dataclasses", @@ -92,10 +125,41 @@ def default(session, install_grpc=True): "pytest-xdist", ) - if install_grpc: - session.install("-e", ".[grpc]", "-c", constraints_path) + constraints_dir = str(CURRENT_DIRECTORY / "testing") + + if prerelease: + install_prerelease_dependencies( + session, f"{constraints_dir}/constraints-{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", ".", "-c", constraints_path) + if install_grpc: + session.install( + "-e", + ".[grpc]", + "-c", + f"{constraints_dir}/constraints-{session.python}.txt", + ) + else: + session.install( + "-e", ".", "-c", f"{constraints_dir}/constraints-{session.python}.txt" + ) + + # Print out package versions of dependencies + session.run( + "python", "-c", "import google.protobuf; print(google.protobuf.__version__)" + ) + # Support for proto.version was added in v1.23.0 + # https://github.com/googleapis/proto-plus-python/releases/tag/v1.23.0 + session.run( + "python", + "-c", + """import proto; hasattr(proto, "version") and print(proto.version.__version__)""", + ) + if install_grpc: + session.run("python", "-c", "import grpc; print(grpc.__version__)") + session.run("python", "-c", "import google.auth; print(google.auth.__version__)") pytest_args = [ "python", @@ -130,15 +194,26 @@ def default(session, install_grpc=True): session.run(*pytest_args) -@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]) +@nox.session(python=PYTHON_VERSIONS) def unit(session): """Run the unit test suite.""" default(session) -@nox.session(python=["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]) +@nox.session(python=PYTHON_VERSIONS[-1]) +def unit_prerelease(session): + """Run the unit test suite.""" + default(session, prerelease=True) + + +@nox.session(python=PYTHON_VERSIONS) def unit_grpc_gcp(session): - """Run the unit test suite with grpcio-gcp installed.""" + """ + Run the unit test suite with grpcio-gcp installed. + `grpcio-gcp` doesn't support protobuf 4+. + Remove extra `grpcgcp` when protobuf 3.x is dropped. + https://github.com/googleapis/python-api-core/issues/594 + """ constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) @@ -150,7 +225,7 @@ def unit_grpc_gcp(session): default(session) -@nox.session(python=["3.8", "3.10", "3.11", "3.12"]) +@nox.session(python=PYTHON_VERSIONS) def unit_wo_grpc(session): """Run the unit test suite w/o grpcio installed""" default(session, install_grpc=False) @@ -164,10 +239,10 @@ def lint_setup_py(session): session.run("python", "setup.py", "check", "--restructuredtext", "--strict") -@nox.session(python="3.8") +@nox.session(python=DEFAULT_PYTHON_VERSION) def pytype(session): """Run type-checking.""" - session.install(".[grpc]", "pytype >= 2019.3.21") + session.install(".[grpc]", "pytype") session.run("pytype") @@ -175,12 +250,10 @@ def pytype(session): def mypy(session): """Run type-checking.""" session.install(".[grpc]", "mypy") - # Exclude types-protobuf==4.24.0.20240106 - # See https://github.com/python/typeshed/issues/11254 session.install( "types-setuptools", "types-requests", - "types-protobuf!=4.24.0.20240106", + "types-protobuf", "types-mock", "types-dataclasses", ) diff --git a/setup.py b/setup.py index 47e0b454..a9e01f49 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ release_status = "Development Status :: 5 - Production/Stable" dependencies = [ "googleapis-common-protos >= 1.56.2, < 2.0.dev0", - "protobuf>=3.19.5,<5.0.0.dev0,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", + "protobuf>=3.19.5,<6.0.0.dev0,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5", "proto-plus >= 1.22.3, <2.0.0dev", "google-auth >= 2.14.1, < 3.0.dev0", "requests >= 2.18.0, < 3.0.0.dev0", From 13e156792eff4d45e15109b72e1d1cdb8e1c8408 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 29 Apr 2024 14:47:23 +0000 Subject: [PATCH 02/10] remove pin for types-protobuf --- noxfile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index a4de1e3a..64e72177 100644 --- a/noxfile.py +++ b/noxfile.py @@ -253,9 +253,7 @@ def mypy(session): session.install( "types-setuptools", "types-requests", - # TODO(https://github.com/googleapis/python-api-core/issues/642): - # Use the latest version of types-protobuf. - "types-protobuf<5", + "types-protobuf", "types-mock", "types-dataclasses", ) From 8b6bc48f1a1a3962765ec98ce7c8c8c3e75a33bd Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Mon, 29 Apr 2024 20:49:10 +0000 Subject: [PATCH 03/10] remove pytest from noxfile --- .github/workflows/docs.yml | 6 ------ .github/workflows/lint.yml | 3 --- .github/workflows/mypy.yml | 3 --- .github/workflows/unittest.yml | 3 --- noxfile.py | 4 ++-- 5 files changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 13d359b6..698fbc5c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -17,9 +17,6 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox - - name: Install pytest - run: | - python -m pip install pytest - name: Run docs run: | nox -s docs @@ -36,9 +33,6 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox - - name: Install pytest - run: | - python -m pip install pytest - name: Run docfx run: | nox -s docfx diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 29499a8b..1051da0b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,9 +17,6 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox - - name: Install pytest - run: | - python -m pip install pytest - name: Run lint run: | nox -s lint diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 85f2db3e..e6a79291 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -17,9 +17,6 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox - - name: Install pytest - run: | - python -m pip install pytest - name: Run mypy run: | nox -s mypy diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 00a391c0..3b2020ba 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -47,9 +47,6 @@ jobs: run: | python -m pip install --upgrade setuptools pip wheel python -m pip install nox - - name: Install pytest - run: | - python -m pip install pytest - name: Run unit tests env: COVERAGE_FILE: .coverage${{ matrix.option }}-${{matrix.python }} diff --git a/noxfile.py b/noxfile.py index 64e72177..ee6ffee2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -15,9 +15,9 @@ from __future__ import absolute_import import os import pathlib -import pytest import re import shutil +import unittest # https://github.com/google/importlab/issues/25 import nox # pytype: disable=import-error @@ -115,7 +115,7 @@ def default(session, install_grpc=True, prerelease=False): run the tests. """ if prerelease and not install_grpc: - pytest.skip("The pre-release session cannot be run without grpc") + unittest.skip("The pre-release session cannot be run without grpc") session.install( "dataclasses", From 5a49a53603c97a6d65deb9b23bb084699ef3372a Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 11 Jun 2024 19:40:56 +0000 Subject: [PATCH 04/10] refactor common code --- .../api_core/operations_v1/transports/rest.py | 98 +++++++------------ 1 file changed, 36 insertions(+), 62 deletions(-) diff --git a/google/api_core/operations_v1/transports/rest.py b/google/api_core/operations_v1/transports/rest.py index 03870465..a2d0fb6a 100644 --- a/google/api_core/operations_v1/transports/rest.py +++ b/google/api_core/operations_v1/transports/rest.py @@ -188,22 +188,7 @@ def _list_operations( "google.longrunning.Operations.ListOperations" ] - # For backwards compatibility with protobuf 3.x 4.x - # Remove once support for protobuf 3.x and 4.x is dropped - # https://github.com/googleapis/python-api-core/issues/643 - if PROTOBUF_VERSION[0:2] in ["3.", "4."]: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, # type: ignore # backward compatibility - ) - else: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - always_print_fields_with_no_presence=True, - ) - + request_kwargs = self._convert_protobuf_message_to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] @@ -279,22 +264,7 @@ def _get_operation( "google.longrunning.Operations.GetOperation" ] - # For backwards compatibility with protobuf 3.x 4.x - # Remove once support for protobuf 3.x and 4.x is dropped - # https://github.com/googleapis/python-api-core/issues/643 - if PROTOBUF_VERSION[0:2] in ["3.", "4."]: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, # type: ignore # backward compatibility - ) - else: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - always_print_fields_with_no_presence=True, - ) - + request_kwargs = self._convert_protobuf_message_to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] @@ -363,21 +333,7 @@ def _delete_operation( "google.longrunning.Operations.DeleteOperation" ] - # For backwards compatibility with protobuf 3.x 4.x - # Remove once support for protobuf 3.x and 4.x is dropped - # https://github.com/googleapis/python-api-core/issues/643 - if PROTOBUF_VERSION[0:2] in ["3.", "4."]: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, # type: ignore # backward compatibility - ) - else: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - always_print_fields_with_no_presence=True, - ) + request_kwargs = self._convert_protobuf_message_to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] @@ -444,21 +400,7 @@ def _cancel_operation( "google.longrunning.Operations.CancelOperation" ] - # For backwards compatibility with protobuf 3.x 4.x - # Remove once support for protobuf 3.x and 4.x is dropped - # https://github.com/googleapis/python-api-core/issues/643 - if PROTOBUF_VERSION[0:2] in ["3.", "4."]: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - including_default_value_fields=True, # type: ignore # backward compatibility - ) - else: - request_kwargs = json_format.MessageToDict( - request, - preserving_proto_field_name=True, - always_print_fields_with_no_presence=True, - ) + request_kwargs = self._convert_protobuf_message_to_dict(request) transcoded_request = path_template.transcode(http_options, **request_kwargs) # Jsonify the request body @@ -499,6 +441,38 @@ def _cancel_operation( return empty_pb2.Empty() + def _convert_protobuf_message_to_dict( + self, message: google.protobuf.message.Message + ): + r"""Converts protobuf message to a dictionary. + + When the dictionary is encoded to JSON, it conforms to proto3 JSON spec. + + Args: + message(google.protobuf.message.Message): The protocol buffers message + instance to serialize. + + Returns: + A dict representation of the protocol buffer message. + """ + # For backwards compatibility with protobuf 3.x 4.x + # Remove once support for protobuf 3.x and 4.x is dropped + # https://github.com/googleapis/python-api-core/issues/643 + if PROTOBUF_VERSION[0:2] in ["3.", "4."]: + result = json_format.MessageToDict( + message, + preserving_proto_field_name=True, + including_default_value_fields=True, # type: ignore # backward compatibility + ) + else: + result = json_format.MessageToDict( + message, + preserving_proto_field_name=True, + always_print_fields_with_no_presence=True, + ) + + return result + @property def list_operations( self, From 3bca72cbc6712aaff37e9015f597d109698d37fe Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 11 Jun 2024 15:42:30 -0400 Subject: [PATCH 05/10] Refactor Co-authored-by: Victor Chudnovsky --- noxfile.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/noxfile.py b/noxfile.py index ee6ffee2..e0950029 100644 --- a/noxfile.py +++ b/noxfile.py @@ -134,16 +134,11 @@ def default(session, install_grpc=True, prerelease=False): # This *must* be the last install command to get the package from source. session.install("-e", ".", "--no-deps") else: - if install_grpc: - session.install( - "-e", - ".[grpc]", - "-c", - f"{constraints_dir}/constraints-{session.python}.txt", - ) - else: - session.install( - "-e", ".", "-c", f"{constraints_dir}/constraints-{session.python}.txt" + session.install( + "-e", + ".[grpc]" if install_grpc else ".", + "-c", + f"{constraints_dir}/constraints-{session.python}.txt", ) # Print out package versions of dependencies From f263d69659e98e96d42295cdb52a8788c5ae8945 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 11 Jun 2024 19:43:14 +0000 Subject: [PATCH 06/10] run black --- google/api_core/operations_v1/__init__.py | 6 ++++-- noxfile.py | 2 +- owlbot.py | 4 ++-- tests/unit/test_rest_streaming.py | 8 +++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/google/api_core/operations_v1/__init__.py b/google/api_core/operations_v1/__init__.py index 61186451..8b75426b 100644 --- a/google/api_core/operations_v1/__init__.py +++ b/google/api_core/operations_v1/__init__.py @@ -14,7 +14,9 @@ """Package for interacting with the google.longrunning.operations meta-API.""" -from google.api_core.operations_v1.abstract_operations_client import AbstractOperationsClient +from google.api_core.operations_v1.abstract_operations_client import ( + AbstractOperationsClient, +) from google.api_core.operations_v1.operations_async_client import OperationsAsyncClient from google.api_core.operations_v1.operations_client import OperationsClient from google.api_core.operations_v1.transports.rest import OperationsRestTransport @@ -23,5 +25,5 @@ "AbstractOperationsClient", "OperationsAsyncClient", "OperationsClient", - "OperationsRestTransport" + "OperationsRestTransport", ] diff --git a/noxfile.py b/noxfile.py index e0950029..cb1204df 100644 --- a/noxfile.py +++ b/noxfile.py @@ -139,7 +139,7 @@ def default(session, install_grpc=True, prerelease=False): ".[grpc]" if install_grpc else ".", "-c", f"{constraints_dir}/constraints-{session.python}.txt", - ) + ) # Print out package versions of dependencies session.run( diff --git a/owlbot.py b/owlbot.py index 5a83032e..c8c76542 100644 --- a/owlbot.py +++ b/owlbot.py @@ -29,8 +29,8 @@ ".flake8", # flake8-import-order, layout ".coveragerc", # layout "CONTRIBUTING.rst", # no systests - ".github/workflows/unittest.yml", # exclude unittest gh action - ".github/workflows/lint.yml", # exclude lint gh action + ".github/workflows/unittest.yml", # exclude unittest gh action + ".github/workflows/lint.yml", # exclude lint gh action "README.rst", ] templated_files = common.py_library(microgenerator=True, cov_level=100) diff --git a/tests/unit/test_rest_streaming.py b/tests/unit/test_rest_streaming.py index b532eb1d..0f2b3b32 100644 --- a/tests/unit/test_rest_streaming.py +++ b/tests/unit/test_rest_streaming.py @@ -101,9 +101,11 @@ def _parse_responses(self, responses: List[proto.Message]) -> bytes: # json.dumps returns a string surrounded with quotes that need to be stripped # in order to be an actual JSON. json_responses = [ - self._response_message_cls.to_json(r).strip('"') - if issubclass(self._response_message_cls, proto.Message) - else MessageToJson(r).strip('"') + ( + self._response_message_cls.to_json(r).strip('"') + if issubclass(self._response_message_cls, proto.Message) + else MessageToJson(r).strip('"') + ) for r in responses ] logging.info(f"Sending JSON stream: {json_responses}") From 23964956a0112e230ae9c4ec501149b1ff7283c6 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Tue, 11 Jun 2024 19:44:09 +0000 Subject: [PATCH 07/10] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index e0950029..cb1204df 100644 --- a/noxfile.py +++ b/noxfile.py @@ -139,7 +139,7 @@ def default(session, install_grpc=True, prerelease=False): ".[grpc]" if install_grpc else ".", "-c", f"{constraints_dir}/constraints-{session.python}.txt", - ) + ) # Print out package versions of dependencies session.run( From 7fbce0dfe60502f4b9e8502f2bef11dc9a2c551b Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 11 Jun 2024 19:46:28 +0000 Subject: [PATCH 08/10] mypy --- google/api_core/operations_v1/transports/base.py | 2 +- google/api_core/operations_v1/transports/rest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/google/api_core/operations_v1/transports/base.py b/google/api_core/operations_v1/transports/base.py index 98cf7896..fb1d4fc9 100644 --- a/google/api_core/operations_v1/transports/base.py +++ b/google/api_core/operations_v1/transports/base.py @@ -45,7 +45,7 @@ def __init__( self, *, host: str = DEFAULT_HOST, - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, diff --git a/google/api_core/operations_v1/transports/rest.py b/google/api_core/operations_v1/transports/rest.py index a2d0fb6a..f37bb344 100644 --- a/google/api_core/operations_v1/transports/rest.py +++ b/google/api_core/operations_v1/transports/rest.py @@ -70,7 +70,7 @@ def __init__( self, *, host: str = "longrunning.googleapis.com", - credentials: ga_credentials.Credentials = None, + credentials: Optional[ga_credentials.Credentials] = None, credentials_file: Optional[str] = None, scopes: Optional[Sequence[str]] = None, client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None, From e1efa83cb43ddd9413e540fbdab90763a7231e87 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 11 Jun 2024 19:57:16 +0000 Subject: [PATCH 09/10] run pre-release test against all python versions --- .github/workflows/unittest.yml | 12 +----------- noxfile.py | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 3b2020ba..34d29b7c 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", "_prerelease"] + option: ["", "_grpc_gcp", "_wo_grpc", "_with_prerelease_deps"] python: - "3.7" - "3.8" @@ -26,16 +26,6 @@ jobs: python: 3.8 - option: "_wo_grpc" python: 3.9 - - option: "_prerelease" - python: 3.7 - - option: "_prerelease" - python: 3.8 - - option: "_prerelease" - python: 3.9 - - option: "_prerelease" - python: 3.10 - - option: "_prerelease" - python: 3.11 steps: - name: Checkout uses: actions/checkout@v4 diff --git a/noxfile.py b/noxfile.py index cb1204df..593bfc85 100644 --- a/noxfile.py +++ b/noxfile.py @@ -195,8 +195,8 @@ def unit(session): default(session) -@nox.session(python=PYTHON_VERSIONS[-1]) -def unit_prerelease(session): +@nox.session(python=PYTHON_VERSIONS) +def unit_with_prerelease_deps(session): """Run the unit test suite.""" default(session, prerelease=True) From 28a41f8d8c04d83c46c140cf6aa76b7e2519df82 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Tue, 11 Jun 2024 20:01:21 +0000 Subject: [PATCH 10/10] filter warning --- pytest.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytest.ini b/pytest.ini index 13d5bf4d..696548cf 100644 --- a/pytest.ini +++ b/pytest.ini @@ -19,3 +19,5 @@ filterwarnings = ignore:.*pkg_resources is deprecated as an API:DeprecationWarning # Remove once https://github.com/grpc/grpc/issues/35086 is fixed (and version newer than 1.60.0 is published) ignore:There is no current event loop:DeprecationWarning + # Remove after support for Python 3.7 is dropped + ignore:After January 1, 2024, new releases of this library will drop support for Python 3.7:DeprecationWarning