From 0bd13ed8d0ee0f5600b0b8d05907e86d24a7ab1b Mon Sep 17 00:00:00 2001
From: Masood Malekghassemi <atash@google.com>
Date: Mon, 13 Jun 2016 19:22:43 -0700
Subject: [PATCH] Fall back to default python for test virtualenvs

---
 tools/run_tests/build_python.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/run_tests/build_python.sh b/tools/run_tests/build_python.sh
index 9d2813fa19..1ad928f2da 100755
--- a/tools/run_tests/build_python.sh
+++ b/tools/run_tests/build_python.sh
@@ -33,6 +33,7 @@ set -ex
 # change to grpc repo root
 cd $(dirname $0)/../..
 
+# Arguments
 PYTHON=${1:-python2.7}
 VENV=${2:-py27}
 VENV_RELATIVE_PYTHON=${3:-bin/python}
@@ -42,6 +43,10 @@ ROOT=`pwd`
 export CFLAGS="-I$ROOT/include -std=gnu99 -fno-wrapv"
 export GRPC_PYTHON_BUILD_WITH_CYTHON=1
 
+# Default python on the host to fall back to when instantiating e.g. the
+# virtualenv.
+HOST_PYTHON=${HOST_PYTHON:-python}
+
 # If ccache is available, use it... unless we're on Mac, then all hell breaks
 # loose because Python does hacky things to support other hacky things done to
 # hacky things on Mac OS X
@@ -71,7 +76,14 @@ if [ "$CONFIG" = "gcov" ]; then
   export GRPC_PYTHON_ENABLE_CYTHON_TRACING=1
 fi
 
-($PYTHON -m virtualenv $VENV || true)
+# Instnatiate the virtualenv, preferring to do so from the relevant python
+# version. Even if these commands fail (e.g. on Windows due to name conflicts)
+# it's possible that the virtualenv is still usable and we trust the tester to
+# be able to 'figure it out' instead of us e.g. doing potentially expensive and
+# unnecessary error recovery by `rm -rf`ing the virtualenv.
+($PYTHON -m virtualenv $VENV ||
+ $HOST_PYTHON -m virtualenv -p $PYTHON $VENV ||
+ true)
 VENV_PYTHON=`$REALPATH -s "$VENV/$VENV_RELATIVE_PYTHON"`
 
 # pip-installs the directory specified. Used because on MSYS the vanilla Windows
-- 
GitLab