https://pantsbuild.org/ logo
#development
Title
# development
c

careful-address-89803

09/29/2022, 1:22 AM
hey folks, if I have a rule_helper with a Get, is there a way to multiget multiples of those? I thought I could just asyncio.gather, but there's not current event loop. The real problem I'm trying to solve: I need to factor out a part of a rule so I can use it in 2 places. I can't just create a new rule, since it depends on getting the subsystem, and subsystems are unhashable. So I can create a rule_helper, and that works in the original usage on 1 fieldset. Now I want to use that rule_helper in a place where I have multiple fieldsets. If this were a rule, I would MultiGet that. But it's a rule helper, so I can't just do that. I guess I could have the helper only marshall the arguments to the Get and use the 3arg form in the main function, but that feels clunky. I think that this question is interesting in the general case. I think "extract some code" and "put something in a forloop" are common operations, but I don't have a good intuition for how that's supposed to be done in Pants (esp with their interaction).
1
f

fast-nail-55400

09/29/2022, 2:04 AM
Instead of using a
rule_helper
, just turn the rule helper into a regular
rule
with its own request and result types.
Then the (now) rule can take any subsystems it needs as parameters
And it should work with
MutliGet
c

careful-address-89803

09/29/2022, 2:45 AM
I tried a rule at first, but I was hitting an issue where the subsystem wasn't hashable so
Get
with types the rule could satisfy were hitting TypeError: unhashable type: 'PythonInferSubsystem'
f

fast-nail-55400

09/29/2022, 3:00 AM
You shouldn't need to put a subsystem into the request type. Just make it be a parameter in the rule's signature and the Pants engine will automatically supply it.
Get
instances may appear to be function calls, but they actually aren't given the engine is an expert system. Any parameters in a rule's signature will be resolved by the engine using any existing rules.
1
The request type in a
Get
just happens to be a singleton instance of that type for that particular subgraph and so is the only possible value to be supplied into the rule's parameter of the same type for that particular subgraph.
c

careful-address-89803

09/29/2022, 3:28 AM
Thanks! this works! my mind is blown and my paradigm is shifted
h

hundreds-father-404

09/29/2022, 3:02 PM
it's basically "dependency injection" with types and all statically validated. The rule graph errors are really confusing, but other than that, the engine is incredibly cool magic (the good type) 😄
it's ludicrous how much easier it is for us to make changes with Pants v2 than Pants v1
b

busy-vase-39202

10/03/2022, 4:59 PM
"How the Pants engine works" sounds like it'd make a really cool blog post.