test/common: add new 'pywrap' script

This is meant to be used as an alternate interpreter path which runs a
Python script in an environment with the bots checked out and the
PYTHONPATH correctly configured.

This provides an alternate mechanism to our `import parent` hacks, which
are now considered deprecated.
This commit is contained in:
Allison Karlitskaya 2023-05-26 10:40:46 +02:00
parent 89db1c68a9
commit d97ddebca2
1 changed files with 19 additions and 0 deletions

19
test/common/pywrap Executable file
View File

@ -0,0 +1,19 @@
#!/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.
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
exec python3 "$@"