Skip to content

Commit 56340ed

Browse files
committed
1 parent 346097d commit 56340ed

File tree

1 file changed

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

1 file changed

+58
-33
lines changed

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

Lines changed: 58 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,47 @@ 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 dictionary 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 dictionary below
460+
# once this bug is fixed.
461+
package_namespaces = {
462+
"google-api-core": "google.api_core",
463+
"google-auth": "google.auth",
464+
"grpcio": "grpc",
465+
"protobuf": "google.protobuf",
466+
"proto-plus": "proto",
467+
}
468+
469+
try:
470+
version_namespace = package_namespaces[dep]
471+
except KeyError:
472+
version_namespace = None
473+
474+
print(f"Installed {dep}")
475+
if version_namespace:
476+
session.run(
477+
"python",
478+
"-c",
479+
f"import {version_namespace}; print({version_namespace}.__version__)",
480+
)
463481

464482
session.run(
465483
"py.test",
@@ -476,12 +494,12 @@ def prerelease_deps(session, protobuf_implementation):
476494
["python", "upb"],
477495
)
478496
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.
497+
"""Run all tests with core dependencies installed from source
498+
rather than pulling the dependencies from PyPI.
481499
"""
482500

483501
# Install all dependencies
484-
session.install(".")
502+
session.install("-e", ".")
485503

486504
# Install dependencies for the unit test environment
487505
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
@@ -497,7 +515,7 @@ def core_deps_from_source(session, protobuf_implementation):
497515

498516
# Because we test minimum dependency versions on the minimum Python
499517
# 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.
518+
# constraints file containing all dependencies and extras.
501519
with open(
502520
CURRENT_DIRECTORY
503521
/ "testing"
@@ -517,16 +535,23 @@ def core_deps_from_source(session, protobuf_implementation):
517535
# Install dependencies specified in `testing/constraints-X.txt`.
518536
session.install(*constraints_deps)
519537

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

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

531556
session.run(
532557
"py.test",

0 commit comments

Comments
 (0)