Hi all, maybe this is trivial but I could not find...
# general
a
Hi all, maybe this is trivial but I could not find a way yet. How can I generate a requirements.txt for a project? As far as I know
peek
cannot get 3rdparty dependencies, and with
dependencies
I don't get the versions. Any suggestion?
👀 1
b
Are you using a lockfile? If so, one way to handle it is using the
pex
tool directly: install it, and then run like
PEX_SCRIPT=pex3 pex lock export --format pip ...
I think. You may have to edit the lockfile to make it valid JSON; remove the
//
comments in the header.
a
Yes, I’m using a lockfile. However, my goal is to generate the requirements.txt from the context of a subproject. The only way I see at the moment would be to run a pip freeze from within the venv of a pex, but I hoped there was an easier mode. Otherwise I should get the list of 3rd party dependencies and then find the versions in the lockfile…
c
If the data from peek is an alternative, you can get it in a roundabout way (three steps):
Copy code
pants dependencies --transitive some/target:name > deps
pants --spec-files=deps list --filter-target-type=python_requirement > reqs
pants --spec-files=reqs peek --exclude-defaults | jq -r '.[]|.requirements[]'
This will give you the requirement, as provided in the resolves requirements.txt, if you're using that..
it will not include transitive deps from 3rd party libs though..
a
Thanks, I will try that out. Maybe transitive 3rd party libs are not very needed because they would be retrieved anyways if installed. However, my understanding is that I cannot get exact version as in the global lockfile. Am I right? Probably the only way is to pass through a PEX…
Or actually use a mix of requirements retrieval (as a list) and then matching the exact version from the lockfile.
c
yea, if the requirement is not pinned, then the exact version would only be available from the lockfile.
a
Ok I’ll try to find a way. Is it in your opinion something that a plugin could do more conveniently, by using Pants API?
c
not really.. there's not many rules to work with lockfile content for plugins to leverage atm.
ah.. there could be some rules however that determines the input requirements for building a pex for a particular target tho.. that could be useful from a plugin.. but it's not very intuitive to use, I think.. so not really convenient in the end after all.
a
Alright, maybe I'll go though a plugin that calls shell commands or something similar....