is it possible to add a new option for an existing...
# development
f
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?
f
What's the context?
Are you trying to modify the behavior of the goal from the plugin?
f
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
cli.alias
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.
f
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)
f
I'd like to filter the output produced by the
dependencies
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 🙂
f
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
@goal_rule
for that particular goal) will provide that result type
1
two rules doing that would be a rule graph error
f
so my only option then is to extend the Pants core 😉
f
or write a new goal (e.g.,
my-deps
) and then either copy/paste the impl of
dependencies
goal or call its impl (which now keeps its same type) but pass in a
Console
wrapper that does the filtering
1
or yeah, extend the Pants core
f
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
f
hmm any reason why it was deprecated?
no objection from me if it were resurrected
f
from https://www.pantsbuild.org/v2.8/docs/reference-dependencies#section-type 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;][]' https://github.com/pantsbuild/pants/pull/13431/files
I'll ask in the #general if there's a more robust way now 🙂
f
or invent that more robust way :)
🙌 1
b
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