|
16 | 16 | """ |
17 | 17 |
|
18 | 18 | load("@bazel_skylib//rules:expand_template.bzl", "expand_template") |
19 | | -load("@bazel_skylib//rules:write_file.bzl", "write_file") |
20 | 19 | load("//python:py_binary.bzl", "py_binary") |
21 | 20 | load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility |
22 | 21 |
|
@@ -124,8 +123,8 @@ def lock(*, name, srcs, out, args = [], **kwargs): |
124 | 123 | "--no-cache", |
125 | 124 | ] |
126 | 125 | args += user_args |
127 | | - run_args = [] |
128 | 126 |
|
| 127 | + run_args = [] |
129 | 128 | existing_outputs = _glob(out) |
130 | 129 | if existing_outputs: |
131 | 130 | # This means that the output file already exists and it should be used |
@@ -186,29 +185,18 @@ def lock(*, name, srcs, out, args = [], **kwargs): |
186 | 185 |
|
187 | 186 | # Write a script that can be used for updating the in-tree version of the |
188 | 187 | # requirements file |
189 | | - write_file( |
| 188 | + expand_template( |
190 | 189 | name = update_target + "_gen", |
191 | 190 | out = update_target + ".py", |
192 | | - content = [ |
193 | | - "from os import environ", |
194 | | - "from pathlib import Path", |
195 | | - "from sys import stderr", |
196 | | - "", |
197 | | - 'src = Path(environ["REQUIREMENTS_FILE"])', |
198 | | - 'assert src.exists(), f"the {src} file does not exist"', |
199 | | - 'dst = "{}/{}"'.format(pkg, out), |
200 | | - 'print(f"cp <bazel-sandbox>/{src}\\n -> <workspace>/{dst}", file=stderr)', |
201 | | - 'build_workspace = Path(environ["BUILD_WORKSPACE_DIRECTORY"])', |
202 | | - "dst = build_workspace / dst", |
203 | | - "dst.write_text(src.read_text())", |
204 | | - 'print("Success!", file=stderr)', |
205 | | - ], |
| 191 | + template = "//python/uv/private:copy.py", |
| 192 | + substitutions = { |
| 193 | + 'dst = ""': 'dst = "{}/{}"'.format(pkg, out), |
| 194 | + }, |
206 | 195 | ) |
207 | 196 |
|
208 | 197 | py_binary( |
209 | 198 | name = update_target, |
210 | 199 | srcs = [update_target + ".py"], |
211 | | - main = update_target + ".py", |
212 | 200 | data = [name], |
213 | 201 | env = { |
214 | 202 | "REQUIREMENTS_FILE": "$(rootpath {})".format(name), |
|
0 commit comments