fresh-cat-90827
12/01/2022, 5:38 PMStringField. I know I can use compute_value to set a value for some field and it works. Now, if I want to set a field value based on the value that was passed in the BUILD file in a target declaration to another field, is using rules my only option or is there some other clever way to do it?fresh-cat-90827
12/01/2022, 5:39 PMmytarget(foo=10)
when inspecting the object I want the mytarget after creation to have .bar = foo + 5hundreds-father-404
12/01/2022, 5:39 PMcompute_based_on_foo(other_field: OtherField)fast-nail-55400
12/01/2022, 5:50 PMfast-nail-55400
12/01/2022, 5:51 PMBuildGoPackageRequest which has no reference to targets whatsoever.fast-nail-55400
12/01/2022, 5:52 PMcurved-television-6568
12/01/2022, 6:53 PMfresh-cat-90827
12/01/2022, 11:33 PM./pants peek project: and can see
custom_target(source="data.txt")
[
{
"address": "project:project",
"target_type": "custom_target",
"custom_field": null,
"dependencies": [],
"dependencies_raw": null,
"description": null,
"source_raw": "data.txt",
"sources": [
"project/data.txt"
],
"tags": null
}
]
Now, what's the minimal thing I need to do to set the custom_field based on the value provided in source_raw? Or let's start with just accessing existing fields.
@rule
async def example(custom_target: CustomTarget) -> None:
<http://logger.info|logger.info>("Logged!")
<http://logger.info|logger.info>(custom_target.alias)
return
def rules():
return (
*collect_rules(),
)
doesn't seem to be enough.
the Pants engine determines when rules are used and calls the rules for you.Says the docs; how can I find out what kind of inputs and outputs do I need to provide to the rule so that Pants enginer would determine that it needs to be run?
hundreds-father-404
12/01/2022, 11:50 PMMyResult. It's fine if it's an empty class. All the engine cares about is it's a distinct type (class)
Then, something needs to request MyResult so that it gets executed, typically by using Get(MyResult, CustomTarget) inside something like a @goal_rule or one of our plugin hooks that get invoked by the builtin goal rulesfresh-cat-90827
12/01/2022, 11:55 PMour plugin hooks that get invoked by the builtin goal ruleshm, if I don't have a new goal, just want to populate fields for a target, where I can do
Get(MyResult, CustomTarget) so that the field is visible, e.g. when doing ./pants peek?hundreds-father-404
12/01/2022, 11:56 PM./pants peek?fresh-cat-90827
12/01/2022, 11:56 PMhundreds-father-404
12/01/2022, 11:58 PM./pants peek for how to evaulate your field
Instead, I recommend following the guide on Goal Rules and creating a dummy goal rulefresh-cat-90827
12/02/2022, 12:05 AM./pants my-dummy-goal target: ?hundreds-father-404
12/02/2022, 12:06 AM./pants my-dummy-goal simply, and hardcode what target to run on inside the rule bodycurved-television-6568
12/02/2022, 12:17 AMpeek invocation.. like registering a custom ValidateDependenciesRequest fresh-cat-90827
12/02/2022, 5:53 PMto trigger custom rules from a@curved-television-6568 If you have an example, please share, if not, not a problem, I'll get to this at some point once I'm past the basic stuff 😄invocation.. like registering a custompeekValidateDependenciesRequestgoalrule as one
curved-television-6568
12/02/2022, 6:49 PMpeek goal run when registered with https://github.com/pantsbuild/pants/blob/47a8d60f419336c0b71725a7e33d343d3ad9bfdb/src/python/pants/backend/visibility/rules.py#L65