Core: Fix __defaults__ to also apply for generated file targets.#20649
Merged
Core: Fix __defaults__ to also apply for generated file targets.#20649
__defaults__ to also apply for generated file targets.#20649Conversation
kaos
commented
Mar 7, 2024
| assert target_adaptor.kwargs["tags"] == ["24"] | ||
|
|
||
|
|
||
| def test_generated_target_defaults(target_adaptor_rule_runner: RuleRunner) -> None: |
Member
Author
There was a problem hiding this comment.
This is implemented in graph.py, but the __defaults__ feature, as used in the BUILD files, are otherwise tested here so I felt this was the logical place for this test but could be convinced to move it to graph_test.py.
Comment on lines
+266
to
+270
| # Pre-load field values from defaults for the target type being generated. | ||
| if hasattr(target_type, "generated_target_cls"): | ||
| family = await Get(AddressFamily, AddressFamilyDir(address.spec_path)) | ||
| template_fields = dict(family.defaults.get(target_type.generated_target_cls.alias, {})) | ||
| else: |
Member
Author
There was a problem hiding this comment.
This is the only new in this function. It had to move before the @rule method calling it.
Comment on lines
-438
to
-439
| # Split out the `propagated_fields` before construction. | ||
| template_fields = {} |
Member
Author
There was a problem hiding this comment.
This part is the changed bit in the moved function, the rest is unchanged.
benjyw
approved these changes
Mar 18, 2024
Contributor
benjyw
left a comment
There was a problem hiding this comment.
LGTM!
And also serves as a reminder that our target mechanisms are much too complicated... :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When providing defaults for a target generator, such as
python_sources, the defaults now apply to the generatedpython_sourcetargets.Closes #20595
Plugin API note:
This works for all
TargetGeneratorclasses that declares the generated target type using thegenerated_target_clsclass var.pants/src/python/pants/engine/target.py
Lines 1017 to 1018 in d2af94c