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

fresh-cat-90827

12/19/2022, 8:12 PM
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

fast-nail-55400

12/19/2022, 8:16 PM
What's the context?
Are you trying to modify the behavior of the goal from the plugin?
f

fresh-cat-90827

12/19/2022, 8:18 PM
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

fast-nail-55400

12/19/2022, 8:20 PM
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

fresh-cat-90827

12/19/2022, 8:21 PM
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

fast-nail-55400

12/19/2022, 8:22 PM
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

fresh-cat-90827

12/19/2022, 8:24 PM
so my only option then is to extend the Pants core 😉
f

fast-nail-55400

12/19/2022, 8:25 PM
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

fresh-cat-90827

12/19/2022, 8:26 PM
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

fast-nail-55400

12/19/2022, 8:27 PM
hmm any reason why it was deprecated?
no objection from me if it were resurrected
f

fresh-cat-90827

12/19/2022, 8:32 PM
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

fast-nail-55400

12/19/2022, 8:34 PM
or invent that more robust way :)
🙌 1
b

bitter-ability-32190

12/19/2022, 8:43 PM
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
2 Views