Skip to content

Commit c12a10c

Browse files
committed
wip
1 parent e7f99cf commit c12a10c

File tree

3 files changed

+96
-8
lines changed

3 files changed

+96
-8
lines changed

python/uv/private/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1616
load("//python:py_binary.bzl", "py_binary")
17+
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
1718

1819
exports_files(
1920
srcs = [
@@ -110,3 +111,12 @@ py_binary(
110111
visibility = ["//visibility:public"],
111112
deps = ["//python/runfiles"],
112113
)
114+
115+
filegroup(
116+
name = "pip_compile_template",
117+
srcs = select({
118+
"@platforms//os:windows": ["//python:none"],
119+
"//conditions:default": ["pip_compile.sh"],
120+
}),
121+
target_compatible_with = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"],
122+
)

python/uv/private/lock.bzl

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
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")
21-
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
2221

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

25-
_REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:incompatible"]
26-
2724
def _impl(ctx):
2825
args = ctx.actions.args()
2926

@@ -67,6 +64,85 @@ _lock = rule(
6764
},
6865
)
6966

67+
_uv_toolchain = Label("//python/uv:uv_toolchain_type")
68+
_py_toolchain = Label("//python:toolchain_type")
69+
70+
_LockInfo = provider(
71+
doc = "",
72+
fields = {
73+
"args": "",
74+
"py": "",
75+
"srcs": "",
76+
"template": "",
77+
"uv": "",
78+
}
79+
)
80+
81+
def _impl2(ctx):
82+
args = ctx.attr.args
83+
srcs = ctx.attr.srcs
84+
85+
toolchain_info = ctx.toolchains[_uv_toolchain]
86+
uv = toolchain_info.uv_toolchain_info.uv[DefaultInfo].files_to_run.executable
87+
88+
py_runtime = ctx.toolchains[_py_toolchain]
89+
fail(py_runtime)
90+
py = ""
91+
92+
return [
93+
DefaultInfo(files = depset([ctx.outputs.out])),
94+
_LockInfo(
95+
args = args,
96+
srcs = srcs,
97+
uv = uv,
98+
py = py,
99+
template = ctx.attr._template,
100+
),
101+
]
102+
103+
_lock2 = rule(
104+
implementation = _impl2,
105+
doc = """\
106+
""",
107+
attrs = {
108+
"args": attr.string_list(),
109+
"env": attr.string_dict(),
110+
"existing_output": attr.label(
111+
mandatory = False, allow_single_file = True,
112+
doc = "An already existing output file that is used as a basis for futher modifications and the locking is not done from scratch",
113+
),
114+
"output": attr.output(mandatory = False),
115+
"python_version": attr.string(doc = "TODO: how do I create a transition thing?"),
116+
"srcs": attr.label_list(mandatory = True, allow_files = True),
117+
"_template": attr.label(default = "//python/uv/private:pip_compile_template"),
118+
},
119+
toolchains = [
120+
_uv_toolchain,
121+
_py_toolchain,
122+
],
123+
)
124+
125+
def _impl3(ctx):
126+
fail()
127+
128+
_lock_run = rule(
129+
implementation = _impl3,
130+
doc = """\
131+
""",
132+
attrs = {
133+
"lock": attr.label(
134+
doc = "",
135+
providers = [_LockInfo],
136+
),
137+
"out": attr.string(),
138+
},
139+
toolchains = [
140+
_uv_toolchain,
141+
_py_toolchain,
142+
],
143+
)
144+
145+
70146
def _maybe_file(path):
71147
"""A small function to return a list of existing outputs.
72148
@@ -161,22 +237,20 @@ def lock(*, name, srcs, out, args = [], **kwargs):
161237
deps = ["//python/runfiles"],
162238
)
163239

164-
_lock(
240+
_lock2(
165241
name = name,
166242
srcs = srcs,
167243
# Check if the output file already exists, if yes, first copy it to the
168244
# output file location in order to make `uv` not change the requirements if
169245
# we are just running the command.
170-
maybe_out = maybe_out,
171-
out = out + ".new",
246+
existing_output = maybe_out,
247+
output = out + ".new",
172248
tags = [
173249
"local",
174250
"manual",
175251
"no-cache",
176252
],
177253
args = args,
178-
target_compatible_with = _REQUIREMENTS_TARGET_COMPATIBLE_WITH,
179-
cmd = locker_target,
180254
)
181255

182256
if maybe_out:

python/uv/private/pip_compile.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
exec uv --output-file "$@"

0 commit comments

Comments
 (0)