Is it possible to programmatically call a `goal` w...
# plugins
w
Is it possible to programmatically call a
goal
without being in a
@rule
?
h
what do you mean?
w
Like, if I want to call "help" (for instance), without using
subprocess
or without using the
Get
API, as I'm not inside an
@rule
I guess what I'm wondering is whether the CLI hooks are available from within a python script, without subprocess. Autocomplete is one use-case, but I have a few others in the back of my mind for codegen and testing
f
Is the code that wants to invoke a rule still running inside of Pants?
w
Yes
f
You may want to look at the BSP code. It receives Build Server Protocol requests and then invokes the engine synchronously. https://github.com/pantsbuild/pants/blob/9ca84b5eb6ff66e224ee4f4e0a5a7aec0c922843/src/python/pants/bsp/protocol.py#L155-L165
Also, while you can call the engine to run a goal rule, you could also just request the intermediate level rules that the goal rule would have called.
For example, if you wanted to run
./pants check
, just ask the engine for
CheckResults
.
w
Ahhh, yes yes, the BSP - that's similar to the functionality I'm looking for!
Ah, okay, I didn't know we could synchronously call the engine to run on results, perfect!
In hindsight, I guess i could have spent some time in the unit tests to see how all the rule runners and such work, but the BSP feels more apt
w
the
RuleRunner
is a really good thing to look at, yea
it essentially ends up being a simplified API for the engine (the
Scheduler
class in particular)