Module: Mesa Branch: main Commit: 69ec13b303a8781148aaaee74fb6b05227ed783c URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=69ec13b303a8781148aaaee74fb6b05227ed783c
Author: Eric Engestrom <e...@igalia.com> Date: Fri Nov 24 16:43:30 2023 +0000 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> --- bin/python-venv.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bin/python-venv.sh b/bin/python-venv.sh index 2c4f6dccdbe..b6cf7fd9f5b 100755 --- a/bin/python-venv.sh +++ b/bin/python-venv.sh @@ -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