Module: Mesa
Branch: staging/23.1
Commit: 5a6ce53dd8a1ba9b2b07d5e5679ac90f60cd8d96
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=5a6ce53dd8a1ba9b2b07d5e5679ac90f60cd8d96

Author: Eric Engestrom <[email protected]>
Date:   Wed May  3 17:52:57 2023 +0100

bin: add wrapper to run scripts in a python venv

This isolates the script environment from the rest of the machine,
avoiding missing/incompatible dependencies and avoiding polluting the
rest of the machine with python packages.

Signed-off-by: Eric Engestrom <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24367>
(cherry picked from commit 75f44bd79a01b8bec4b7cbb561bbb10cadc3db8c)

---

 .pick_status.json  |  2 +-
 bin/python-venv.sh | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/.pick_status.json b/.pick_status.json
index 139846080e6..aff6bc0ca1e 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -67,7 +67,7 @@
         "description": "bin: add wrapper to run scripts in a python venv",
         "nominated": false,
         "nomination_type": null,
-        "resolution": 4,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/bin/python-venv.sh b/bin/python-venv.sh
new file mode 100755
index 00000000000..2c4f6dccdbe
--- /dev/null
+++ b/bin/python-venv.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+set -eu
+
+readonly requirements_file=$1
+shift
+
+venv_dir="$(dirname "$requirements_file")"/.venv
+readonly venv_dir
+readonly venv_req=$venv_dir/requirements.txt
+
+if ! [ -r "$venv_dir/bin/activate" ]
+then
+  echo "Creating Python environment..."
+  python -m venv "$venv_dir"
+fi
+
+# shellcheck disable=1091
+source "$venv_dir/bin/activate"
+
+if ! cmp --quiet "$requirements_file" "$venv_req"
+then
+  echo "$(realpath --relative-to="$PWD" "$requirements_file") has changed, 
re-installing..."
+  pip --disable-pip-version-check install --requirement "$requirements_file"
+  cp "$requirements_file" "$venv_req"
+fi
+
+python "$@"

Reply via email to