From 5b21bc5c93d7221e3d9dbf5e8b381a6800fdc7c2 Mon Sep 17 00:00:00 2001 From: Jiajun Yao Date: Thu, 9 Dec 2021 23:25:22 +0000 Subject: [PATCH] [BUILD] Use bazel-skylib rule to check bazel version (#20990) Bazel has a rule for enforcing the version so we can just reuse that. This redundant bazel version check logic in setup.py is also causing issue when building conda package, because conda has its own version of bazel and it doesn't support `--version`. --- WORKSPACE | 4 +++- python/setup.py | 14 ++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index f36f34371..c175d8e40 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -17,4 +17,6 @@ grpc_extra_deps() load("@bazel_skylib//lib:versions.bzl", "versions") -versions.check(minimum_bazel_version = "3.4.0") +# When the bazel version is updated, make sure to update it +# in setup.py as well. +versions.check(minimum_bazel_version = "4.2.1") diff --git a/python/setup.py b/python/setup.py index a26a7a97b..499a040f6 100644 --- a/python/setup.py +++ b/python/setup.py @@ -13,7 +13,6 @@ import tempfile import zipfile from itertools import chain -from itertools import takewhile from enum import Enum import urllib.error @@ -23,6 +22,8 @@ import urllib.request logger = logging.getLogger(__name__) SUPPORTED_PYTHONS = [(3, 6), (3, 7), (3, 8), (3, 9)] +# When the bazel version is updated, make sure to update it +# in WORKSPACE file as well. SUPPORTED_BAZEL = (4, 2, 1) ROOT_DIR = os.path.dirname(__file__) @@ -485,17 +486,6 @@ def build(build_python, build_java, build_cpp): ] + pip_packages, env=dict(os.environ, CC="gcc")) - version_info = bazel_invoke(subprocess.check_output, ["--version"]) - bazel_version_str = version_info.rstrip().decode("utf-8").split(" ", 1)[1] - bazel_version_split = bazel_version_str.split(".") - bazel_version_digits = [ - "".join(takewhile(str.isdigit, s)) for s in bazel_version_split - ] - bazel_version = tuple(map(int, bazel_version_digits)) - if bazel_version < SUPPORTED_BAZEL: - logger.warning("Expected Bazel version {} but found {}".format( - ".".join(map(str, SUPPORTED_BAZEL)), bazel_version_str)) - bazel_flags = ["--verbose_failures"] if BAZEL_LIMIT_CPUS: n = int(BAZEL_LIMIT_CPUS) # the value must be an int