Skip to content

Commit dc231df

Browse files
committed
wip
1 parent 4442b12 commit dc231df

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

python/uv/private/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1616
load("//python:py_binary.bzl", "py_binary")
1717

1818
exports_files(
19-
srcs = ["pip_compile.py"],
19+
srcs = [
20+
"copy.py",
21+
"pip_compile.py",
22+
],
2023
# only because this is used from a macro to template
2124
visibility = ["//visibility:public"],
2225
)

python/uv/private/copy.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from os import environ
2+
from pathlib import Path
3+
from sys import stderr
4+
5+
src = Path(environ["REQUIREMENTS_FILE"])
6+
assert src.exists(), f"the {src} file does not exist"
7+
dst = ""
8+
9+
print(f"cp <bazel-sandbox>/{src}\\n -> <workspace>/{dst}", file=stderr)
10+
build_workspace = Path(environ["BUILD_WORKSPACE_DIRECTORY"])
11+
12+
dst = build_workspace / dst
13+
dst.write_text(src.read_text())
14+
print("Success!", file=stderr)

python/uv/private/lock.bzl

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""
1717

1818
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
19-
load("@bazel_skylib//rules:write_file.bzl", "write_file")
2019
load("//python:py_binary.bzl", "py_binary")
2120
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
2221

@@ -124,8 +123,8 @@ def lock(*, name, srcs, out, args = [], **kwargs):
124123
"--no-cache",
125124
]
126125
args += user_args
127-
run_args = []
128126

127+
run_args = []
129128
existing_outputs = _glob(out)
130129
if existing_outputs:
131130
# This means that the output file already exists and it should be used
@@ -186,29 +185,18 @@ def lock(*, name, srcs, out, args = [], **kwargs):
186185

187186
# Write a script that can be used for updating the in-tree version of the
188187
# requirements file
189-
write_file(
188+
expand_template(
190189
name = update_target + "_gen",
191190
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+
},
206195
)
207196

208197
py_binary(
209198
name = update_target,
210199
srcs = [update_target + ".py"],
211-
main = update_target + ".py",
212200
data = [name],
213201
env = {
214202
"REQUIREMENTS_FILE": "$(rootpath {})".format(name),

0 commit comments

Comments
 (0)