@@ -19,24 +19,33 @@ load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
1919load ("@bazel_skylib//rules:expand_template.bzl" , "expand_template" )
2020load ("//python:py_binary.bzl" , "py_binary" )
2121load ("//python/private:bzlmod_enabled.bzl" , "BZLMOD_ENABLED" ) # buildifier: disable=bzl-visibility
22+ load ("//python/private:text_util.bzl" , "render" ) # buildifier: disable=bzl-visibility
2223
2324visibility (["//..." ])
2425
2526_REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:incompatible" ]
2627
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
2933
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+ )
3238
39+ def _lock_impl (ctx ):
40+ args = ctx .actions .args ()
3341 if ctx .files .maybe_out :
3442 args .add_all ([
3543 "--src-out" ,
3644 ctx .files .maybe_out [0 ].path ,
3745 ])
3846 args .add ("--output-file" , ctx .outputs .out )
3947 args .add_all (ctx .files .srcs )
48+ args .use_param_file ("--file=%s" , use_always = True )
4049
4150 ctx .actions .run (
4251 executable = ctx .executable .cmd ,
@@ -51,10 +60,13 @@ def _impl(ctx):
5160 env = ctx .attr .env ,
5261 )
5362
54- return [DefaultInfo (files = depset ([ctx .outputs .out ]))]
63+ return [
64+ DefaultInfo (files = depset ([ctx .outputs .out ])),
65+ _LockRunInfo (args = args ),
66+ ]
5567
5668_lock = rule (
57- implementation = _impl ,
69+ implementation = _lock_impl ,
5870 doc = """\
5971 """ ,
6072 attrs = {
@@ -71,6 +83,37 @@ _lock = rule(
7183 },
7284)
7385
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+
74117def lock (* , name , srcs , out , args = [], ** kwargs ):
75118 """Pin the requirements based on the src files.
76119
@@ -142,6 +185,7 @@ def lock(*, name, srcs, out, args = [], **kwargs):
142185 "//python/uv:current_toolchain" ,
143186 ] + srcs + ([maybe_out ] if maybe_out else []),
144187 args = run_args ,
188+ python_version = kwargs .get ("python_version" ),
145189 tags = ["manual" ],
146190 deps = ["//python/runfiles" ],
147191 )
@@ -164,6 +208,11 @@ def lock(*, name, srcs, out, args = [], **kwargs):
164208 cmd = locker_target ,
165209 )
166210
211+ _run_lock (
212+ name = name + ".run2" ,
213+ lock = name ,
214+ )
215+
167216 if maybe_out :
168217 diff_test (
169218 name = name + "_test" ,
0 commit comments