1515"""A simple macro to lock the requirements.
1616"""
1717
18+ load ("@bazel_skylib//rules:expand_template.bzl" , "expand_template" )
1819load ("@bazel_skylib//rules:native_binary.bzl" , "native_binary" )
1920load ("@bazel_skylib//rules:write_file.bzl" , "write_file" )
2021load ("//python:py_binary.bzl" , "py_binary" )
@@ -27,7 +28,7 @@ _REQUIREMENTS_TARGET_COMPATIBLE_WITH = [] if BZLMOD_ENABLED else ["@platforms//:
2728_RunLockInfo = provider (
2829 doc = "Information for running the underlying Sphinx command directly" ,
2930 fields = {
30- "locker " : """
31+ "cmd " : """
3132:type: Target
3233
3334The locker binary to run.
@@ -46,30 +47,29 @@ def _impl(ctx):
4647 ctx .files .src_outs [0 ].path ,
4748 ])
4849 args .add ("--output-file" , ctx .outputs .out )
49- args .add_all (ctx .attr .args )
5050
5151 # TODO @aignas 2025-03-02: add the following deps to _RunLockInfo
5252 srcs = ctx .files .srcs + ctx .files .src_outs
5353 args .add_all (ctx .files .srcs )
5454
5555 ctx .actions .run (
56- executable = ctx .executable ._locker ,
56+ executable = ctx .executable .cmd ,
5757 mnemonic = "RulesPythonLock" ,
5858 inputs = srcs ,
5959 outputs = [
6060 ctx .outputs .out ,
6161 ],
6262 arguments = [args ],
6363 tools = [
64- ctx .executable ._locker ,
64+ ctx .executable .cmd ,
6565 ],
6666 progress_message = "Locking requirements using uv" ,
6767 env = ctx .attr .env ,
6868 )
6969
7070 return [
7171 DefaultInfo (files = depset ([ctx .outputs .out ])),
72- _RunLockInfo (locker = ctx .executable ._locker ),
72+ _RunLockInfo (cmd = ctx .executable .cmd ),
7373 ]
7474
7575_lock = rule (
@@ -78,15 +78,15 @@ _lock = rule(
7878 """ ,
7979 attrs = {
8080 "args" : attr .string_list (),
81- "env" : attr .string_dict (),
82- "out" : attr .output (mandatory = True ),
83- "src_outs" : attr .label_list (mandatory = True , allow_files = True ),
84- "srcs" : attr .label_list (mandatory = True , allow_files = True ),
85- "_locker" : attr .label (
81+ "cmd" : attr .label (
8682 default = "//python/uv/private:pip_compile" ,
8783 executable = True ,
8884 cfg = "target" ,
8985 ),
86+ "env" : attr .string_dict (),
87+ "out" : attr .output (mandatory = True ),
88+ "src_outs" : attr .label_list (mandatory = True , allow_files = True ),
89+ "srcs" : attr .label_list (mandatory = True , allow_files = True ),
9090 },
9191)
9292
@@ -130,6 +130,26 @@ def lock(*, name, srcs, out, args = [], **kwargs):
130130 ]
131131 args += user_args
132132
133+ expand_template (
134+ name = name + "_locker_src" ,
135+ out = name + "_locker.py" ,
136+ template = "//python/uv/private:pip_compile.py" ,
137+ substitutions = {
138+ " args = []" : " args = " + repr (args ),
139+ },
140+ tags = ["manual" ],
141+ )
142+
143+ py_binary (
144+ name = name + "_locker" ,
145+ srcs = [name + "_locker.py" ],
146+ data = [
147+ "//python/uv:current_toolchain" ,
148+ ],
149+ tags = ["manual" ],
150+ deps = ["//python/runfiles" ],
151+ )
152+
133153 _lock (
134154 name = name ,
135155 srcs = srcs ,
@@ -145,6 +165,7 @@ def lock(*, name, srcs, out, args = [], **kwargs):
145165 ],
146166 args = args ,
147167 target_compatible_with = _REQUIREMENTS_TARGET_COMPATIBLE_WITH ,
168+ cmd = name + "_locker" ,
148169 )
149170
150171 run_args = []
0 commit comments