Skip to content

Commit 872e034

Browse files
committed
wip
1 parent c685a42 commit 872e034

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

python/uv/private/copy.py

+45-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
1+
import sys
2+
from difflib import unified_diff
13
from os import environ
24
from pathlib import Path
3-
from sys import stderr
45

5-
src = Path(environ["REQUIREMENTS_FILE"])
6-
assert src.exists(), f"the {src} file does not exist"
7-
dst = ""
86

9-
print(f"cp <bazel-sandbox>/{src}\\n -> <workspace>/{dst}", file=stderr)
10-
build_workspace = Path(environ["BUILD_WORKSPACE_DIRECTORY"])
7+
def main():
8+
src = ""
9+
dst = ""
1110

12-
dst = build_workspace / dst
13-
dst.write_text(src.read_text())
14-
print("Success!", file=stderr)
11+
src = Path(src)
12+
assert src.exists(), f"the {src} file does not exist"
13+
14+
if "BUILD_WORKSPACE_DIRECTORY" not in environ:
15+
dst = Path(dst)
16+
a = dst.read_text() if dst.exists() else "\n"
17+
b = src.read_text()
18+
19+
diff = unified_diff(
20+
a.splitlines(),
21+
b.splitlines(),
22+
str(dst),
23+
str(src),
24+
lineterm="",
25+
)
26+
diff = "\n".join(list(diff))
27+
print(diff)
28+
print(
29+
"""\
30+
31+
===============================================================================
32+
The in source file copy is out of date, please run the failed test target with
33+
'bazel run' to fix the error message update the source file copy.
34+
===============================================================================
35+
"""
36+
)
37+
return 1 if diff else 0
38+
39+
print(f"cp <bazel-sandbox>/{src}", file=sys.stderr)
40+
print(f" -> <workspace>/{dst}", file=sys.stderr)
41+
build_workspace = Path(environ["BUILD_WORKSPACE_DIRECTORY"])
42+
43+
dst = build_workspace / dst
44+
dst.write_text(src.read_text())
45+
print("Success!", file=sys.stderr)
46+
return 0
47+
48+
49+
if __name__ == "__main__":
50+
sys.exit(main())

python/uv/private/lock.bzl

+14-16
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
1919
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
20-
load("//python:py_binary.bzl", "py_binary")
20+
load("//python:py_test.bzl", "py_test")
2121

2222
visibility(["//..."])
2323

@@ -78,6 +78,7 @@ def _lock_impl(ctx):
7878
lock_args.add("--custom-compile-command", update_command)
7979
run_args.extend(("--custom-compile-command", "'{}'".format(update_command)))
8080

81+
lock_args.add("--no-progress")
8182
lock_args.add("--python", py_runtime.interpreter)
8283
lock_args.add_all(args)
8384
lock_args.add_all(srcs)
@@ -225,7 +226,7 @@ def lock(*, name, srcs, out, args = [], **kwargs):
225226
srcs: The srcs to use as inputs.
226227
out: The output file.
227228
args: Extra args to pass to `uv`.
228-
**kwargs: Extra kwargs passed to the {obj}`py_binary` rule.
229+
**kwargs: Extra kwargs passed to the {obj}`py_test` rule.
229230
"""
230231
pkg = native.package_name()
231232
update_target = "{}.update".format(name)
@@ -249,14 +250,6 @@ def lock(*, name, srcs, out, args = [], **kwargs):
249250
args = args,
250251
)
251252

252-
if maybe_out:
253-
diff_test(
254-
name = name + "_test",
255-
file1 = out + ".new",
256-
file2 = maybe_out,
257-
tags = ["manual"],
258-
)
259-
260253
_lock_run(
261254
name = locker_target,
262255
lock = name,
@@ -271,16 +264,21 @@ def lock(*, name, srcs, out, args = [], **kwargs):
271264
template = "//python/uv/private:copy.py",
272265
substitutions = {
273266
'dst = ""': 'dst = "{}/{}"'.format(pkg, out),
267+
'src = ""': 'src = "{}/{}.new"'.format(pkg, out),
274268
},
275269
)
276270

277-
py_binary(
271+
py_test(
278272
name = update_target,
279273
srcs = [update_target + ".py"],
280-
data = [name],
281-
env = {
282-
"REQUIREMENTS_FILE": "$(rootpath {})".format(name),
283-
},
284-
tags = ["manual"],
274+
data = [name] + ([] if not maybe_out else [maybe_out]),
285275
**kwargs
286276
)
277+
278+
if maybe_out:
279+
diff_test(
280+
name = name + "_test",
281+
file1 = out + ".new",
282+
file2 = maybe_out,
283+
tags = ["manual"],
284+
)

0 commit comments

Comments
 (0)