Skip to content

Commit

Permalink
Support using parametrize() with a single value. (pantsbuild#19920)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaos authored Sep 23, 2023
1 parent 1329b43 commit 9abb613
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/python/pants/engine/internals/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@ def _target_parametrizations(
target_type: type[Target],
union_membership: UnionMembership,
) -> _TargetParametrization:
first, *rest = Parametrize.expand(address, target_adaptor.kwargs)
if rest:
expanded_parametrizations = tuple(Parametrize.expand(address, target_adaptor.kwargs))
first_address, first_kwargs = expanded_parametrizations[0]
if first_address is not address:
# The target was parametrized, and so the original Target does not exist.
generated = FrozenDict(
(
Expand All @@ -380,7 +381,7 @@ def _target_parametrizations(
description_of_origin=target_adaptor.description_of_origin,
),
)
for parameterized_address, parameterized_fields in (first, *rest)
for parameterized_address, parameterized_fields in expanded_parametrizations
)
return _TargetParametrization(None, generated)
else:
Expand Down
19 changes: 19 additions & 0 deletions src/python/pants/engine/internals/graph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,25 @@ def test_parametrize_16910(generated_targets_rule_runner: RuleRunner, field_cont
)


def test_parametrize_single_value_16978(generated_targets_rule_runner: RuleRunner) -> None:
assert_generated(
generated_targets_rule_runner,
Address("demo"),
"generated(resolve=parametrize('demo'), source='f1.ext')",
["f1.ext"],
{
MockGeneratedTarget(
{SingleSourceField.alias: "f1.ext", ResolveField.alias: "demo"},
Address("demo", parameters={"resolve": "demo"}),
residence_dir="demo",
),
},
expected_dependencies={
"demo@resolve=demo": set(),
},
)


# -----------------------------------------------------------------------------------------------
# Test `SourcesField`. Also see `engine/target_test.py`.
# -----------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 9abb613

Please sign in to comment.