From c6471a7f858da25a3d730a382e73757504055a31 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Wed, 7 Nov 2018 17:33:49 -0800 Subject: [PATCH] Only install virtualenv if not inside of virtualenv already --- tools/run_tests/helper_scripts/build_python.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tools/run_tests/helper_scripts/build_python.sh b/tools/run_tests/helper_scripts/build_python.sh index 4c94c4c6d22..8394f07e518 100755 --- a/tools/run_tests/helper_scripts/build_python.sh +++ b/tools/run_tests/helper_scripts/build_python.sh @@ -56,6 +56,12 @@ function is_linux() { fi } +function inside_venv() { + if [[ -n "${VIRTUAL_ENV}" ]]; then + echo true + fi +} + # Associated virtual environment name for the given python command. function venv() { $1 -c "import sys; print('py{}{}'.format(*sys.version_info[:2]))" @@ -134,10 +140,14 @@ fi # Perform build operations # ############################ -# Instantiate the virtualenv from the Python version passed in. -$PYTHON -m pip install --user virtualenv -$PYTHON -m virtualenv "$VENV" -VENV_PYTHON=$(script_realpath "$VENV/$VENV_RELATIVE_PYTHON") +if [[ "$(inside_venv)" ]]; then + VENV_PYTHON="$PYTHON" +else + # Instantiate the virtualenv from the Python version passed in. + $PYTHON -m pip install --user virtualenv + $PYTHON -m virtualenv "$VENV" + VENV_PYTHON=$(script_realpath "$VENV/$VENV_RELATIVE_PYTHON") +fi # See https://github.com/grpc/grpc/issues/14815 for more context. We cannot rely # on pip to upgrade itself because if pip is too old, it may not have the required