|
18 | 18 | load("@bazel_skylib//rules:diff_test.bzl", "diff_test") |
19 | 19 | load("@bazel_skylib//rules:expand_template.bzl", "expand_template") |
20 | 20 | load("//python:py_binary.bzl", "py_binary") |
21 | | -load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility |
22 | 21 |
|
23 | 22 | visibility(["//..."]) |
24 | 23 |
|
25 | | -_REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"] |
26 | | - |
27 | 24 | def _impl(ctx): |
28 | 25 | args = ctx.actions.args() |
29 | 26 |
|
@@ -67,6 +64,85 @@ _lock = rule( |
67 | 64 | }, |
68 | 65 | ) |
69 | 66 |
|
| 67 | +_uv_toolchain = Label("//python/uv:uv_toolchain_type") |
| 68 | +_py_toolchain = Label("//python:toolchain_type") |
| 69 | + |
| 70 | +_LockInfo = provider( |
| 71 | + doc = "", |
| 72 | + fields = { |
| 73 | + "args": "", |
| 74 | + "py": "", |
| 75 | + "srcs": "", |
| 76 | + "template": "", |
| 77 | + "uv": "", |
| 78 | + } |
| 79 | +) |
| 80 | + |
| 81 | +def _impl2(ctx): |
| 82 | + args = ctx.attr.args |
| 83 | + srcs = ctx.attr.srcs |
| 84 | + |
| 85 | + toolchain_info = ctx.toolchains[_uv_toolchain] |
| 86 | + uv = toolchain_info.uv_toolchain_info.uv[DefaultInfo].files_to_run.executable |
| 87 | + |
| 88 | + py_runtime = ctx.toolchains[_py_toolchain] |
| 89 | + fail(py_runtime) |
| 90 | + py = "" |
| 91 | + |
| 92 | + return [ |
| 93 | + DefaultInfo(files = depset([ctx.outputs.out])), |
| 94 | + _LockInfo( |
| 95 | + args = args, |
| 96 | + srcs = srcs, |
| 97 | + uv = uv, |
| 98 | + py = py, |
| 99 | + template = ctx.attr._template, |
| 100 | + ), |
| 101 | + ] |
| 102 | + |
| 103 | +_lock2 = rule( |
| 104 | + implementation = _impl2, |
| 105 | + doc = """\ |
| 106 | +""", |
| 107 | + attrs = { |
| 108 | + "args": attr.string_list(), |
| 109 | + "env": attr.string_dict(), |
| 110 | + "existing_output": attr.label( |
| 111 | + mandatory = False, allow_single_file = True, |
| 112 | + doc = "An already existing output file that is used as a basis for futher modifications and the locking is not done from scratch", |
| 113 | + ), |
| 114 | + "output": attr.output(mandatory = False), |
| 115 | + "python_version": attr.string(doc = "TODO: how do I create a transition thing?"), |
| 116 | + "srcs": attr.label_list(mandatory = True, allow_files = True), |
| 117 | + "_template": attr.label(default = "//python/uv/private:pip_compile_template"), |
| 118 | + }, |
| 119 | + toolchains = [ |
| 120 | + _uv_toolchain, |
| 121 | + _py_toolchain, |
| 122 | + ], |
| 123 | +) |
| 124 | + |
| 125 | +def _impl3(ctx): |
| 126 | + fail() |
| 127 | + |
| 128 | +_lock_run = rule( |
| 129 | + implementation = _impl3, |
| 130 | + doc = """\ |
| 131 | +""", |
| 132 | + attrs = { |
| 133 | + "lock": attr.label( |
| 134 | + doc = "", |
| 135 | + providers = [_LockInfo], |
| 136 | + ), |
| 137 | + "out": attr.string(), |
| 138 | + }, |
| 139 | + toolchains = [ |
| 140 | + _uv_toolchain, |
| 141 | + _py_toolchain, |
| 142 | + ], |
| 143 | +) |
| 144 | + |
| 145 | + |
70 | 146 | def _maybe_file(path): |
71 | 147 | """A small function to return a list of existing outputs. |
72 | 148 |
|
@@ -161,22 +237,20 @@ def lock(*, name, srcs, out, args = [], **kwargs): |
161 | 237 | deps = ["//python/runfiles"], |
162 | 238 | ) |
163 | 239 |
|
164 | | - _lock( |
| 240 | + _lock2( |
165 | 241 | name = name, |
166 | 242 | srcs = srcs, |
167 | 243 | # Check if the output file already exists, if yes, first copy it to the |
168 | 244 | # output file location in order to make `uv` not change the requirements if |
169 | 245 | # we are just running the command. |
170 | | - maybe_out = maybe_out, |
171 | | - out = out + ".new", |
| 246 | + existing_output = maybe_out, |
| 247 | + output = out + ".new", |
172 | 248 | tags = [ |
173 | 249 | "local", |
174 | 250 | "manual", |
175 | 251 | "no-cache", |
176 | 252 | ], |
177 | 253 | args = args, |
178 | | - target_compatible_with = _REQUIREMENTS_TARGET_COMPATIBLE_WITH, |
179 | | - cmd = locker_target, |
180 | 254 | ) |
181 | 255 |
|
182 | 256 | if maybe_out: |
|
0 commit comments