is it possible to add a new option for an existing...
# development
is it possible to add a new option for an existing Pants goal using the plugin API? E.g.
./pants dependencies --my-flag
. The docs show how to add an option for a new subsystem, but I wonder if one can hook up into an existing goal?
What's the context?
Are you trying to modify the behavior of the goal from the plugin?
yes, exactly, sorry if that was unclear.
./pants dependencies
would show all dependencies, but I am looking into adding an option defined in my in-repo plugin to avoid doing
./pants dependencies | xargs command ... | xargs command
. Using
won't work as it involves chaining multiple commands. I'd like instead to do this in Python before emitting output from the very first command.
not sure how you would an option to an existing subsystem. I first have a question about how does your plugin even change the semantics/code of a core goal?
(without somehow intercepting and overriding it)
I'd like to filter the output produced by the
goal, so the option wouldn't interfere with the semantics at all. Essentially the last step filtering before returning
I was hoping for being able to somehow register the rule filtering the dependencies returned, similar to what we do with UnionRule thingy, but I'd also get if what I want is not possible 🙂
I don't think the current rules allow you to override an existing goal in that manner.
the engine asks the rules for the goal's result type and only one rule (the
for that particular goal) will provide that result type
two rules doing that would be a rule graph error
so my only option then is to extend the Pants core 😉
or write a new goal (e.g.,
) and then either copy/paste the impl of
goal or call its impl (which now keeps its same type) but pass in a
wrapper that does the filtering
or yeah, extend the Pants core
it was deprecated a year ago or something, but I find this to be very helpful as it adds clarity and one doesn't need to do the additional grep / filtering
hmm any reason why it was deprecated?
no objection from me if it were resurrected
from type --dependencies-type=<DependencyType> PANTS_DEPENDENCIES_TYPE one of: source, 3rdparty, source-and-3rdparty default: source Deprecated, will be removed in version: 2.9.0.dev0. This option is misleading and not very useful. In the future there will be a more robust way of querying and filtering dependencies. Meanwhile you can get the list of requirement strings for a set of targets using something like ./pants dependencies :: | xargs ./pants filter --target-type=python_requirement | xargs ./pants peek | jq -r '.[][&quot;requirements&quot;][]'
I'll ask in the #general if there's a more robust way now 🙂
or invent that more robust way :)
🙌 1
You CAN add an option to other goals' subsystems, but that's really only useful in your rules, which in this case wouldn't be considered
👍 1