Skip to content

Commit 3bffc0d

Browse files
committed
add docs
1 parent f1ab3b7 commit 3bffc0d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

python/uv/private/lock.bzl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Differences with the current {obj}`compile_pip_requirements` rule:
2121
- This does not error out if the output file does not exist yet.
2222
- Supports transitions out of the box.
2323
24-
2524
Note, this does not provide a `test` target, if you would like to add a test
2625
target that always does the locking automatically to ensure that the
2726
`requirements.txt` file is up-to-date, add something similar to:
@@ -283,6 +282,17 @@ def _maybe_file(path):
283282
def lock(*, name, srcs, out, args = [], env = None, **kwargs):
284283
"""Pin the requirements based on the src files.
285284
285+
This macro creates the following targets:
286+
- `name`: the target that creates the requirements.txt file in a build
287+
action.
288+
- `name.run`: a runnable target that can be used to pass extra parameters
289+
to the same command that would be run in the `name` action. This will
290+
update the source copy of the requirements file.
291+
- `name.update`: a target that can be run to update the source-tree version
292+
of the requirements lock file. The output can be fed to the
293+
{obj}`pip.parse` bzlmod extension tag class. Note, you can use
294+
`native_test` to wrap this target to make a test.
295+
286296
Args:
287297
name: The name of the target to run for updating the requirements.
288298
srcs: The srcs to use as inputs.
@@ -295,8 +305,11 @@ def lock(*, name, srcs, out, args = [], env = None, **kwargs):
295305
"""
296306
update_target = "{}.update".format(name)
297307
locker_target = "{}.run".format(name)
308+
309+
# Check if the output file already exists, if yes, first copy it to the
310+
# output file location in order to make `uv` not change the requirements if
311+
# we are just running the command.
298312
maybe_out = _maybe_file(out)
299-
out_new = name + ".out"
300313
target_compatible_with = kwargs.pop("target_compatible_with", None)
301314
if target_compatible_with == None and not BZLMOD_ENABLED:
302315
target_compatible_with = ["@platforms//:incompatible"]
@@ -310,9 +323,6 @@ def lock(*, name, srcs, out, args = [], env = None, **kwargs):
310323
_lock(
311324
name = name,
312325
srcs = srcs,
313-
# Check if the output file already exists, if yes, first copy it to the
314-
# output file location in order to make `uv` not change the requirements if
315-
# we are just running the command.
316326
existing_output = maybe_out,
317327
update_target = update_target,
318328
tags = [
@@ -346,7 +356,7 @@ def lock(*, name, srcs, out, args = [], env = None, **kwargs):
346356
template = "//python/uv/private:lock_copier.py",
347357
substitutions = {
348358
"{{dst}}": "{}/{}".format(pkg, out),
349-
"{{src}}": "{}/{}".format(pkg, out_new),
359+
"{{src}}": "{}/{}.out".format(pkg, name),
350360
"{{update_target}}": "//{}/{}".format(pkg, update_target),
351361
},
352362
)

0 commit comments

Comments
 (0)