Fix the default version of Python for '-p 3' option

When '-p 3' option is used, the setup_env script checks whether
there is 'python3' installed on the system. If it is, then python
3.8.10 is not installed by the script and whatever version that is
pointed to by the 'python3' command is used.

This is an issue as the setup_env script help message states that
python 3.8.10 is used for the '-p 3' option.

This patch fixes the issue by ensuring that PY_VERSION == "3.8.10"
when '-p 3' is utilized and by checking the exact version of the
installed python on the system.

Change-Id: Ic4e32ca84f4c7bf63ae0a1deb11c1b4cb44166d8
This commit is contained in:
Lukáš Piwowarski 2022-10-06 14:24:25 +02:00
parent df3ce16947
commit 23d9f5d7df
1 changed files with 8 additions and 5 deletions

View File

@ -44,6 +44,8 @@ while getopts c:p:t:qs:h FLAG; do
p)
if [ ${OPTARG} == '2' ]; then
PY_VERSION="2.7.8"
elif [ ${OPTARG} == '3' ]; then
PY_VERSION=${PY_VERSION}
else
PY_VERSION=${OPTARG}
fi
@ -168,8 +170,12 @@ fi
# Build local python interpreter if needed
sub_pystr="python$(echo $PY_VERSION | cut -c 1-3)"
if [ ! -n "$(command -v $sub_pystr)" ]; then
echo "$sub_pystr not found. Building python ${PY_VERSION}..."
python_version=$($sub_pystr -V | cut -d " " -f 2)
if [ $python_version == $PY_VERSION ]; then
echo "Python $PY_VERSION found!"
PYPATH="$sub_pystr"
else
echo "Python $PY_VERSION not found. Building python ${PY_VERSION}..."
mkdir ${WORKDIR}/.localpython
mkdir ${WORKDIR}/.python_src
cd ${WORKDIR}/.python_src
@ -182,9 +188,6 @@ if [ ! -n "$(command -v $sub_pystr)" ]; then
cd ${WORKDIR}
rm -rf ${WORKDIR}/.python_src
PYPATH="${WORKDIR}/.localpython/bin/$sub_pystr"
else
echo "$sub_pystr found!"
PYPATH="$sub_pystr"
fi
# Setup virtual environments for refstack-client and tempest