From 8a70d2b64db3c7925d80321763e47a4689065a00 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Wed, 11 May 2022 23:20:59 -0700 Subject: [PATCH] Minor crimes to deal with platform-variable pythons --- WORKSPACE | 19 ++++++++++--------- tools/python/BUILD | 3 ++- tools/python/pythonshim | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100755 tools/python/pythonshim diff --git a/WORKSPACE b/WORKSPACE index 806a371..fad71a2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -53,7 +53,7 @@ load("@rules_python//python:pip.bzl", "pip_parse") pip_parse( name = "arrdem_source_pypi", requirements_lock = "//tools/python:requirements.txt", - python_interpreter = "/usr/bin/python3.10" + python_interpreter_target = "//tools/python:pythonshim", ) # Load the starlark macro which will define your dependencies. @@ -62,13 +62,14 @@ load("@arrdem_source_pypi//:requirements.bzl", "install_deps") # Call it to define repos for your requirements. install_deps() -# git_repository( -# name = "rules_zapp", -# remote = "https://github.com/arrdem/rules_zapp.git", -# tag = "0.1.2", -# ) - -local_repository( +git_repository( name = "rules_zapp", - path = "/home/arrdem/doc/hobby/programming/lang/python/rules_zapp", + remote = "https://github.com/arrdem/rules_zapp.git", + commit = "d7a0382927fb8a68115b560f4fee7dca743068f8", + # tag = "0.1.2", ) + +# local_repository( +# name = "rules_zapp", +# path = "/home/arrdem/doc/hobby/programming/lang/python/rules_zapp", +# ) diff --git a/tools/python/BUILD b/tools/python/BUILD index 5aca2e3..181f52e 100644 --- a/tools/python/BUILD +++ b/tools/python/BUILD @@ -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"], ) diff --git a/tools/python/pythonshim b/tools/python/pythonshim new file mode 100755 index 0000000..a3a0a7e --- /dev/null +++ b/tools/python/pythonshim @@ -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