Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Mar 11, 2025
1 parent 346097d commit 56340ed
Showing 1 changed file with 58 additions and 33 deletions.
91 changes: 58 additions & 33 deletions packages/google-cloud-access-context-manager/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

import nox

# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303):
# Remove try/except once Python 3.7 is dropped
try:
import importlib
import importlib.metadata
except ImportError:
pass

BLACK_VERSION = "black[jupyter]==23.7.0"
ISORT_VERSION = "isort==5.11.0"

Expand Down Expand Up @@ -385,7 +393,7 @@ def prerelease_deps(session, protobuf_implementation):
"""
Run all tests with pre-release versions of dependencies installed
rather than the standard non pre-release versions.
Pre-releases versions can be installed using
Pre-release versions can be installed using
`pip install --pre <package>`.
"""

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

unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
# Install dependencies for the unit test environment
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
session.install(*unit_deps_all)

# Install dependencies for the system test environment
system_deps_all = (
SYSTEM_TEST_STANDARD_DEPENDENCIES
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
+ SYSTEM_TEST_EXTRAS
)
# Install dependencies for the system test environment
session.install(*system_deps_all)

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

# Note: If a dependency is added to the `prerel_deps` list,
# the `core_dependencies_from_source` list in the `core_deps_from_source`
# nox session should also be updated.
prerel_deps = [
"protobuf",
# dependency of grpc
"six",
"grpc-google-iam-v1",
"googleapis-common-protos",
"grpcio",
"grpcio-status",
"google-api-core",
"google-auth",
"grpc-google-iam-v1",
"grpcio",
"grpcio-status",
"protobuf",
"proto-plus",
"google-cloud-testutils",
# dependencies of google-cloud-testutils"
"click",
]

for dep in prerel_deps:
session.install("--pre", "--no-deps", "--upgrade", dep)

# Remaining dependencies
other_deps = [
"requests",
]
session.install(*other_deps)

# Print out prerelease package versions
session.run(
"python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
)
session.run("python", "-c", "import grpc; print(grpc.__version__)")
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")
session.install("--pre", "--no-deps", "--ignore-installed", dep)
# TODO(https://github.com/grpc/grpc/issues/38965): Add `grpcio-status``
# to the dictionary below once this bug is fixed.
# TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add
# `googleapis-common-protos` and `grpc-google-iam-v1` to the dictionary below
# once this bug is fixed.
package_namespaces = {
"google-api-core": "google.api_core",
"google-auth": "google.auth",
"grpcio": "grpc",
"protobuf": "google.protobuf",
"proto-plus": "proto",
}

try:
version_namespace = package_namespaces[dep]
except KeyError:
version_namespace = None

print(f"Installed {dep}")
if version_namespace:
session.run(
"python",
"-c",
f"import {version_namespace}; print({version_namespace}.__version__)",
)

session.run(
"py.test",
Expand All @@ -476,12 +494,12 @@ def prerelease_deps(session, protobuf_implementation):
["python", "upb"],
)
def core_deps_from_source(session, protobuf_implementation):
"""Run all tests with local versions of core dependencies installed,
rather than pulling core dependencies from PyPI.
"""Run all tests with core dependencies installed from source
rather than pulling the dependencies from PyPI.
"""

# Install all dependencies
session.install(".")
session.install("-e", ".")

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

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

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

for dep in core_dependencies_from_source:
session.install(dep, "--ignore-installed", "--no-deps")
session.install(dep, "--no-deps", "--ignore-installed")
print(f"Installed {dep}")

session.run(
"py.test",
Expand Down

0 comments on commit 56340ed

Please sign in to comment.