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 70623e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/typical/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pip_compile(
requirements_txt = "requirements_linux.txt",
)

pip_compile(
name = "generate_requirements_twine",
requirements_in = ["twine"],
requirements_txt = "requirements_twine.txt",
)

create_venv(name = "create-venv")

create_venv(
Expand Down
11 changes: 11 additions & 0 deletions uv/pip.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"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 +20,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 +41,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 70623e0

Please sign in to comment.