-
Notifications
You must be signed in to change notification settings - Fork 82
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
fix: add support for protobuf 5.x #644
Changes from 5 commits
ac9cad8
a62ea6e
13e1567
8b6bc48
583b8ce
5a49a53
3bca72c
f263d69
2396495
ef6050f
7fbce0d
e1efa83
28a41f8
0037d7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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) | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have this block repeated in four places. I suggest factoring it out into a helper function that only needs to take one parameter:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 5a49a53 |
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
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, | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is essentially also converting a message to a dict. So we could use a similar approach to what we're doing for I'll leave it up to you since this isn't a blocker! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took a closer look at making this change and I don't believe the helper function will result in fewer lines of code. The reason that we had the helper function elsewhere was to remove duplication for the protobuf 3.x/4.x compatibility code but we don't have the duplication here. |
||||||||||||||||||||||||||||||||||||||
|
@@ -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,19 +444,28 @@ 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 | ||||||||||||||||||||||||||||||||||||||
body_request = operations_pb2.CancelOperationRequest() | ||||||||||||||||||||||||||||||||||||||
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, | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,7 +15,9 @@ | |||||||||||||||||||||||||||||||||||||||
from __future__ import absolute_import | ||||||||||||||||||||||||||||||||||||||||
import os | ||||||||||||||||||||||||||||||||||||||||
import pathlib | ||||||||||||||||||||||||||||||||||||||||
import re | ||||||||||||||||||||||||||||||||||||||||
import shutil | ||||||||||||||||||||||||||||||||||||||||
import unittest | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# https://github.com/google/importlab/issues/25 | ||||||||||||||||||||||||||||||||||||||||
import nox # pytype: disable=import-error | ||||||||||||||||||||||||||||||||||||||||
|
@@ -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,17 +76,46 @@ def blacken(session): | |||||||||||||||||||||||||||||||||||||||
session.run("black", *BLACK_EXCLUDES, *BLACK_PATHS) | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
def default(session, install_grpc=True): | ||||||||||||||||||||||||||||||||||||||||
def install_prerelease_dependencies(session, constraints_path): | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I have gaps in my mental model for testing prerelease; This installs our dependencies at pre-release versions, right? Is the only difference, then, the use of (It might be easier to talk synchronously about this.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a difference in that we don't allow transitive dependencies in the |
||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||
that the current ``python`` (on the ``PATH``) or the version of | ||||||||||||||||||||||||||||||||||||||||
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: | ||||||||||||||||||||||||||||||||||||||||
unittest.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" | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused: in line 206, where we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the comment in below, the constraints file for the lowest supported python version contains a list of all of the dependencies of the library. The function python-api-core/testing/constraints-3.7.txt Lines 1 to 7 in 126b5c7
Lines 79 to 88 in 7fbce0d
Once we have a list of dependencies, we will install them independently with the Lines 99 to 100 in 7fbce0d
|
||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||
# 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" | ||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||
parthea marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# 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): | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this tests running against the pre-release versions of the dependencies, right? And we only bother to do this with the latest Python run-time. A comment might be helpful. Also, my personal preference would to rename this (and similar code elsewhere) as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in e1efa83 |
||||||||||||||||||||||||||||||||||||||||
"""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) | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify, do we want to run this against all versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We normally only run it on 1 version but we can expand it if there is value |
||||||||||||||||||||||||||||||||||||||||
def pytype(session): | ||||||||||||||||||||||||||||||||||||||||
"""Run type-checking.""" | ||||||||||||||||||||||||||||||||||||||||
session.install(".[grpc]", "pytype >= 2019.3.21") | ||||||||||||||||||||||||||||||||||||||||
session.install(".[grpc]", "pytype") | ||||||||||||||||||||||||||||||||||||||||
session.run("pytype") | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
@@ -178,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", | ||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||
|
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 think this more succinct code should work (I haven't tested it) and would be easier to maintain.
Ref: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
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 comment is obsolete with the changes in e1efa83