Hi, is there a way to get pants to output 3rd part...
# general
c
Hi, is there a way to get pants to output 3rd party requirements for a target in a
requirements.txt
format? It looks like
./pants dependencies
used to do this with
--type=3rdparty
(see

https://www.youtube.com/watch?v=IpEv5cWfyko&t=120s&ab_channel=PantsBuild

) but that option seems to have disappeared.
From the docs, it looks like it was deprecated in 2.8: https://www.pantsbuild.org/v2.8/docs/reference-dependencies Is the recommended way still something like this?
Copy code
./pants dependencies --dependencies-transitive <target> | xargs ./pants peek --filter-target-type=python_requirement | jq -r '.[]["requirements"][]'
h
Something like that, yeah... The old way of doing this was perhaps more convenient for this specific use-case, but very ad-hoc
c
Thanks - I don't mind wrapping the above in a script or something, but I'd have preferred to avoid doing that if Pants supported it directly.
Is there anywhere in the docs that includes (or could include) recipes like this? If I hadn't come across that youtube video and then searched through the old versions of the docs, I'm not sure I'd have come up with that myself.
h
There are various examples here that we could add to: https://www.pantsbuild.org/docs/project-introspection
(under "Piping other introspection commands into ./pants peek")
So yeah, adding this to one of those would be great! The docs are generated from sources in the repo, if you want to take a crack at it
c
Ah that must be where that youtube video came from! (A colleague sent me the link - presumably he got it from that page.)
And yeah happy to have a rummage around the repo and maybe submit a PR once I've had a read of this!
f
thanks, Alex, this is great. I was exploring this myself in https://pantsbuild.slack.com/archives/C046T6T9U/p1671482123490549 a couple weeks ago.
c
for posterity, I ended up with
Copy code
pants dependencies --dependencies-transitive <target> | tr '\n' '\0' | xargs -0 pants peek --filter-target-type=python_requirement | jq -r '.[]["requirements"][]' | sort -u
where •
tr '\n' '\0'
and
xargs -0
account for target names that contain characters that
xargs
would normally split on (eg spaces/tabs) •
sort -u
accounts for cases where
xargs
invokes
pants peek
more than once, and combines the output. (This happens in cases where
pants dependencies
outputs many targets, eg if you pass in
::
.)
I did also say I'd submit a documentation PR, and I will try to do that some time this week
🙏 1