*Generating `requirements.txt` per Pants target.* ...
# general
m
Generating
requirements.txt
per Pants target.
Hello team, I am seeking advice. I would like to generate a
requirements.txt
for a Pants target so that in the actual remote execution environment (Docker) I can do
pip -r requirements.txt
. What is the best way to achieve this? Couple of approaches I can think of: 1. Use
shell_command
and invoke
pants dependencies
. I am not sure whether I can invoke a Pants command within a Pants command. 2. Write a plugin that somehow hook into Pants dependency results? I think I know how to write such plugin for Bazel / Blaze, but not sure how to approach this in Pants. Could you give me some advice on what is best practice? I did search on Slack but it seems no one has done this before? PS. Before you think I am doing this all wrong, I did do a multi-platform PEX previously, but the size of the PEX is enormous as it requires all the ML stack. Another reality is that ML researchers are not used to PEX, and it seems they are would prefer the traditional venv / Docker debug path...
b
Hello! Just on your P.S., are you aware that one can use PEX to construct a normal venv? So use pex as an intermediate packaging artifact and splat that into the actual docker image: https://docs.pex-tool.org/recipes.html#pex-app-in-a-container https://www.pantsbuild.org/blog/2022/08/02/optimizing-python-docker-deploys-using-pants (There's a few ways one can make these pexes easier to work with too, e.g.
layout="packed"
and separating third-party and first-party code into separate pexes. The second link there goes into more detail.) Re the approaches: 1. recursive pants invocations can work, although will be a bit fiddly and slow, so generally not recommended 2. yeah, a plugin might work: https://www.pantsbuild.org/stable/docs/writing-plugins/overview has the docs about these, although might be an uphill battle
m
Thank you so much for the kind answers... Yeah, I did read the docs on plugins but it did look like it will be an uphill battle. I think your pex idea is great. That is such a good advice. I will give that a go. Thank you!