Revert "Merge pull request #17644 from lidizheng/bzl-py3"
This reverts commit a25828ad784e4302699c00751ebe1191462caee8, reversing
changes made to 5176fd80fc160c492cb6529569bde5f36e1ecf44.
diff --git a/BUILD b/BUILD
index ff066ed..3f1e735 100644
--- a/BUILD
+++ b/BUILD
@@ -63,11 +63,6 @@
values = {"cpu": "x64_windows_msvc"},
)
-config_setting(
- name = "python3",
- values = {"python_path": "python3"},
-)
-
# This should be updated along with build.yaml
g_stands_for = "gold"
diff --git a/src/python/grpcio/grpc/BUILD.bazel b/src/python/grpcio/grpc/BUILD.bazel
index 27d5d2e..6958ccd 100644
--- a/src/python/grpcio/grpc/BUILD.bazel
+++ b/src/python/grpcio/grpc/BUILD.bazel
@@ -15,11 +15,9 @@
"//src/python/grpcio/grpc/_cython:cygrpc",
"//src/python/grpcio/grpc/experimental",
"//src/python/grpcio/grpc/framework",
+ requirement('enum34'),
requirement('six'),
- ] + select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ ],
data = [
"//:grpc",
],
diff --git a/src/python/grpcio/grpc/framework/common/BUILD.bazel b/src/python/grpcio/grpc/framework/common/BUILD.bazel
index 52fbb2b..9d9ef68 100644
--- a/src/python/grpcio/grpc/framework/common/BUILD.bazel
+++ b/src/python/grpcio/grpc/framework/common/BUILD.bazel
@@ -13,17 +13,15 @@
py_library(
name = "cardinality",
srcs = ["cardinality.py"],
- deps = select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ deps = [
+ requirement("enum34"),
+ ],
)
py_library(
name = "style",
srcs = ["style.py"],
- deps = select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ deps = [
+ requirement("enum34"),
+ ],
)
diff --git a/src/python/grpcio/grpc/framework/foundation/BUILD.bazel b/src/python/grpcio/grpc/framework/foundation/BUILD.bazel
index a447ecd..1287fdd 100644
--- a/src/python/grpcio/grpc/framework/foundation/BUILD.bazel
+++ b/src/python/grpcio/grpc/framework/foundation/BUILD.bazel
@@ -23,11 +23,9 @@
name = "callable_util",
srcs = ["callable_util.py"],
deps = [
+ requirement("enum34"),
requirement("six"),
- ] + select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ ],
)
py_library(
@@ -41,10 +39,9 @@
py_library(
name = "logging_pool",
srcs = ["logging_pool.py"],
- deps = select({
- "//conditions:default": [requirement('futures'),],
- "//:python3": [],
- }),
+ deps = [
+ requirement("futures"),
+ ],
)
py_library(
diff --git a/src/python/grpcio/grpc/framework/interfaces/base/BUILD.bazel b/src/python/grpcio/grpc/framework/interfaces/base/BUILD.bazel
index 35cfe87..408a66a 100644
--- a/src/python/grpcio/grpc/framework/interfaces/base/BUILD.bazel
+++ b/src/python/grpcio/grpc/framework/interfaces/base/BUILD.bazel
@@ -15,18 +15,15 @@
srcs = ["base.py"],
deps = [
"//src/python/grpcio/grpc/framework/foundation:abandonment",
+ requirement("enum34"),
requirement("six"),
- ] + select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ ],
)
py_library(
name = "utilities",
srcs = ["utilities.py"],
- deps = select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ deps = [
+ requirement("enum34"),
+ ],
)
diff --git a/src/python/grpcio/grpc/framework/interfaces/face/BUILD.bazel b/src/python/grpcio/grpc/framework/interfaces/face/BUILD.bazel
index 83fadb6..e683e7c 100644
--- a/src/python/grpcio/grpc/framework/interfaces/face/BUILD.bazel
+++ b/src/python/grpcio/grpc/framework/interfaces/face/BUILD.bazel
@@ -16,11 +16,9 @@
deps = [
"//src/python/grpcio/grpc/framework/foundation",
"//src/python/grpcio/grpc/framework/common",
+ requirement("enum34"),
requirement("six"),
- ] + select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ ],
)
py_library(
diff --git a/src/python/grpcio_status/grpc_status/rpc_status.py b/src/python/grpcio_status/grpc_status/rpc_status.py
index 76891e2..87618fa 100644
--- a/src/python/grpcio_status/grpc_status/rpc_status.py
+++ b/src/python/grpcio_status/grpc_status/rpc_status.py
@@ -17,6 +17,11 @@
import grpc
+# TODO(https://github.com/bazelbuild/bazel/issues/6844)
+# Due to Bazel issue, the namespace packages won't resolve correctly.
+# Adding this unused-import as a workaround to avoid module-not-found error
+# under Bazel builds.
+import google.protobuf # pylint: disable=unused-import
from google.rpc import status_pb2
_CODE_TO_GRPC_CODE_MAPPING = {x.value[0]: x for x in grpc.StatusCode}
diff --git a/src/python/grpcio_tests/tests/BUILD.bazel b/src/python/grpcio_tests/tests/BUILD.bazel
deleted file mode 100644
index b908ab8..0000000
--- a/src/python/grpcio_tests/tests/BUILD.bazel
+++ /dev/null
@@ -1,8 +0,0 @@
-py_library(
- name = "bazel_namespace_package_hack",
- srcs = ["bazel_namespace_package_hack.py"],
- visibility = [
- "//src/python/grpcio_tests/tests/status:__subpackages__",
- "//src/python/grpcio_tests/tests/interop:__subpackages__",
- ],
-)
diff --git a/src/python/grpcio_tests/tests/bazel_namespace_package_hack.py b/src/python/grpcio_tests/tests/bazel_namespace_package_hack.py
deleted file mode 100644
index c6b72c3..0000000
--- a/src/python/grpcio_tests/tests/bazel_namespace_package_hack.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright 2019 The gRPC Authors
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import os
-import site
-import sys
-
-
-# TODO(https://github.com/bazelbuild/bazel/issues/6844) Bazel failed to
-# interpret namespace packages correctly. This monkey patch will force the
-# Python process to parse the .pth file in the sys.path to resolve namespace
-# package in the right place.
-# 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."""
- for item in sys.path:
- if os.path.exists(item):
- # The only difference between sys.path and site-directory is
- # whether the .pth file will be parsed or not. A site-directory
- # will always exist in sys.path, but not another way around.
- site.addsitedir(item)
diff --git a/src/python/grpcio_tests/tests/interop/BUILD.bazel b/src/python/grpcio_tests/tests/interop/BUILD.bazel
index 770b1f7..aebdbf6 100644
--- a/src/python/grpcio_tests/tests/interop/BUILD.bazel
+++ b/src/python/grpcio_tests/tests/interop/BUILD.bazel
@@ -29,20 +29,17 @@
srcs = ["methods.py"],
deps = [
"//src/python/grpcio/grpc:grpcio",
- "//src/python/grpcio_tests/tests:bazel_namespace_package_hack",
"//src/proto/grpc/testing:py_empty_proto",
"//src/proto/grpc/testing:py_messages_proto",
"//src/proto/grpc/testing:py_test_proto",
requirement('google-auth'),
requirement('requests'),
+ requirement('enum34'),
requirement('urllib3'),
requirement('chardet'),
requirement('certifi'),
requirement('idna'),
- ] + select({
- "//conditions:default": [requirement('enum34'),],
- "//:python3": [],
- }),
+ ],
imports=["../../",],
)
diff --git a/src/python/grpcio_tests/tests/interop/methods.py b/src/python/grpcio_tests/tests/interop/methods.py
index e16966e..c11f6c8 100644
--- a/src/python/grpcio_tests/tests/interop/methods.py
+++ b/src/python/grpcio_tests/tests/interop/methods.py
@@ -13,9 +13,6 @@
# limitations under the License.
"""Implementations of interoperability test methods."""
-from tests import bazel_namespace_package_hack
-bazel_namespace_package_hack.sys_path_to_site_dir_hack()
-
import enum
import json
import os
diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py
index 37a66ad..560f6d3 100644
--- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py
+++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py
@@ -50,16 +50,6 @@
class ReflectionServicerTest(unittest.TestCase):
- # TODO(https://github.com/grpc/grpc/issues/17844)
- # Bazel + Python 3 will result in creating two different instance of
- # DESCRIPTOR for each message. So, the equal comparison between protobuf
- # returned by stub and manually crafted protobuf will always fail.
- def _assert_sequence_of_proto_equal(self, x, y):
- self.assertSequenceEqual(
- list(map(lambda x: x.SerializeToString(), x)),
- list(map(lambda x: x.SerializeToString(), y)),
- )
-
def setUp(self):
self._server = test_common.test_server()
reflection.enable_server_reflection(_SERVICE_NAMES, self._server)
@@ -94,7 +84,7 @@
error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(),
)),
)
- self._assert_sequence_of_proto_equal(expected_responses, responses)
+ self.assertSequenceEqual(expected_responses, responses)
def testFileBySymbol(self):
requests = (
@@ -118,7 +108,7 @@
error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(),
)),
)
- self._assert_sequence_of_proto_equal(expected_responses, responses)
+ self.assertSequenceEqual(expected_responses, responses)
def testFileContainingExtension(self):
requests = (
@@ -147,7 +137,7 @@
error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(),
)),
)
- self._assert_sequence_of_proto_equal(expected_responses, responses)
+ self.assertSequenceEqual(expected_responses, responses)
def testExtensionNumbersOfType(self):
requests = (
@@ -172,7 +162,7 @@
error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(),
)),
)
- self._assert_sequence_of_proto_equal(expected_responses, responses)
+ self.assertSequenceEqual(expected_responses, responses)
def testListServices(self):
requests = (reflection_pb2.ServerReflectionRequest(list_services='',),)
@@ -183,7 +173,7 @@
service=tuple(
reflection_pb2.ServiceResponse(name=name)
for name in _SERVICE_NAMES))),)
- self._assert_sequence_of_proto_equal(expected_responses, responses)
+ self.assertSequenceEqual(expected_responses, responses)
def testReflectionServiceName(self):
self.assertEqual(reflection.SERVICE_NAME,
diff --git a/src/python/grpcio_tests/tests/status/BUILD.bazel b/src/python/grpcio_tests/tests/status/BUILD.bazel
index b163fe3..937e504 100644
--- a/src/python/grpcio_tests/tests/status/BUILD.bazel
+++ b/src/python/grpcio_tests/tests/status/BUILD.bazel
@@ -10,7 +10,6 @@
deps = [
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_status/grpc_status:grpc_status",
- "//src/python/grpcio_tests/tests:bazel_namespace_package_hack",
"//src/python/grpcio_tests/tests/unit:test_common",
"//src/python/grpcio_tests/tests/unit/framework/common:common",
requirement('protobuf'),
diff --git a/src/python/grpcio_tests/tests/status/_grpc_status_test.py b/src/python/grpcio_tests/tests/status/_grpc_status_test.py
index 77f5fb2..519c372 100644
--- a/src/python/grpcio_tests/tests/status/_grpc_status_test.py
+++ b/src/python/grpcio_tests/tests/status/_grpc_status_test.py
@@ -13,9 +13,6 @@
# limitations under the License.
"""Tests of grpc_status."""
-from tests import bazel_namespace_package_hack
-bazel_namespace_package_hack.sys_path_to_site_dir_hack()
-
import unittest
import logging
diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl
index 9036a95..2ba1e07 100644
--- a/third_party/py/python_configure.bzl
+++ b/third_party/py/python_configure.bzl
@@ -138,13 +138,10 @@
def _get_python_bin(repository_ctx):
"""Gets the python bin path."""
- python_bin = repository_ctx.os.environ.get(_PYTHON_BIN_PATH, 'python')
- if not '/' in python_bin and not '\\' in python_bin:
- # It's a command, use 'which' to find its path.
- python_bin_path = repository_ctx.which(python_bin)
- else:
- # It's a path, use it as it is.
- python_bin_path = python_bin
+ python_bin = repository_ctx.os.environ.get(_PYTHON_BIN_PATH)
+ if python_bin != None:
+ return python_bin
+ python_bin_path = repository_ctx.which("python")
if python_bin_path != None:
return str(python_bin_path)
_fail("Cannot find python in PATH, please make sure " +
diff --git a/tools/bazel.rc b/tools/bazel.rc
index 9934749..59e597b 100644
--- a/tools/bazel.rc
+++ b/tools/bazel.rc
@@ -57,7 +57,3 @@
build:basicprof --copt=-O2
build:basicprof --copt=-DGRPC_BASIC_PROFILER
build:basicprof --copt=-DGRPC_TIMERS_RDTSC
-
-build:python3 --python_path=python3
-build:python3 --force_python=PY3
-build:python3 --action_env=PYTHON_BIN_PATH=python3
diff --git a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh
index 1498964..156d659 100755
--- a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh
+++ b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh
@@ -25,5 +25,3 @@
${name}')
cd /var/local/git/grpc/test
bazel test --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //src/python/...
-bazel clean --expunge
-bazel test --config=python3 --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //src/python/...