Skip to content

Commit f36b806

Browse files
committed
1 parent 346097d commit f36b806

File tree

1 file changed

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

1 file changed

+56
-33
lines changed

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

Lines changed: 56 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,45 @@ 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("python", "-c", f"import {version_namespace}; print({version_namespace}.__version__)")
478+
463479

464480
session.run(
465481
"py.test",
@@ -476,12 +492,12 @@ def prerelease_deps(session, protobuf_implementation):
476492
["python", "upb"],
477493
)
478494
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.
495+
"""Run all tests with core dependencies installed from source
496+
rather than pulling the dependencies from PyPI.
481497
"""
482498

483499
# Install all dependencies
484-
session.install(".")
500+
session.install("-e", ".")
485501

486502
# Install dependencies for the unit test environment
487503
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
@@ -497,7 +513,7 @@ def core_deps_from_source(session, protobuf_implementation):
497513

498514
# Because we test minimum dependency versions on the minimum Python
499515
# 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.
516+
# constraints file containing all dependencies and extras.
501517
with open(
502518
CURRENT_DIRECTORY
503519
/ "testing"
@@ -517,16 +533,23 @@ def core_deps_from_source(session, protobuf_implementation):
517533
# Install dependencies specified in `testing/constraints-X.txt`.
518534
session.install(*constraints_deps)
519535

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

528550
for dep in core_dependencies_from_source:
529-
session.install(dep, "--ignore-installed", "--no-deps")
551+
session.install(dep, "--no-deps", "--ignore-installed")
552+
print(f"Installed {dep}")
530553

531554
session.run(
532555
"py.test",

0 commit comments

Comments
 (0)