bin/python-venv: detect python version change

The venv only works for a specific python version; when updating python,
the venv needs to be regenerated.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26354>
This commit is contained in:
Eric Engestrom 2023-11-24 16:43:30 +00:00 committed by Marge Bot
parent 01d15d8a38
commit 69ec13b303

View File

@ -7,11 +7,28 @@ shift
venv_dir="$(dirname "$requirements_file")"/.venv
readonly venv_dir
readonly venv_req=$venv_dir/requirements.txt
readonly venv_python_version=$venv_dir/python-version.txt
if [ -d "$venv_dir" ] && [ ! -r "$venv_python_version" ]
then
echo "Python environment predates Python version checks."
echo "It might be invalid and needs to be regenerated."
rm -rf "$venv_dir"
elif ! cmp --quiet <(python --version) "$venv_python_version"
then
old=$(cat "$venv_python_version")
new=$(python --version)
echo "Python version has changed ($old -> $new)."
echo "Python environment needs to be regenerated."
unset old new
rm -rf "$venv_dir"
fi
if ! [ -r "$venv_dir/bin/activate" ]
then
echo "Creating Python environment..."
python -m venv "$venv_dir"
python --version > "$venv_python_version"
fi
# shellcheck disable=1091