I think I've mentioned this in the past, but I've ...
# plugins
a
I think I've mentioned this in the past, but I've got a use-case for a pre/post goal rule. And now I'm thinking of how to implement it in Pants. My thinking was to have the
Goal
class have a mechanism for generating a union subclass e.g.
Copy code
class RunAThingPreTest(Test.PreGoal):
   ...

def rules():
   return [UnionRule(Test.PreGoal, RunAThingPreTest)]
Then something (where?) could do something like
Copy code
pre_goal_results = await MultiGet(
  Get(PreGoalResult, PreGoal, klass(goal_subsystem)
  for klass in UnionMembership[PreGoal]
)

try:
    await do_the_goal()
finally:
    post_goal_results = await MultiGet(
      Get(PostGoalResult, PostGoal, klass(goal_subsystem, pre_results)
      for (klass, pre_result) in zip(UnionMembership[PostGoal], pre_goal_results
    )
How far on/off target am I? for background, some of our tests need to run against code running a PaaS system, so we need to upload the dependencies of the tests that we're running before running the tests.
c
That's an interesting way to hook into goals. Looks feasible to me.
There's one point in the pants runner that invokes the goal rule where it could make sense to also invoke the pre/post union types.
a
is the runner Rust or Python?
c
It's Python. I'll get a link once I'm in front of the computer. But in init/engine_initializer.py is a GraphSession with a run goals method. I think there abouts could make sense.
a
cheers!
c
This segment is running each goal, and here we also have the unions at hand, so is a suitable place to add the pre/post stuff, imo. https://github.com/pantsbuild/pants/blob/main/src/python/pants/init/engine_initializer.py#L137-L142