#!/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