Skip to content

Commit d979829

Browse files
committed
run 'uv' directly via run_shell
1 parent 4fc8a0f commit d979829

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

python/uv/private/lock.bzl

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,13 @@ def _lock_impl(ctx):
7373

7474
py_runtime = ctx.toolchains[TARGET_TOOLCHAIN_TYPE].py3_runtime
7575

76-
cmd = ctx.actions.declare_file(ctx.label.name + ".exe")
77-
ctx.actions.expand_template(
78-
template = ctx.files._template[0],
79-
substitutions = {
80-
'"{{args}}"': "",
81-
"{{bazel_out}}": output.path,
82-
"{{src_out}}": existing_output[0].path,
83-
"{{uv}}": uv.path,
84-
},
85-
output = cmd,
86-
is_executable = True,
87-
)
88-
8976
run_args = []
9077
lock_args = ctx.actions.args()
9178

79+
lock_args.add(uv)
80+
lock_args.add("pip")
81+
lock_args.add("compile")
82+
9283
def _add_args(arg, maybe_value = None):
9384
run_args.append(arg)
9485
if maybe_value:
@@ -120,17 +111,37 @@ def _lock_impl(ctx):
120111
lock_args.add("--python", py_runtime.interpreter_path)
121112
lock_args.add_all(args)
122113
lock_args.add_all(srcs)
123-
124-
ctx.actions.run(
125-
executable = cmd,
126-
mnemonic = "PyRequirementsLockUv",
127-
inputs = srcs + ctx.files.existing_output,
128-
outputs = [output],
129-
arguments = [lock_args],
130-
tools = [cmd],
131-
progress_message = "Creating a requirements.txt with uv: //{}:{}".format(ctx.label.package, ctx.label.name),
132-
env = ctx.attr.env,
133-
)
114+
lock_args.add("--output-file", output)
115+
116+
progress_message = "Creating a requirements.txt with uv: //{}:{}".format(ctx.label.package, ctx.label.name)
117+
if existing_output:
118+
ctx.actions.run_shell(
119+
command = "cp {src} {dst} && \"$@\"".format(
120+
src = existing_output.path,
121+
dst = output.path,
122+
),
123+
mnemonic = "PyRequirementsLockUv",
124+
inputs = srcs + ctx.files.existing_output,
125+
outputs = [output],
126+
arguments = [lock_args],
127+
tools = [uv],
128+
progress_message = progress_message,
129+
env = ctx.attr.env,
130+
)
131+
else:
132+
ctx.actions.run_shell(
133+
command = "\"$@\"".format(
134+
src = ctx.files.existing_output[0].path,
135+
dst = output.path,
136+
),
137+
mnemonic = "PyRequirementsLockUv",
138+
inputs = srcs,
139+
outputs = [output],
140+
arguments = [lock_args],
141+
tools = [uv],
142+
progress_message = progress_message,
143+
env = ctx.attr.env,
144+
)
134145

135146
return [
136147
DefaultInfo(files = depset([output])),

0 commit comments

Comments
 (0)