From 46a050cbfb767b4ea0756559746932eeae010be8 Mon Sep 17 00:00:00 2001 From: akaranjkar-qu <41927856+akaranjkar-qu@users.noreply.github.com> Date: Tue, 9 Jun 2020 18:21:58 -0700 Subject: [PATCH] fix bug in install_python_venv (#36) --- misc/python_venv.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/misc/python_venv.sh b/misc/python_venv.sh index 56b30e3..bbef184 100644 --- a/misc/python_venv.sh +++ b/misc/python_venv.sh @@ -19,11 +19,23 @@ # # @arg $1 float Version of Python to use. Defaults to 3.6 # @arg $2 string Location to create virtualenv in. Defaults to /usr/lib/virtualenv/py36 +# +# @exitcode 0 Python virtualenv was created and activated +# @exitcode 1 Python executable for virtualenv couldn't be found or installed function install_python_venv() { - version=${$1:-36} - location=${$2:-/usr/lib/virtualenv/py36} + version=${1:-36} + location=${2:-/usr/lib/virtualenv/py36} + + if [[ ! -x /usr/bin/python${version} ]]; then + echo "No executable /usr/bin/python${version} found. Attempting to install.." + yum_python_package=${version//.} + yum install -y "python${yum_python_package}" + if [[ $? -ne 0 ]]; then + echo "Failed to install python${version}.." + return 1 + fi + fi - yum install -y "python${version}" mkdir -p $location virtualenv -p "/usr/bin/python${version}" $location