]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Updating update-env.sh to use minimal Python version 3.5
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 12 Feb 2019 11:12:32 +0000 (12:12 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 12 Feb 2019 11:12:32 +0000 (12:12 +0100)
update-env.sh

index e952f3cf5221761c422ea29817ca94bf4caddf0c..7f3f6e39cb74bfe55a34a81d88ce416d88390099 100755 (executable)
@@ -1,9 +1,33 @@
 #!/bin/bash
 
-echo "Preparing virtual environment ..."
+base_dir=$( dirname $0 )
+cd ${base_dir}
+base_dir=$( readlink -f . )
+
+declare -a VALID_PY_VERSIONS=("3.8" "3.7" "3.6" "3.5")
+
+echo "Preparing virtual environment …"
 echo
 if [[ ! -f venv/bin/activate ]] ; then
-    virtualenv --python=python3 venv
+    found="n"
+    for py_version in "${VALID_PY_VERSIONS[@]}" ; do
+        PYTHON="python${py_version}"
+        if type -t ${PYTHON} >/dev/null ; then
+            found="y"
+            echo
+            echo "Found ${PYTHON}."
+            echo
+            virtualenv --python=${PYTHON} venv
+            break
+        fi
+    done
+    if [[ "${found}" == "n" ]] ; then
+        echo >&2
+        echo "Did not found a usable Python version." >&2
+        echo "Usable Python versions are: ${VALID_PY_VERSIONS[*]}" >&2
+        echo >&2
+        exit 5
+    fi
 fi
 
 . venv/bin/activate || exit 5