Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 351fc14

Browse files
mattemdcode
authored andcommitted
fix: spill module mapping args to a file (bazel-contrib#2644)
Calls to the modules mapping rule contains very long command line args due to the use of the full `wheels` parameter. This change adds support for spilling the args into a file as needed. In addition, it improves the performance of the `modules_mapping` rule: * Remove the calls `to_list` that are unnecessary on the depset. * Remove the iteration over the depset when passing to `args`, and other calls to `.path`, and instead let args do this lazily.
1 parent a5c1136 commit 351fc14

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Unreleased changes template.
6363
is now the default. Note that running as root may still cause spurious
6464
Bazel cache invalidation
6565
([#1169](https://github.com/bazelbuild/rules_python/issues/1169)).
66+
* (gazelle) Don't collapse depsets to a list or into args when generating the modules mapping file.
67+
Support spilling modules mapping args into a params file.
6668
* (uv) Adds support for versions 0.5.26 through 0.6.3 and a maintenance script
6769
for future releases. Fixed in [#2647](https://github.com/bazelbuild/rules_python/pull/2647).
6870

gazelle/modules_mapping/def.bzl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,25 @@ module name doesn't match the wheel distribution name.
2525

2626
def _modules_mapping_impl(ctx):
2727
modules_mapping = ctx.actions.declare_file(ctx.attr.modules_mapping_name)
28-
args = ctx.actions.args()
2928
all_wheels = depset(
3029
[whl for whl in ctx.files.wheels],
3130
transitive = [dep[DefaultInfo].files for dep in ctx.attr.wheels] + [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.wheels],
3231
)
33-
args.add("--output_file", modules_mapping.path)
32+
33+
args = ctx.actions.args()
34+
35+
# Spill parameters to a file prefixed with '@'. Note, the '@' prefix is the same
36+
# prefix as used in the `generator.py` in `fromfile_prefix_chars` attribute.
37+
args.use_param_file(param_file_arg = "@%s")
38+
args.set_param_file_format(format = "multiline")
3439
if ctx.attr.include_stub_packages:
3540
args.add("--include_stub_packages")
41+
args.add("--output_file", modules_mapping)
3642
args.add_all("--exclude_patterns", ctx.attr.exclude_patterns)
37-
args.add_all("--wheels", [whl.path for whl in all_wheels.to_list()])
43+
args.add_all("--wheels", all_wheels)
44+
3845
ctx.actions.run(
39-
inputs = all_wheels.to_list(),
46+
inputs = all_wheels,
4047
outputs = [modules_mapping],
4148
executable = ctx.executable._generator,
4249
arguments = [args],

gazelle/modules_mapping/generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def data_has_purelib_or_platlib(path):
152152
parser = argparse.ArgumentParser(
153153
prog="generator",
154154
description="Generates the modules mapping used by the Gazelle manifest.",
155+
# Automatically read parameters from a file. Note, the '@' is the same prefix
156+
# as set in the 'args.use_param_file' in the bazel rule.
157+
fromfile_prefix_chars="@",
155158
)
156159
parser.add_argument("--output_file", type=str)
157160
parser.add_argument("--include_stub_packages", action="store_true")

0 commit comments

Comments
 (0)