Skip to content

Commit b4d4551

Browse files
partheavchudnov-g
andauthored
fix: Allow protobuf 6.x (#13637)
Apply changes from googleapis/gapic-generator-python#2352 and googleapis/gapic-generator-python#2347 to 4 packages containing protobuf stubs which are not automatically generated using `gapic-generator-python` BEGIN_COMMIT_OVERRIDE fix: Allow protobuf 6.x fix: resolve issue where pre-release versions of dependencies are installed END_COMMIT_OVERRIDE --------- Co-authored-by: Victor Chudnovsky <vchudnov@google.com>
1 parent fef876b commit b4d4551

File tree

5 files changed

+122
-30
lines changed

5 files changed

+122
-30
lines changed

packages/google-cloud-access-context-manager/noxfile.py

Lines changed: 114 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,24 @@ def docfx(session):
382382
["python", "upb", "cpp"],
383383
)
384384
def prerelease_deps(session, protobuf_implementation):
385-
"""Run all tests with prerelease versions of dependencies installed."""
385+
"""
386+
Run all tests with pre-release versions of dependencies installed
387+
rather than the standard non pre-release versions.
388+
Pre-release versions can be installed using
389+
`pip install --pre <package>`.
390+
"""
386391

387392
if protobuf_implementation == "cpp" and session.python in ("3.11", "3.12", "3.13"):
388393
session.skip("cpp implementation is not supported in python 3.11+")
389394

390395
# Install all dependencies
391-
session.install("-e", ".[all, tests, tracing]")
396+
session.install("-e", ".")
397+
398+
# Install dependencies for the unit test environment
392399
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
393400
session.install(*unit_deps_all)
401+
402+
# Install dependencies for the system test environment
394403
system_deps_all = (
395404
SYSTEM_TEST_STANDARD_DEPENDENCIES
396405
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
@@ -417,39 +426,122 @@ def prerelease_deps(session, protobuf_implementation):
417426
)
418427
]
419428

429+
# Install dependencies specified in `testing/constraints-X.txt`.
420430
session.install(*constraints_deps)
421431

432+
# Note: If a dependency is added to the `prerel_deps` list,
433+
# the `core_dependencies_from_source` list in the `core_deps_from_source`
434+
# nox session should also be updated.
422435
prerel_deps = [
423-
"protobuf",
424-
# dependency of grpc
425-
"six",
426-
"grpc-google-iam-v1",
427436
"googleapis-common-protos",
428-
"grpcio",
429-
"grpcio-status",
430437
"google-api-core",
431438
"google-auth",
439+
"grpc-google-iam-v1",
440+
"grpcio",
441+
"grpcio-status",
442+
"protobuf",
432443
"proto-plus",
433-
"google-cloud-testutils",
434-
# dependencies of google-cloud-testutils"
435-
"click",
436444
]
437445

438446
for dep in prerel_deps:
439-
session.install("--pre", "--no-deps", "--upgrade", dep)
440-
441-
# Remaining dependencies
442-
other_deps = [
443-
"requests",
444-
]
445-
session.install(*other_deps)
447+
session.install("--pre", "--no-deps", "--ignore-installed", dep)
448+
# TODO(https://github.com/grpc/grpc/issues/38965): Add `grpcio-status``
449+
# to the dictionary below once this bug is fixed.
450+
# TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add
451+
# `googleapis-common-protos` and `grpc-google-iam-v1` to the dictionary below
452+
# once this bug is fixed.
453+
package_namespaces = {
454+
"google-api-core": "google.api_core",
455+
"google-auth": "google.auth",
456+
"grpcio": "grpc",
457+
"protobuf": "google.protobuf",
458+
"proto-plus": "proto",
459+
}
460+
461+
version_namespace = package_namespaces.get(dep)
462+
463+
print(f"Installed {dep}")
464+
if version_namespace:
465+
session.run(
466+
"python",
467+
"-c",
468+
f"import {version_namespace}; print({version_namespace}.__version__)",
469+
)
446470

447-
# Print out prerelease package versions
448471
session.run(
449-
"python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
472+
"py.test",
473+
"tests/unit",
474+
env={
475+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
476+
},
477+
)
478+
479+
480+
@nox.session(python="3.13")
481+
@nox.parametrize(
482+
"protobuf_implementation",
483+
["python", "upb"],
484+
)
485+
def core_deps_from_source(session, protobuf_implementation):
486+
"""Run all tests with core dependencies installed from source
487+
rather than pulling the dependencies from PyPI.
488+
"""
489+
490+
# Install all dependencies
491+
session.install("-e", ".")
492+
493+
# Install dependencies for the unit test environment
494+
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
495+
session.install(*unit_deps_all)
496+
497+
# Install dependencies for the system test environment
498+
system_deps_all = (
499+
SYSTEM_TEST_STANDARD_DEPENDENCIES
500+
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
501+
+ SYSTEM_TEST_EXTRAS
450502
)
451-
session.run("python", "-c", "import grpc; print(grpc.__version__)")
452-
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")
503+
session.install(*system_deps_all)
504+
505+
# Because we test minimum dependency versions on the minimum Python
506+
# version, the first version we test with in the unit tests sessions has a
507+
# constraints file containing all dependencies and extras.
508+
with open(
509+
CURRENT_DIRECTORY
510+
/ "testing"
511+
/ f"constraints-{UNIT_TEST_PYTHON_VERSIONS[0]}.txt",
512+
encoding="utf-8",
513+
) as constraints_file:
514+
constraints_text = constraints_file.read()
515+
516+
# Ignore leading whitespace and comment lines.
517+
constraints_deps = [
518+
match.group(1)
519+
for match in re.finditer(
520+
r"^\s*(\S+)(?===\S+)", constraints_text, flags=re.MULTILINE
521+
)
522+
]
523+
524+
# Install dependencies specified in `testing/constraints-X.txt`.
525+
session.install(*constraints_deps)
526+
527+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and
528+
# `grpcio-status` should be added to the list below so that they are installed from source,
529+
# rather than PyPI.
530+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be
531+
# added to the list below so that it is installed from source, rather than PyPI
532+
# Note: If a dependency is added to the `core_dependencies_from_source` list,
533+
# the `prerel_deps` list in the `prerelease_deps` nox session should also be updated.
534+
core_dependencies_from_source = [
535+
f"{CURRENT_DIRECTORY}/../googleapis-common-protos",
536+
"google-api-core @ git+https://github.com/googleapis/python-api-core.git",
537+
"google-auth @ git+https://github.com/googleapis/google-auth-library-python.git",
538+
f"{CURRENT_DIRECTORY}/../grpc-google-iam-v1",
539+
"proto-plus @ git+https://github.com/googleapis/proto-plus-python.git",
540+
]
541+
542+
for dep in core_dependencies_from_source:
543+
session.install(dep, "--no-deps", "--ignore-installed")
544+
print(f"Installed {dep}")
453545

454546
session.run(
455547
"py.test",

packages/google-cloud-access-context-manager/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
# 'Development Status :: 5 - Production/Stable'
3030
release_status = "Development Status :: 4 - Beta"
3131
dependencies = [
32-
"google-api-core[grpc] >= 1.34.1, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
33-
"protobuf>=3.20.2,<6.0.0dev,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
32+
"google-api-core[grpc] >= 1.34.1, <3.0.0,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.*,!=2.4.*,!=2.5.*,!=2.6.*,!=2.7.*,!=2.8.*,!=2.9.*,!=2.10.*",
33+
"protobuf>=3.20.2,<7.0.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
3434
]
3535

3636
# Setup boilerplate below this line.

packages/google-cloud-audit-log/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
version = "0.3.1"
2424
release_status = "Development Status :: 4 - Beta"
2525
dependencies = [
26-
"protobuf>=3.20.2,<6.0.0dev,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
27-
"googleapis-common-protos >= 1.56.2, < 2.0dev",
26+
"protobuf>=3.20.2,<7.0.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
27+
"googleapis-common-protos >= 1.56.2, < 2.0.0",
2828
]
2929

3030
package_root = os.path.abspath(os.path.dirname(__file__))

packages/googleapis-common-protos/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ classifiers = [
4141
"Topic :: Internet",
4242
]
4343
dependencies = [
44-
"protobuf >= 3.20.2, < 6.0.0.dev0, != 4.21.1, != 4.21.2, != 4.21.3, != 4.21.4, != 4.21.5",
44+
"protobuf >= 3.20.2, < 7.0.0, != 4.21.1, != 4.21.2, != 4.21.3, != 4.21.4, != 4.21.5",
4545
]
4646

4747
[project.urls]
4848
Repository = "https://github.com/googleapis/google-cloud-python/tree/main/packages/googleapis-common-protos"
4949

5050
[project.optional-dependencies]
51-
grpc = ["grpcio >= 1.44.0, < 2.0.0.dev0"]
51+
grpc = ["grpcio >= 1.44.0, < 2.0.0"]
5252

5353
[tool.setuptools.packages.find]
5454
exclude = ["tests*", "testing*", "docs*"]

packages/grpc-google-iam-v1/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ classifiers = [
4141
"Topic :: Internet",
4242
]
4343
dependencies = [
44-
"grpcio >= 1.44.0, < 2.0.0dev",
44+
"grpcio >= 1.44.0, < 2.0.0",
4545
"googleapis-common-protos[grpc] >= 1.56.0, < 2.0.0dev",
46-
"protobuf >= 3.20.2, < 6.0.0dev, != 4.21.1, != 4.21.2, != 4.21.3, != 4.21.4, != 4.21.5",
46+
"protobuf >= 3.20.2, < 7.0.0, != 4.21.1, != 4.21.2, != 4.21.3, != 4.21.4, != 4.21.5",
4747
]
4848

4949
[project.urls]

0 commit comments

Comments
 (0)