From ddb837a810229a9b96080ed60e4b436192e94b69 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble <gcmn@google.com> Date: Tue, 20 Oct 2020 01:00:50 -0700 Subject: [PATCH] Look for python3 before python on PATH TF no longer supports python2. This ensures that python3 will be picked up if available under the common "python3" name in the PATH. PiperOrigin-RevId: 338014609 Change-Id: Iaf0ee14e3ebbbcd72cf4ef15050bdc4b5968c525 --- third_party/remote_config/common.bzl | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/third_party/remote_config/common.bzl b/third_party/remote_config/common.bzl index 2d627e26cb8..d7e69326205 100644 --- a/third_party/remote_config/common.bzl +++ b/third_party/remote_config/common.bzl @@ -41,15 +41,24 @@ def get_python_bin(repository_ctx): python_bin = get_host_environ(repository_ctx, PYTHON_BIN_PATH) if python_bin != None: return python_bin - python_bin_path = which(repository_ctx, "python") - if python_bin_path == None: - auto_config_fail("Cannot find python in PATH, please make sure " + - "python is installed and add its directory in PATH, or --define " + - "%s='/something/else'.\nPATH=%s" % ( - PYTHON_BIN_PATH, - get_environ("PATH", ""), - )) - return python_bin_path + + # First check for an explicit "python3" + python_bin = which(repository_ctx, "python3") + if python_bin != None: + return python_bin + + # Some systems just call pythone3 "python" + python_bin = which(repository_ctx, "python") + if python_bin != None: + return python_bin + + auto_config_fail("Cannot find python in PATH, please make sure " + + "python is installed and add its directory in PATH, or --define " + + "%s='/something/else'.\nPATH=%s" % ( + PYTHON_BIN_PATH, + get_environ("PATH", ""), + )) + return python_bin # unreachable def get_bash_bin(repository_ctx): """Gets the bash bin path.