Start migrating to upstream pip package management
Rather than packaging up Debian packages, we can start using upstream
wheels.
There are still some issues to figure out. The biggest one is how to
make the upstream packages reproducible. Some packages like numpy are
distributed as wheels which should address the majority of concerns.
Some packages are only distributed in source form though. Those will
be compiled by rules_python against the host system. We'll need to
find a better way to deal with those.
For now you can use the new Python setup if you use
`--config=k8_upstream_python`. Once the majority of the issues are
fixed, I will get rid of the special casing. Then you'll only need
`--config=k8`.
Change-Id: I982ea057e0f47cdfda3d11d58275d7c07e34975a
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
diff --git a/tools/python/BUILD b/tools/python/BUILD
index 9939653..37101f5 100644
--- a/tools/python/BUILD
+++ b/tools/python/BUILD
@@ -1,4 +1,5 @@
load("@rules_python//python:defs.bzl", "py_runtime_pair")
+load("@rules_python//python:pip.bzl", "compile_pip_requirements")
py_runtime(
name = "python3_runtime",
@@ -25,7 +26,52 @@
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
+ "//tools/platforms/python:debian_bundled_python",
],
toolchain = ":py_runtime",
toolchain_type = "@rules_python//python:toolchain_type",
)
+
+# Invoke this via "bazel run //tools/python:requirements.update".
+compile_pip_requirements(
+ name = "requirements",
+ requirements_in = "requirements.txt",
+ requirements_txt = "requirements.lock.txt",
+ tags = [
+ # The test pings pypi.org to make sure that the lock file matches the
+ # requirements file.
+ # TODO(phil): Disable this if it's too flaky.
+ "requires-network",
+ ],
+)
+
+py_runtime(
+ name = "upstream_python3_runtime",
+ files = [
+ "runtime_binary.sh",
+ "@python3_9_x86_64-unknown-linux-gnu//:files",
+ ],
+ interpreter = "runtime_binary.sh",
+ python_version = "PY3",
+)
+
+py_runtime_pair(
+ name = "upstream_py_runtime",
+ py2_runtime = None,
+ py3_runtime = ":upstream_python3_runtime",
+)
+
+toolchain(
+ name = "upstream_python_toolchain",
+ exec_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:linux",
+ ],
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:linux",
+ "//tools/platforms/python:upstream_bundled_python",
+ ],
+ toolchain = ":upstream_py_runtime",
+ toolchain_type = "@rules_python//python:toolchain_type",
+)