@@ -19,24 +19,33 @@ load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
19
19
load ("@bazel_skylib//rules:expand_template.bzl" , "expand_template" )
20
20
load ("//python:py_binary.bzl" , "py_binary" )
21
21
load ("//python/private:bzlmod_enabled.bzl" , "BZLMOD_ENABLED" ) # buildifier: disable=bzl-visibility
22
+ load ("//python/private:text_util.bzl" , "render" ) # buildifier: disable=bzl-visibility
22
23
23
24
visibility (["//..." ])
24
25
25
26
_REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:incompatible" ]
26
27
27
- def _impl (ctx ):
28
- args = ctx .actions .args ()
28
+ _LockRunInfo = provider (
29
+ doc = "Information about source tree for Sphinx to build." ,
30
+ fields = {
31
+ "args" : """
32
+ :type: Args
29
33
30
- # TODO @aignas 2025-03-02: create an executable file here that is using a
31
- # python and uv toolchains.
34
+ TODO
35
+ """ ,
36
+ },
37
+ )
32
38
39
+ def _lock_impl (ctx ):
40
+ args = ctx .actions .args ()
33
41
if ctx .files .maybe_out :
34
42
args .add_all ([
35
43
"--src-out" ,
36
44
ctx .files .maybe_out [0 ].path ,
37
45
])
38
46
args .add ("--output-file" , ctx .outputs .out )
39
47
args .add_all (ctx .files .srcs )
48
+ args .use_param_file ("--file=%s" , use_always = True )
40
49
41
50
ctx .actions .run (
42
51
executable = ctx .executable .cmd ,
@@ -51,10 +60,13 @@ def _impl(ctx):
51
60
env = ctx .attr .env ,
52
61
)
53
62
54
- return [DefaultInfo (files = depset ([ctx .outputs .out ]))]
63
+ return [
64
+ DefaultInfo (files = depset ([ctx .outputs .out ])),
65
+ _LockRunInfo (args = args ),
66
+ ]
55
67
56
68
_lock = rule (
57
- implementation = _impl ,
69
+ implementation = _lock_impl ,
58
70
doc = """\
59
71
""" ,
60
72
attrs = {
@@ -71,6 +83,37 @@ _lock = rule(
71
83
},
72
84
)
73
85
86
+ 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 ,
92
+ output = executable ,
93
+ substitutions = {
94
+ " args = []" : " args = " + render .indent (render .list (provider .args )),
95
+ },
96
+ is_executable = True ,
97
+ )
98
+ fail (provider )
99
+
100
+ _run_lock = rule (
101
+ implementation = _run_lock_impl ,
102
+ doc = """\
103
+ """ ,
104
+ attrs = {
105
+ "lock" : attr .label (
106
+ mandatory = True ,
107
+ providers = [_LockRunInfo ],
108
+ ),
109
+ "_template" : attr .label (
110
+ default = "//python/uv/private:pip_compile.py" ,
111
+ allow_single_file = True ,
112
+ ),
113
+ },
114
+ executable = True ,
115
+ )
116
+
74
117
def lock (* , name , srcs , out , args = [], ** kwargs ):
75
118
"""Pin the requirements based on the src files.
76
119
@@ -142,6 +185,7 @@ def lock(*, name, srcs, out, args = [], **kwargs):
142
185
"//python/uv:current_toolchain" ,
143
186
] + srcs + ([maybe_out ] if maybe_out else []),
144
187
args = run_args ,
188
+ python_version = kwargs .get ("python_version" ),
145
189
tags = ["manual" ],
146
190
deps = ["//python/runfiles" ],
147
191
)
@@ -164,6 +208,11 @@ def lock(*, name, srcs, out, args = [], **kwargs):
164
208
cmd = locker_target ,
165
209
)
166
210
211
+ _run_lock (
212
+ name = name + ".run2" ,
213
+ lock = name ,
214
+ )
215
+
167
216
if maybe_out :
168
217
diff_test (
169
218
name = name + "_test" ,
0 commit comments