Skip to content

Commit 9977027

Browse files
committed
feat: support extra parameters in the locking format and allow setting visibility
Also fix a few bugs in the macro.
1 parent 6babe59 commit 9977027

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

python/uv/private/lock.bzl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ visibility(["//..."])
2424

2525
_REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"]
2626

27-
def lock(*, name, srcs, out, upgrade = False, universal = True, python_version = None):
27+
def lock(*, name, srcs, out, upgrade = False, universal = True, python_version = None, args = [], **kwargs):
2828
"""Pin the requirements based on the src files.
2929
3030
Args:
@@ -36,6 +36,8 @@ def lock(*, name, srcs, out, upgrade = False, universal = True, python_version =
3636
universal: Tell `uv` to generate a universal lock file.
3737
python_version: Tell `rules_python` to use a particular version.
3838
Defaults to the default py toolchain.
39+
args: Extra args to pass to the rule.
40+
**kwargs: Extra kwargs passed to the binary rule.
3941
4042
Differences with the current pip-compile rule:
4143
- This is implemented in shell and uv.
@@ -45,22 +47,25 @@ def lock(*, name, srcs, out, upgrade = False, universal = True, python_version =
4547
pkg = native.package_name()
4648
update_target = name + ".update"
4749

48-
args = [
50+
_args = [
4951
"--custom-compile-command='bazel run //{}:{}'".format(pkg, update_target),
5052
"--generate-hashes",
5153
"--emit-index-url",
5254
"--no-strip-extras",
5355
"--python=$(PYTHON3)",
54-
] + [
56+
] + args + [
5557
"$(location {})".format(src)
5658
for src in srcs
5759
]
5860
if upgrade:
59-
args.append("--upgrade")
61+
_args.append("--upgrade")
6062
if universal:
61-
args.append("--universal")
62-
args.append("--output-file=$@")
63-
cmd = "$(UV_BIN) pip compile " + " ".join(args)
63+
_args.append("--universal")
64+
_args.append("--output-file=$@")
65+
cmd = "$(UV_BIN) pip compile " + " ".join(_args)
66+
67+
# Make a copy to ensure that we are not modifying the initial list
68+
srcs = list(srcs)
6469

6570
# Check if the output file already exists, if yes, first copy it to the
6671
# output file location in order to make `uv` not change the requirements if
@@ -118,4 +123,5 @@ def lock(*, name, srcs, out, upgrade = False, universal = True, python_version =
118123
"REQUIREMENTS_FILE": "$(rootpath {})".format(name),
119124
},
120125
tags = ["manual"],
126+
**kwargs
121127
)

0 commit comments

Comments
 (0)