diff --git a/examples/typical/BUILD.bazel b/examples/typical/BUILD.bazel index b3ebf69..569e59f 100644 --- a/examples/typical/BUILD.bazel +++ b/examples/typical/BUILD.bazel @@ -3,4 +3,10 @@ load("@rules_uv//uv:venv.bzl", "create_venv") pip_compile(name = "generate_requirements_txt") +pip_compile( + name = "generate_requirements_linux_txt", + python_platform = "x86_64-unknown-linux-gnu", + requirements_txt = "requirements_linux.txt", +) + create_venv(name = "create-venv") diff --git a/examples/typical/requirements_linux.txt b/examples/typical/requirements_linux.txt new file mode 100644 index 0000000..f2aabcd --- /dev/null +++ b/examples/typical/requirements_linux.txt @@ -0,0 +1,3 @@ +click==8.1.7 \ + --hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \ + --hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de diff --git a/uv/private/pip.bzl b/uv/private/pip.bzl index bd31d7b..2ba782a 100644 --- a/uv/private/pip.bzl +++ b/uv/private/pip.bzl @@ -5,9 +5,15 @@ _PY_TOOLCHAIN = "@bazel_tools//tools/python:toolchain_type" _common_attrs = { "requirements_in": attr.label(mandatory = True, allow_single_file = True), "requirements_txt": attr.label(mandatory = True, allow_single_file = True), + "python_platform": attr.string(default = ""), "_uv": attr.label(default = "@multitool//tools/uv", executable = True, cfg = "exec"), } +def _python_platform(maybe_python_platform): + if maybe_python_platform == "": + return "" + return "--python-platform {python_platform}".format(python_platform = maybe_python_platform) + def _uv_pip_compile(ctx, template, executable): py_toolchain = ctx.toolchains[_PY_TOOLCHAIN] ctx.actions.expand_template( @@ -18,6 +24,7 @@ def _uv_pip_compile(ctx, template, executable): "{{requirements_in}}": ctx.file.requirements_in.short_path, "{{requirements_txt}}": ctx.file.requirements_txt.short_path, "{{resolved_python}}": py_toolchain.py3_runtime.interpreter.short_path, + "{{python_platform}}": _python_platform(ctx.attr.python_platform), }, ) @@ -64,11 +71,12 @@ _pip_compile_test = rule( test = True, ) -def pip_compile(name, requirements_in = None, requirements_txt = None, target_compatible_with = None): +def pip_compile(name, requirements_in = None, requirements_txt = None, target_compatible_with = None, python_platform = None): _pip_compile( name = name, requirements_in = requirements_in or "//:requirements.in", requirements_txt = requirements_txt or "//:requirements.txt", + python_platform = python_platform or "", target_compatible_with = target_compatible_with, ) @@ -76,6 +84,7 @@ def pip_compile(name, requirements_in = None, requirements_txt = None, target_co name = name + "_diff_test", requirements_in = requirements_in or "//:requirements.in", requirements_txt = requirements_txt or "//:requirements.txt", + python_platform = python_platform or "", target_compatible_with = target_compatible_with, tags = ["requires-network"], ) diff --git a/uv/private/pip_compile.sh b/uv/private/pip_compile.sh index cb0c32f..55ce47b 100644 --- a/uv/private/pip_compile.sh +++ b/uv/private/pip_compile.sh @@ -3,6 +3,7 @@ set -euo pipefail UV="{{uv}}" +PYTHON_PLATFORM="{{python_platform}}" RESOLVED_PYTHON="{{resolved_python}}" REQUIREMENTS_IN="{{requirements_in}}" REQUIREMENTS_TXT="{{requirements_txt}}" @@ -20,6 +21,7 @@ $UV pip compile \ --no-header \ --no-strip-extras \ --python-version=$PYTHON_VERSION \ + $(echo $PYTHON_PLATFORM) \ -o $REQUIREMENTS_TXT \ $REQUIREMENTS_IN \ $@ diff --git a/uv/private/pip_compile_test.sh b/uv/private/pip_compile_test.sh index 70a9cc7..c74d19d 100644 --- a/uv/private/pip_compile_test.sh +++ b/uv/private/pip_compile_test.sh @@ -3,6 +3,7 @@ set -euo pipefail UV="{{uv}}" +PYTHON_PLATFORM="{{python_platform}}" RESOLVED_PYTHON="{{resolved_python}}" REQUIREMENTS_IN="{{requirements_in}}" REQUIREMENTS_TXT="{{requirements_txt}}" @@ -21,5 +22,6 @@ $UV pip compile \ --no-header \ --no-strip-extras \ --python-version=$PYTHON_VERSION \ + $(echo $PYTHON_PLATFORM) \ -c $REQUIREMENTS_TXT \ $REQUIREMENTS_IN