Skip to content

Commit 958ddd4

Browse files
committed
1 parent 346097d commit 958ddd4

File tree

1 file changed

+59
-33
lines changed
  • packages/google-cloud-access-context-manager

1 file changed

+59
-33
lines changed

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

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727

2828
import nox
2929

30+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303):
31+
# Remove try/except once Python 3.7 is dropped
32+
try:
33+
import importlib
34+
import importlib.metadata
35+
except ImportError:
36+
pass
37+
3038
BLACK_VERSION = "black[jupyter]==23.7.0"
3139
ISORT_VERSION = "isort==5.11.0"
3240

@@ -385,7 +393,7 @@ def prerelease_deps(session, protobuf_implementation):
385393
"""
386394
Run all tests with pre-release versions of dependencies installed
387395
rather than the standard non pre-release versions.
388-
Pre-releases versions can be installed using
396+
Pre-release versions can be installed using
389397
`pip install --pre <package>`.
390398
"""
391399

@@ -395,16 +403,16 @@ def prerelease_deps(session, protobuf_implementation):
395403
# Install all dependencies
396404
session.install("-e", ".")
397405

398-
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
399406
# Install dependencies for the unit test environment
407+
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
400408
session.install(*unit_deps_all)
401409

410+
# Install dependencies for the system test environment
402411
system_deps_all = (
403412
SYSTEM_TEST_STANDARD_DEPENDENCIES
404413
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
405414
+ SYSTEM_TEST_EXTRAS
406415
)
407-
# Install dependencies for the system test environment
408416
session.install(*system_deps_all)
409417

410418
# Because we test minimum dependency versions on the minimum Python
@@ -429,37 +437,48 @@ def prerelease_deps(session, protobuf_implementation):
429437
# Install dependencies specified in `testing/constraints-X.txt`.
430438
session.install(*constraints_deps)
431439

440+
# Note: If a dependency is added to the `prerel_deps` list,
441+
# the `core_dependencies_from_source` list in the `core_deps_from_source`
442+
# nox session should also be updated.
432443
prerel_deps = [
433-
"protobuf",
434-
# dependency of grpc
435-
"six",
436-
"grpc-google-iam-v1",
437444
"googleapis-common-protos",
438-
"grpcio",
439-
"grpcio-status",
440445
"google-api-core",
441446
"google-auth",
447+
"grpc-google-iam-v1",
448+
"grpcio",
449+
"grpcio-status",
450+
"protobuf",
442451
"proto-plus",
443-
"google-cloud-testutils",
444-
# dependencies of google-cloud-testutils"
445-
"click",
446452
]
447453

448454
for dep in prerel_deps:
449-
session.install("--pre", "--no-deps", "--upgrade", dep)
450-
451-
# Remaining dependencies
452-
other_deps = [
453-
"requests",
454-
]
455-
session.install(*other_deps)
456-
457-
# Print out prerelease package versions
458-
session.run(
459-
"python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
460-
)
461-
session.run("python", "-c", "import grpc; print(grpc.__version__)")
462-
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")
455+
session.install("--pre", "--no-deps", "--ignore-installed", dep)
456+
# TODO(https://github.com/grpc/grpc/issues/38965): Add grpcio-status
457+
# to the statement below once this bug is fixed.
458+
# TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add
459+
# `googleapis-common-protos` and `grpc-google-iam-v1` to the statement below
460+
# once this bug is fixed.
461+
match (dep):
462+
case "google-api-core":
463+
version_namespace = "google.api_core"
464+
case "google-auth":
465+
version_namespace = "google.auth"
466+
case "grpcio":
467+
version_namespace = "grpc"
468+
case "protobuf":
469+
version_namespace = "google.protobuf"
470+
case "proto-plus":
471+
version_namespace = "proto"
472+
case _:
473+
version_namespace = None
474+
475+
print(f"Installed {dep}")
476+
if version_namespace:
477+
session.run(
478+
"python",
479+
"-c",
480+
f"import {version_namespace}; print({version_namespace}.__version__)",
481+
)
463482

464483
session.run(
465484
"py.test",
@@ -476,12 +495,12 @@ def prerelease_deps(session, protobuf_implementation):
476495
["python", "upb"],
477496
)
478497
def core_deps_from_source(session, protobuf_implementation):
479-
"""Run all tests with local versions of core dependencies installed,
480-
rather than pulling core dependencies from PyPI.
498+
"""Run all tests with core dependencies installed from source
499+
rather than pulling the dependencies from PyPI.
481500
"""
482501

483502
# Install all dependencies
484-
session.install(".")
503+
session.install("-e", ".")
485504

486505
# Install dependencies for the unit test environment
487506
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
@@ -497,7 +516,7 @@ def core_deps_from_source(session, protobuf_implementation):
497516

498517
# Because we test minimum dependency versions on the minimum Python
499518
# version, the first version we test with in the unit tests sessions has a
500-
# constraints file containing all dependencies and extras that should be installed.
519+
# constraints file containing all dependencies and extras.
501520
with open(
502521
CURRENT_DIRECTORY
503522
/ "testing"
@@ -517,16 +536,23 @@ def core_deps_from_source(session, protobuf_implementation):
517536
# Install dependencies specified in `testing/constraints-X.txt`.
518537
session.install(*constraints_deps)
519538

539+
# TODO(hhttps://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and
540+
# `grpcio-status` should be added to the list below so that it is installed from source, rather than PyPI
541+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be
542+
# added to the list below so that it is installed from source, rather than PyPI
543+
# Note: If a dependency is added to the `core_dependencies_from_source` list,
544+
# the `prerel_deps` list in the `prerelease_deps` nox session should also be updated.
520545
core_dependencies_from_source = [
546+
"proto-plus @ git+https://github.com/googleapis/proto-plus-python.git",
547+
f"{CURRENT_DIRECTORY}/../googleapis-common-protos",
521548
"google-api-core @ git+https://github.com/googleapis/python-api-core.git",
522549
"google-auth @ git+https://github.com/googleapis/google-auth-library-python.git",
523-
f"{CURRENT_DIRECTORY}/../googleapis-common-protos",
524550
f"{CURRENT_DIRECTORY}/../grpc-google-iam-v1",
525-
"proto-plus @ git+https://github.com/googleapis/proto-plus-python.git",
526551
]
527552

528553
for dep in core_dependencies_from_source:
529-
session.install(dep, "--ignore-installed", "--no-deps")
554+
session.install(dep, "--no-deps", "--ignore-installed")
555+
print(f"Installed {dep}")
530556

531557
session.run(
532558
"py.test",

0 commit comments

Comments
 (0)