Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Unreleased changes template.
is now the default. Note that running as root may still cause spurious
Bazel cache invalidation
([#1169](https://github.com/bazelbuild/rules_python/issues/1169)).
* (gazelle) Don't collapse depsets to a list or into args when generating the modules mapping file.
Support spilling modules mapping args into a params file.

{#v0-0-0-added}
### Added
Expand Down
15 changes: 11 additions & 4 deletions gazelle/modules_mapping/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,25 @@ module name doesn't match the wheel distribution name.

def _modules_mapping_impl(ctx):
modules_mapping = ctx.actions.declare_file(ctx.attr.modules_mapping_name)
args = ctx.actions.args()
all_wheels = depset(
[whl for whl in ctx.files.wheels],
transitive = [dep[DefaultInfo].files for dep in ctx.attr.wheels] + [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.wheels],
)
args.add("--output_file", modules_mapping.path)

args = ctx.actions.args()

# Spill parameters to a file prefixed with '@'. Note, the '@' prefix is the same
# prefix as used in the `generator.py` in `fromfile_prefix_chars` attribute.
args.use_param_file(param_file_arg = "@%s")
args.set_param_file_format(format = "multiline")
if ctx.attr.include_stub_packages:
args.add("--include_stub_packages")
args.add("--output_file", modules_mapping)
args.add_all("--exclude_patterns", ctx.attr.exclude_patterns)
args.add_all("--wheels", [whl.path for whl in all_wheels.to_list()])
args.add_all("--wheels", all_wheels)

ctx.actions.run(
inputs = all_wheels.to_list(),
inputs = all_wheels,
outputs = [modules_mapping],
executable = ctx.executable._generator,
arguments = [args],
Expand Down
3 changes: 3 additions & 0 deletions gazelle/modules_mapping/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def data_has_purelib_or_platlib(path):
parser = argparse.ArgumentParser(
prog="generator",
description="Generates the modules mapping used by the Gazelle manifest.",
# Automatically read parameters from a file. Note, the '@' is the same prefix
# as set in the 'args.use_param_file' in the bazel rule.
fromfile_prefix_chars="@",
)
parser.add_argument("--output_file", type=str)
parser.add_argument("--include_stub_packages", action="store_true")
Expand Down
Loading