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

View File

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