Is there a way to list/filter all targets that wou...
# general
b
Is there a way to list/filter all targets that would be used by a goal? For example, I want to know what would happen if I ran
pants package ::
-- there are many package-able target types and I don't know them all ahead of time
looking through source code PackageFieldSet looks close to what I want but I don't see how to use this in a list/filter/etc command on the command line
w
There's kinda an inverse of this functionality, which tells you some of the goals that can be run on a target using pants peek
Copy code
% pants peek ::
...
{
    "address": "pants-plugins/experimental/swift/util_rules/compile.py",
...
    "goals": [
      "run"
    ],
Now, I could have sworn I wrote this while seeing the functionality you asked for. Specifically dealing with the
filter
https://www.pantsbuild.org/2.21/docs/using-pants/advanced-target-selection#filter-options
Or maybe it was something like this?
Copy code
oss/pants-plugins % pants list package 
22:45:31.84 [WARN] No targets were matched in goal `list`.
22:45:31.84 [WARN] No files or targets specified. The `package` goal works with these target types:

  * archive
  * pex_binary
  * python_distribution
  * scie_binary

Please specify relevant file and/or target arguments. Run `pants --filter-target-type=archive,pex_binary,python_distribution,scie_binary list ::` to find all applicable targets in your project, or run `pants --filter-target-type=archive,pex_binary,python_distribution,scie_binary filedeps ::` to find all applicable files.
Is that of any use? Or are you looking for a variant of the above? Like, peek with some
jq
at the end?
b
oh yeah, I suppose that'll work. (I could even
sed
out that part of the output, which will depend on the backends enabled in my pantsverse)
thanks!
w
Can you describe what the call you're looking for woudl look like, with what output? Just trying to make sure I understand your question
b
well I'm trying to troubleshoot why my
pants package ::
is failing in github actions CI (I suspect OOM), so I wanted to get a list of what all it's trying to do and see if I can pare that down to a smaller but useful set of targets
I also thought it could be useful for the github action to print out what it was going to try to do before doing it
in my case
pants --filter-target-type=archive,docker_image,pex_binary,python_aws_lambda_function,python_aws_lambda_layer,python_distribution list ::
gives the output I want
w
👍 I want to say that what you're suggesting should/must be possible first-party somehow - but it's been a long time since I've needed to do similar If not, we should probably have some sort of
--filter-goal
hook, as that seems pretty useful
b
helpful (lucky?) that bare
pants package
prints out the command I'm looking for. But only once? if I re-run
pants package
it no longer prints the warning
w
Yeah, this is exactly the functionality I ran into - and I thought we had some way to trigger it
b
the FieldSet stuff looks like it would be an easy plugin to write
I imagine that's how the warning is getting generated
w
For posterity, maybe something like this?
Copy code
pants peek :: | jq  '.[] | select(.goals | index("package")) | .address'
Copy code
oss/pants-plugins % pants peek :: | jq  '.[] | select(.goals | index("package")) | .address' 
"examples/python/core:core-dist"
"examples/python/hellofastapi:hellofastapi-pex"
"examples/python/hellofastapi:hellofastapi-scie"
"examples/python/hellofib:hellofib-dist"
"examples/python/hellofib:hellofib-mypyc"
"examples/python/hellofib:hellofib-pex"
"examples/python/hellofib:hellofib-scie"
"examples/python/hellokivy:hellokivy-pex"
"examples/python/hellokivy:hellokivy-scie"
"examples/python/hellonumpy:hellonumpy-pex"
"examples/python/hellonumpy:hellonumpy-scie"
"examples/python/hellotyper:hellotyper-pex"
"examples/python/hellotyper:hellotyper-scie"
"examples/python/hellowebview:hellowebview-pex"
"examples/python/hellowebview:hellowebview-scie"
"examples/python/helloworld:helloworld-pex"
"examples/python/helloworld:helloworld-scie"
"pants-plugins/experimental/scie:scie-dist"
b
that doesn't seem to get all of them for me. e.g. my docker_image targets don't specify goals
w
Oh, well, that's interesting - might be a bug in the implementation
w
I ran into the same use case and solved it with a CLI alias of
—-publishable
, mapped to a hardcoded list of our publishable types, which are limited. We also had to add a
skip-publish
tag to that alias - to exclude some intermediate docker images that we don’t ever want to publish. There’s a skip publish param on the
docker_image
, which prevents publish but didn’t affect the alias. We then effectively use
pants list —publishable
, as a
pants package
preview in CI
🎉 1
w
I do think that, if we don't have this functionality somewhere (I could have sworn we did), it should be first-party functionality. Seems natural to have somewhere
👍 1
b
Agree, it feels like a gap. Being able to filter on specific target types is great (nit: are these really "goal" types, not "target" types?). The same way we can say
pants test ::
makes it surprising not to be able to query "what are all the
test
-able targets"
w
Agreed, and year, goal oriented is how I think about this and how we use it
c
Would you mind writing an issue that captures that?