Skip to content

Commit 7ffc8bd

Browse files
committed
chore(python_mono_repo): clean up prerelease_deps and core_deps_from_source
1 parent 0a20722 commit 7ffc8bd

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

synthtool/gcp/templates/python_mono_repo_library/noxfile.py.j2

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ import warnings
2626

2727
import nox
2828

29+
# TODO(https://github.com/googleapis/gapic-generator-python/issues/2303):
30+
# Remove try/except once Python 3.7 is dropped
31+
try:
32+
import importlib.metadata
33+
except ImportError:
34+
pass
35+
2936
BLACK_VERSION = "black[jupyter]==23.7.0"
3037
ISORT_VERSION = "isort==5.11.0"
3138
{% if 'google' in metadata['repo']['distribution_name'] %}
@@ -454,7 +461,7 @@ def prerelease_deps(session, protobuf_implementation):
454461
"""
455462
Run all tests with pre-release versions of dependencies installed
456463
rather than the standard non pre-release versions.
457-
Pre-releases versions can be installed using
464+
Pre-release versions can be installed using
458465
`pip install --pre <package>`.
459466
"""
460467

@@ -464,16 +471,16 @@ def prerelease_deps(session, protobuf_implementation):
464471
# Install all dependencies
465472
session.install("-e", ".")
466473

467-
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
468474
# Install dependencies for the unit test environment
475+
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
469476
session.install(*unit_deps_all)
470477

478+
# Install dependencies for the system test environment
471479
system_deps_all = (
472480
SYSTEM_TEST_STANDARD_DEPENDENCIES
473481
+ SYSTEM_TEST_EXTERNAL_DEPENDENCIES
474482
+ SYSTEM_TEST_EXTRAS
475483
)
476-
# Install dependencies for the system test environment
477484
session.install(*system_deps_all)
478485

479486
# Because we test minimum dependency versions on the minimum Python
@@ -498,37 +505,23 @@ def prerelease_deps(session, protobuf_implementation):
498505
# Install dependencies specified in `testing/constraints-X.txt`.
499506
session.install(*constraints_deps)
500507

508+
# Note: If a dependency is added to the `prerel_deps` list,
509+
# the `core_dependencies_from_source` list in the `core_deps_from_source`
510+
# nox session should also be updated.
501511
prerel_deps = [
502-
"protobuf",
503-
# dependency of grpc
504-
"six",
505-
"grpc-google-iam-v1",
506-
"googleapis-common-protos",
507512
"grpcio",
508513
"grpcio-status",
514+
"protobuf",
515+
"proto-plus",
516+
"googleapis-common-protos",
509517
"google-api-core",
510518
"google-auth",
511-
"proto-plus",
512-
"google-cloud-testutils",
513-
# dependencies of google-cloud-testutils"
514-
"click",
519+
"grpc-google-iam-v1",
515520
]
516521

517522
for dep in prerel_deps:
518-
session.install("--pre", "--no-deps", "--upgrade", dep)
519-
520-
# Remaining dependencies
521-
other_deps = [
522-
"requests",
523-
]
524-
session.install(*other_deps)
525-
526-
# Print out prerelease package versions
527-
session.run(
528-
"python", "-c", "import google.protobuf; print(google.protobuf.__version__)"
529-
)
530-
session.run("python", "-c", "import grpc; print(grpc.__version__)")
531-
session.run("python", "-c", "import google.auth; print(google.auth.__version__)")
523+
session.install("--pre", "--no-deps", "--ignore-installed", dep)
524+
print(f"Installed {dep}: version {importlib.metadata.version(dep)}")
532525

533526
session.run(
534527
"py.test",
@@ -545,12 +538,12 @@ def prerelease_deps(session, protobuf_implementation):
545538
["python", "upb"],
546539
)
547540
def core_deps_from_source(session, protobuf_implementation):
548-
"""Run all tests with local versions of core dependencies installed,
541+
"""Run all tests with core dependencies installed installed from source,
549542
rather than pulling core dependencies from PyPI.
550543
"""
551544

552545
# Install all dependencies
553-
session.install(".")
546+
session.install("-e", ".")
554547

555548
# Install dependencies for the unit test environment
556549
unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
@@ -566,7 +559,7 @@ def core_deps_from_source(session, protobuf_implementation):
566559

567560
# Because we test minimum dependency versions on the minimum Python
568561
# version, the first version we test with in the unit tests sessions has a
569-
# constraints file containing all dependencies and extras that should be installed.
562+
# constraints file containing all dependencies and extras.
570563
with open(
571564
CURRENT_DIRECTORY
572565
/ "testing"
@@ -586,17 +579,23 @@ def core_deps_from_source(session, protobuf_implementation):
586579
# Install dependencies specified in `testing/constraints-X.txt`.
587580
session.install(*constraints_deps)
588581

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

598596
for dep in core_dependencies_from_source:
599-
session.install(dep, "--ignore-installed", "--no-deps")
597+
session.install(dep, "--no-deps", "--ignore-installed")
598+
print(f"Installed {dep}")
600599

601600
session.run(
602601
"py.test",

0 commit comments

Comments
 (0)