Skip to content

Commit

Permalink
feat: add syntax sugar to avoid meaningless requirements.in files in …
Browse files Browse the repository at this point in the history
…the source tree
  • Loading branch information
alexeagle committed Sep 17, 2024
1 parent 2138dc9 commit 60d6f59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/typical/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
1 change: 0 additions & 1 deletion examples/typical/requirements.in

This file was deleted.

12 changes: 11 additions & 1 deletion uv/pip.bzl
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 60d6f59

Please sign in to comment.