@@ -382,15 +382,24 @@ def docfx(session):
382382 ["python" , "upb" , "cpp" ],
383383)
384384def prerelease_deps (session , protobuf_implementation ):
385- """Run all tests with prerelease versions of dependencies installed."""
385+ """
386+ Run all tests with pre-release versions of dependencies installed
387+ rather than the standard non pre-release versions.
388+ Pre-release versions can be installed using
389+ `pip install --pre <package>`.
390+ """
386391
387392 if protobuf_implementation == "cpp" and session .python in ("3.11" , "3.12" , "3.13" ):
388393 session .skip ("cpp implementation is not supported in python 3.11+" )
389394
390395 # Install all dependencies
391- session .install ("-e" , ".[all, tests, tracing]" )
396+ session .install ("-e" , "." )
397+
398+ # Install dependencies for the unit test environment
392399 unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
393400 session .install (* unit_deps_all )
401+
402+ # Install dependencies for the system test environment
394403 system_deps_all = (
395404 SYSTEM_TEST_STANDARD_DEPENDENCIES
396405 + SYSTEM_TEST_EXTERNAL_DEPENDENCIES
@@ -417,39 +426,122 @@ def prerelease_deps(session, protobuf_implementation):
417426 )
418427 ]
419428
429+ # Install dependencies specified in `testing/constraints-X.txt`.
420430 session .install (* constraints_deps )
421431
432+ # Note: If a dependency is added to the `prerel_deps` list,
433+ # the `core_dependencies_from_source` list in the `core_deps_from_source`
434+ # nox session should also be updated.
422435 prerel_deps = [
423- "protobuf" ,
424- # dependency of grpc
425- "six" ,
426- "grpc-google-iam-v1" ,
427436 "googleapis-common-protos" ,
428- "grpcio" ,
429- "grpcio-status" ,
430437 "google-api-core" ,
431438 "google-auth" ,
439+ "grpc-google-iam-v1" ,
440+ "grpcio" ,
441+ "grpcio-status" ,
442+ "protobuf" ,
432443 "proto-plus" ,
433- "google-cloud-testutils" ,
434- # dependencies of google-cloud-testutils"
435- "click" ,
436444 ]
437445
438446 for dep in prerel_deps :
439- session .install ("--pre" , "--no-deps" , "--upgrade" , dep )
440-
441- # Remaining dependencies
442- other_deps = [
443- "requests" ,
444- ]
445- session .install (* other_deps )
447+ session .install ("--pre" , "--no-deps" , "--ignore-installed" , dep )
448+ # TODO(https://github.com/grpc/grpc/issues/38965): Add `grpcio-status``
449+ # to the dictionary below once this bug is fixed.
450+ # TODO(https://github.com/googleapis/google-cloud-python/issues/13643): Add
451+ # `googleapis-common-protos` and `grpc-google-iam-v1` to the dictionary below
452+ # once this bug is fixed.
453+ package_namespaces = {
454+ "google-api-core" : "google.api_core" ,
455+ "google-auth" : "google.auth" ,
456+ "grpcio" : "grpc" ,
457+ "protobuf" : "google.protobuf" ,
458+ "proto-plus" : "proto" ,
459+ }
460+
461+ version_namespace = package_namespaces .get (dep )
462+
463+ print (f"Installed { dep } " )
464+ if version_namespace :
465+ session .run (
466+ "python" ,
467+ "-c" ,
468+ f"import { version_namespace } ; print({ version_namespace } .__version__)" ,
469+ )
446470
447- # Print out prerelease package versions
448471 session .run (
449- "python" , "-c" , "import google.protobuf; print(google.protobuf.__version__)"
472+ "py.test" ,
473+ "tests/unit" ,
474+ env = {
475+ "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" : protobuf_implementation ,
476+ },
477+ )
478+
479+
480+ @nox .session (python = "3.13" )
481+ @nox .parametrize (
482+ "protobuf_implementation" ,
483+ ["python" , "upb" ],
484+ )
485+ def core_deps_from_source (session , protobuf_implementation ):
486+ """Run all tests with core dependencies installed from source
487+ rather than pulling the dependencies from PyPI.
488+ """
489+
490+ # Install all dependencies
491+ session .install ("-e" , "." )
492+
493+ # Install dependencies for the unit test environment
494+ unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
495+ session .install (* unit_deps_all )
496+
497+ # Install dependencies for the system test environment
498+ system_deps_all = (
499+ SYSTEM_TEST_STANDARD_DEPENDENCIES
500+ + SYSTEM_TEST_EXTERNAL_DEPENDENCIES
501+ + SYSTEM_TEST_EXTRAS
450502 )
451- session .run ("python" , "-c" , "import grpc; print(grpc.__version__)" )
452- session .run ("python" , "-c" , "import google.auth; print(google.auth.__version__)" )
503+ session .install (* system_deps_all )
504+
505+ # Because we test minimum dependency versions on the minimum Python
506+ # version, the first version we test with in the unit tests sessions has a
507+ # constraints file containing all dependencies and extras.
508+ with open (
509+ CURRENT_DIRECTORY
510+ / "testing"
511+ / f"constraints-{ UNIT_TEST_PYTHON_VERSIONS [0 ]} .txt" ,
512+ encoding = "utf-8" ,
513+ ) as constraints_file :
514+ constraints_text = constraints_file .read ()
515+
516+ # Ignore leading whitespace and comment lines.
517+ constraints_deps = [
518+ match .group (1 )
519+ for match in re .finditer (
520+ r"^\s*(\S+)(?===\S+)" , constraints_text , flags = re .MULTILINE
521+ )
522+ ]
523+
524+ # Install dependencies specified in `testing/constraints-X.txt`.
525+ session .install (* constraints_deps )
526+
527+ # TODO(https://github.com/googleapis/gapic-generator-python/issues/2358): `grpcio` and
528+ # `grpcio-status` should be added to the list below so that they are installed from source,
529+ # rather than PyPI.
530+ # TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be
531+ # added to the list below so that it is installed from source, rather than PyPI
532+ # Note: If a dependency is added to the `core_dependencies_from_source` list,
533+ # the `prerel_deps` list in the `prerelease_deps` nox session should also be updated.
534+ core_dependencies_from_source = [
535+ f"{ CURRENT_DIRECTORY } /../googleapis-common-protos" ,
536+ "google-api-core @ git+https://github.com/googleapis/python-api-core.git" ,
537+ "google-auth @ git+https://github.com/googleapis/google-auth-library-python.git" ,
538+ f"{ CURRENT_DIRECTORY } /../grpc-google-iam-v1" ,
539+ "proto-plus @ git+https://github.com/googleapis/proto-plus-python.git" ,
540+ ]
541+
542+ for dep in core_dependencies_from_source :
543+ session .install (dep , "--no-deps" , "--ignore-installed" )
544+ print (f"Installed { dep } " )
453545
454546 session .run (
455547 "py.test" ,
0 commit comments