Repository navigation
Expand file tree
/
Copy pathlock.bzl
More file actions
76 lines (63 loc) · 2.56 KB
/
Copy pathlock.bzl
File metadata and controls
76 lines (63 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2025 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The `uv` locking rule.
Differences with the legacy {obj}`compile_pip_requirements` rule:
- This is implemented as a rule that performs locking in a build action.
- Additionally one can use the runnable target.
- Uses `uv`.
- This does not error out if the output file does not exist yet.
- Supports transitions out of the box.
Note, this does not provide a test target like {obj}`compile_pip_requirements` does.
The `uv lock` and `uv pip compile` commands are not hermetic and thus a test
based on them would most likely be flaky:
- It may require auth injected into it, so most likely it requires a local tag added so that the bazel action runs without sandboxing.
- It requires network access.
Given those points, a test target should be an explicit and properly documented target and not a hidden implicit target.
If, you would like to add a test target that always does the locking automatically to ensure that the
lock file is up-to-date, add something similar to:
```starlark
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
load("@rules_python//python/uv:lock.bzl", "lock")
lock(
name = "requirements",
srcs = ["pyproject.toml"],
out = "uv.lock",
)
native_test(
name = "requirements_test",
src = "requirements.update",
)
```
### `[tool.uv]` settings support
When a `pyproject.toml` file is included in {arg}`lock.srcs`, the
`--project` flag is automatically passed to `uv` using the
directory of the shortest-path `pyproject.toml`. This causes `uv` to
read `[tool.uv]` settings such as `no-build-isolation`,
`exclude-dependencies`, and `[tool.uv.workspace]` from that file.
If the auto-detection doesn't select the right project (e.g. in complex
workspace layouts), use the `project` parameter to override it:
```starlark
lock(
name = "requirements",
srcs = [
"pyproject.toml",
"requirements.in",
],
out = "requirements_lock.txt",
project = "subproject",
)
```
"""
load("//python/uv/private:lock.bzl", _lock = "lock")
lock = _lock