Minor crimes to deal with platform-variable pythons

This commit is contained in:
Reid 'arrdem' McKenzie 2022-05-11 23:20:59 -07:00
commit dadd039a84
3 changed files with 33 additions and 10 deletions
tools/python

View file

@ -12,12 +12,13 @@ exports_files([
"defs.bzl",
"bzl_pytest_shim.py",
"bzl_unittest_shim.py",
"pythonshim",
])
py_runtime(
name = "python3_runtime",
files = [],
interpreter_path = "/usr/bin/python3.10",
interpreter = ":pythonshim",
python_version = "PY3",
visibility = ["//visibility:public"],
)

21
tools/python/pythonshim Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
# Bazel STRONGLY disapproves of linking dynamically to a Python interpreter.
# But ... that's exactly what we want to do.
# So this script exists to find a 'compliant' Python install and use that.
PYTHONREV="3.10"
CMD="python${PYTHONREV}"
if [ -x "$(command -v "$CMD")" ]; then
exec "$(which "$CMD")" "$@"
else
case "$(uname)" in
Darwin)
# FIXME: What if it isn't there?
exec /opt/homebrew/bin/"$CMD" "$@"
;;
esac
echo "Error: Unable to find a viable Python executable" >&2
exit 1
fi