Skip to content

Commit 44eec0b

Browse files
committed
wip
1 parent f0b1c76 commit 44eec0b

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

python/uv/private/lock.bzl

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
1919
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
2020
load("//python:py_binary.bzl", "py_binary")
2121
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
22-
load("//python/private:text_util.bzl", "render") # buildifier: disable=bzl-visibility
2322

2423
visibility(["//..."])
2524

@@ -28,11 +27,10 @@ _REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:
2827
_LockRunInfo = provider(
2928
doc = "Information about source tree for Sphinx to build.",
3029
fields = {
31-
"args": """
32-
:type: Args
33-
34-
TODO
35-
""",
30+
"args": "",
31+
"cmd": "",
32+
"cmd_file": "",
33+
"srcs": "",
3634
},
3735
)
3836

@@ -45,24 +43,42 @@ def _lock_impl(ctx):
4543
])
4644
args.add("--output-file", ctx.outputs.out)
4745
args.add_all(ctx.files.srcs)
48-
args.use_param_file("--file=%s", use_always = True)
4946

47+
# We use a manual param file so that we can forward it to the debug executable rule
48+
param_file = ctx.actions.declare_file(ctx.label.name + ".params.txt")
49+
ctx.actions.write(
50+
output = param_file,
51+
content = args,
52+
)
53+
54+
run_args = [param_file.path]
55+
args = ctx.actions.args()
56+
args.add_all(run_args)
57+
58+
cmd = ctx.executable.cmd
59+
60+
srcs = ctx.files.srcs + ctx.files.maybe_out + [param_file]
5061
ctx.actions.run(
5162
executable = ctx.executable.cmd,
5263
mnemonic = "RulesPythonLock",
53-
inputs = ctx.files.srcs + ctx.files.maybe_out,
54-
outputs = [
55-
ctx.outputs.out,
56-
],
64+
inputs = srcs,
65+
outputs = [ctx.outputs.out],
5766
arguments = [args],
58-
tools = [ctx.executable.cmd],
67+
tools = [cmd],
5968
progress_message = "Locking requirements using uv",
6069
env = ctx.attr.env,
6170
)
6271

6372
return [
64-
DefaultInfo(files = depset([ctx.outputs.out])),
65-
_LockRunInfo(args = args),
73+
DefaultInfo(
74+
files = depset([ctx.outputs.out]),
75+
),
76+
_LockRunInfo(
77+
cmd = ctx.attr.cmd,
78+
cmd_file = ctx.executable.cmd,
79+
args = run_args,
80+
srcs = srcs,
81+
),
6682
]
6783

6884
_lock = rule(
@@ -84,18 +100,23 @@ _lock = rule(
84100
)
85101

86102
def _run_lock_impl(ctx):
87-
provider = ctx.attr.lock[_LockRunInfo]
88-
89-
executable = ctx.actions.declare_file(ctx.label.name)
90-
ctx.actions.expand_template(
91-
template = ctx.file._template,
103+
run_info = ctx.attr.lock[_LockRunInfo]
104+
executable = ctx.actions.declare_file(ctx.label.name + ".exe")
105+
ctx.actions.symlink(
92106
output = executable,
93-
substitutions = {
94-
" args = []": " args = " + render.indent(render.list(provider.args)),
95-
},
107+
target_file = run_info.cmd_file,
96108
is_executable = True,
97109
)
98-
fail(provider)
110+
111+
runfiles = ctx.runfiles(
112+
files = run_info.srcs,
113+
transitive_files = run_info.cmd[DefaultInfo].files,
114+
).merge(run_info.cmd[DefaultInfo].default_runfiles)
115+
116+
return DefaultInfo(
117+
executable = executable,
118+
runfiles = runfiles,
119+
)
99120

100121
_run_lock = rule(
101122
implementation = _run_lock_impl,

python/uv/private/pip_compile.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import argparse
34
import os
45
import sys
56
from pathlib import Path
@@ -19,14 +20,14 @@ def _run() -> None:
1920
uv = os.fsdecode(uv_path)
2021
env = os.environ.copy()
2122

23+
parser = argparse.ArgumentParser()
24+
parser.add_argument("file", type=Path)
25+
args = parser.parse_args()
26+
sys_args = args.file.read_text().strip().split("\n")
27+
2228
# Let `uv` know that it was spawned by this Python interpreter
2329
env["UV_INTERNAL__PARENT_INTERPRETER"] = sys.executable
2430
args = []
25-
sys_args = sys.argv[1:]
26-
if sys_args[0].startswith("--file"):
27-
# TODO @aignas 2025-03-10: use argparse.ArgumentParser instead
28-
sys_args = Path(sys_args[0].partition("=")[-1]).read_text().strip().split("\n")
29-
3031
src_out = sys_args[1] if sys_args[0] == "--src-out" else None
3132
if src_out:
3233
sys_args = sys_args[2:]

0 commit comments

Comments
 (0)