summaryrefslogtreecommitdiffstats
path: root/test/common/pywrap
diff options
context:
space:
mode:
Diffstat (limited to 'test/common/pywrap')
-rwxr-xr-xtest/common/pywrap30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/common/pywrap b/test/common/pywrap
new file mode 100755
index 0000000..c5e78b3
--- /dev/null
+++ b/test/common/pywrap
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+# Run a Python script, setting up PYTHONPATH for access to test/common and the
+# python libraries in bots/. Checks out the bots first, if necessary.
+
+# This is intended to be used from the interpreter line of executable Python
+# scripts, referring to it with a relative path. The interpreter line should
+# look something like so:
+
+ #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../test/common/pywrap", sys.argv)
+
+# with the `/../test/common/` part determined by the location of the script
+# relative to this script.
+
+set -eu
+
+realpath="$(realpath "$0")"
+top_srcdir="${realpath%/*}/../.."
+
+# Check out the bots if required
+test -d "${top_srcdir}/bots" || "${top_srcdir}/test/common/make-bots"
+
+# Prepend the path
+PYTHONPATH="${top_srcdir}/test/common:${top_srcdir}/bots:${top_srcdir}/bots/machine${PYTHONPATH:+:${PYTHONPATH}}"
+export PYTHONPATH
+
+# Run the script
+# -B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x
+# -P : don't prepend a potentially unsafe path to sys.path -- but not available in RHEL 8/9 yet, use once we can
+exec python3 -B "$@"