diff --git a/src/python/grpcio_tests/tests/bazel_namespace_package_hack.py b/src/python/grpcio_tests/tests/bazel_namespace_package_hack.py index 006a3deecb4..994a8e1e800 100644 --- a/src/python/grpcio_tests/tests/bazel_namespace_package_hack.py +++ b/src/python/grpcio_tests/tests/bazel_namespace_package_hack.py @@ -16,6 +16,8 @@ import os import site import sys +_GRPC_BAZEL_RUNTIME_ENV = "GRPC_BAZEL_RUNTIME" + # TODO(https://github.com/bazelbuild/bazel/issues/6844) Bazel failed to # interpret namespace packages correctly. This monkey patch will force the @@ -24,6 +26,9 @@ import sys # Analysis in depth: https://github.com/bazelbuild/rules_python/issues/55 def sys_path_to_site_dir_hack(): """Add valid sys.path item to site directory to parse the .pth files.""" + # Only run within our Bazel environment + if not os.environ.get(_GRPC_BAZEL_RUNTIME_ENV): + return items = [] for item in sys.path: if os.path.exists(item): diff --git a/tools/bazel.rc b/tools/bazel.rc index 4bd3a5d7445..7a716e85088 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -5,6 +5,7 @@ build --client_env=CC=clang build --copt=-DGRPC_BAZEL_BUILD +build --action_env=GRPC_BAZEL_RUNTIME=1 build:opt --compilation_mode=opt build:opt --copt=-Wframe-larger-than=16384