diff --git a/examples/typical/BUILD.bazel b/examples/typical/BUILD.bazel index ae3c046..88401b6 100644 --- a/examples/typical/BUILD.bazel +++ b/examples/typical/BUILD.bazel @@ -6,6 +6,7 @@ pip_compile(name = "generate_requirements_txt") pip_compile( name = "generate_requirements_linux_txt", python_platform = "x86_64-unknown-linux-gnu", + requirements_in = ["click~=8.1.7"], requirements_txt = "requirements_linux.txt", ) diff --git a/examples/typical/requirements.in b/examples/typical/requirements.in deleted file mode 100644 index dbcc677..0000000 --- a/examples/typical/requirements.in +++ /dev/null @@ -1 +0,0 @@ -click~=8.1.7 \ No newline at end of file diff --git a/uv/pip.bzl b/uv/pip.bzl index bb95861..cd09bb1 100644 --- a/uv/pip.bzl +++ b/uv/pip.bzl @@ -1,5 +1,6 @@ "uv based pip compile rules" - +load("@bazel_skylib//lib:types.bzl", "types") +load("@bazel_skylib//rules:write_file.bzl", "write_file") load("//uv/private:pip.bzl", "pip_compile_test", _pip_compile = "pip_compile") def pip_compile( @@ -18,6 +19,7 @@ def pip_compile( Args: name: name of the primary compilation target. requirements_in: (optional, default "//:requirements.in") a label for the requirements.in file. + May also be provided as a list of strings which represent the requirements file lines. requirements_txt: (optional, default "//:requirements.txt") a label for the requirements.txt file. python_platform: (optional) a uv pip compile compatible value for --python-platform. target_compatible_with: (optional) specify that a particular target is compatible only with certain @@ -38,6 +40,14 @@ def pip_compile( requirements_in = requirements_in or "//:requirements.in" requirements_txt = requirements_txt or "//:requirements.txt" tags = tags or [] + if types.is_list(requirements_in): + write_target = "_{}.write".format(name) + write_file( + name = write_target, + out = "_{}.requirements.in".format(name), + content = requirements_in, + ) + requirements_in = write_target _pip_compile( name = name,