Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple requirements.in files #159

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions uv/pip.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load("//uv/private:pip.bzl", "pip_compile_test", _pip_compile = "pip_compile")
def pip_compile(
name,
requirements_in = None,
requirements_ins = [],
requirements_txt = None,
target_compatible_with = None,
python_platform = None,
Expand All @@ -21,6 +22,8 @@ def pip_compile(
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_ins: (optional, default []) a list of labels for additional requirements.in files.
These files will be concatenated together in the order they are provided.
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,20 @@ def pip_compile(
[name].update: an alias for [name]
[name]_test: a testable target that will check that requirements_txt is up to date with requirements_in
"""

if requirements_ins:
if requirements_in:
fail("Cannot provide both requirements_in and requirements_ins")
write_target = "_{}.write".format(name)
native.genrule(
name = write_target,
srcs = requirements_ins,
outs = ["_{}.in".format(name)],
# use `awk 1` instead of `cat` ensures trailing newlines for each file
cmd = "awk 1 {} > $(OUTS)".format(" ".join(["$(location {})".format(r) for r in requirements_ins])),
)
requirements_in = write_target

requirements_in = requirements_in or "//:requirements.in"
requirements_txt = requirements_txt or "//:requirements.txt"
tags = tags or []
Expand Down