@@ -150,22 +150,22 @@ _lock = rule(
150150 """ ,
151151 attrs = {
152152 "args" : attr .string_list (
153- doc = "Args to pass to `uv`." ,
153+ doc = "Public, see the docs in the macro." ,
154+ mandatory = True ,
154155 ),
155156 "build_constraints" : attr .label_list (
156- mandatory = False ,
157+ mandatory = True ,
157158 allow_files = True ,
158- doc = """The files to constrain the resolution."" " ,
159+ doc = "Public, see the docs in the macro. " ,
159160 ),
160161 "constraints" : attr .label_list (
161- mandatory = False ,
162+ mandatory = True ,
162163 allow_files = True ,
163- doc = """The files to constrain the versions used when building wheels."" " ,
164+ doc = "Public, see the docs in the macro. " ,
164165 ),
165166 "env" : attr .string_dict (
166- doc = """\
167- The env variables that are set when executing `uv`.
168- """ ,
167+ doc = "Public, see the docs in the macro." ,
168+ mandatory = True ,
169169 ),
170170 "existing_output" : attr .label (
171171 mandatory = False ,
@@ -176,27 +176,17 @@ modifications and the locking is not done from scratch.
176176""" ,
177177 ),
178178 "generate_hashes" : attr .bool (
179- default = True ,
180- doc = """\
181- Generate hashes for all of the requirements. This is a must if you want to use
182- {attr}`pip.parse.experimental_index_url`.
183- """ ,
179+ mandatory = True ,
180+ doc = "Public, see the docs in the macro." ,
184181 ),
185182 "srcs" : attr .label_list (
186183 mandatory = True ,
187184 allow_files = True ,
188- doc = """\
189- The sources that will be used. Add all of the files that would be passed as
190- srcs to the `uv pip compile` command.
191- """ ,
185+ doc = "Public, see the docs in the macro." ,
192186 ),
193187 "strip_extras" : attr .bool (
194- default = False ,
195- doc = """\
196- Currently `rules_python` requires `--no-strip-extras` to properly function, but
197- sometimes one may want to not have the extras if you are compiling the
198- requirements file for using it as a constraints file.
199- """ ,
188+ mandatory = True ,
189+ doc = "Public, see the docs in the macro." ,
200190 ),
201191 "update_target" : attr .string (
202192 mandatory = True ,
@@ -303,7 +293,19 @@ def _maybe_file(path):
303293
304294 return None
305295
306- def lock (* , name , srcs , out , args = [], env = None , ** kwargs ):
296+ def lock (
297+ * ,
298+ name ,
299+ args = [],
300+ build_constraints = [],
301+ constraints = [],
302+ env = None ,
303+ generate_hashes = True ,
304+ out ,
305+ python_version = None ,
306+ srcs ,
307+ strip_extras = False ,
308+ ** kwargs ):
307309 """Pin the requirements based on the src files.
308310
309311 This macro creates the following targets:
@@ -318,14 +320,27 @@ def lock(*, name, srcs, out, args = [], env = None, **kwargs):
318320 `native_test` to wrap this target to make a test.
319321
320322 Args:
321- name: The name of the target to run for updating the requirements.
322- srcs: The srcs to use as inputs.
323- out: The output file.
324- args: Extra args to pass to `uv`.
325- env: Passed to `uv`.
326- **kwargs: Extra kwargs passed to the {obj}`py_binary` rule. The most
327- useful `kwarg` is `{obj}`py_binary.python_version`, which allows
328- customizing the python version used for locking.
323+ name: {type}`str` The prefix of all targets created by this macro.
324+ srcs: {type}`list[Label]` The sources that will be used. Add all of the
325+ files that would be passed as srcs to the `uv pip compile` command.
326+ out: {type}`str` The output file relative to the package.
327+ args: {type}`list[str]` The list of args to pass to uv. Note, these are
328+ written into the runnable `name.run` target.
329+ env: {type}`dict[str, str]` the environment variables to set. Note, this
330+ is passed as is and the environment variables are not expanded.
331+ build_constraints: {type}`list[Label]` The list of build constraints to use.
332+ constraints: {type}`list[Label]` The list of constraints files to use.
333+ generate_hashes: {type}`bool` Generate hashes for all of the
334+ requirements. This is a must if you want to use
335+ {attr}`pip.parse.experimental_index_url`. Defaults to `True`.
336+ strip_extras: {type}`bool` whether to strip extras from the output.
337+ Currently `rules_python` requires `--no-strip-extras` to properly
338+ function, but sometimes one may want to not have the extras if you
339+ are compiling the requirements file for using it as a constraints
340+ file. Defaults to `False`.
341+ python_version: {type}`str | None` the python_version to transition to
342+ when locking the requirements.
343+ **kwargs: Extra kwargs passed to the `name.update` {obj}`py_binary` target.
329344 """
330345 update_target = "{}.update" .format (name )
331346 locker_target = "{}.run" .format (name )
@@ -354,6 +369,10 @@ def lock(*, name, srcs, out, args = [], env = None, **kwargs):
354369 ],
355370 args = args ,
356371 env = env ,
372+ generate_hashes = generate_hashes ,
373+ constraints = constraints ,
374+ build_constraints = build_constraints ,
375+ strip_extras = strip_extras ,
357376 target_compatible_with = target_compatible_with ,
358377 )
359378
@@ -388,5 +407,6 @@ def lock(*, name, srcs, out, args = [], env = None, **kwargs):
388407 name = update_target ,
389408 srcs = [update_target + ".py" ],
390409 data = [name ] + ([] if not maybe_out else [maybe_out ]),
410+ python_version = python_version ,
391411 ** kwargs
392412 )
0 commit comments