Hey, everyone! I’m trying to export a requirements...
# general
b
Hey, everyone! I’m trying to export a requirements.txt with all locked third-party dependencies of a specific
pex_binary
target. Do you know whether pants or pex offers a way to do that? I understand
pex3 lock export
can do that given an existing lockfile, but in this case I’d like to have that not for the global resolve, but for a subset of dependencies of a specific target.
1
b
You might try PEX_TOOLS=1 <PEX> --help To see what all is available, tooling wise. There's a field on the pex binary target to include tools
b
Thanks @bitter-ability-32190! I glanced through the docs of the existing commands for
PEX_TOOLS
and it seems that none of the commands directly supports that. The workaround I could find is to use
venv
to create a virtual environment and then use
venv/bin/pip freeze
to generate the list of requirements. Any thoughts on this approach?
b
It'd work, but that seems expensive. Maybe scrape PEX-INFO?
e
PEX_TOOLS was the right idea, but you missed some tools:
Copy code
$ pex boto3 --include-tools -o boto3.pex
$ PEX_TOOLS=1 ./boto3.pex repository info -v | jq -r '.project_name + "==" + .version'
boto3==1.28.9
botocore==1.31.9
jmespath==1.0.1
python-dateutil==2.8.2
six==1.16.0
urllib3==1.26.16
s3transfer==0.6.1
👍 1
👆 1
Maybe better depending on your needs - but Pants gets in the way by adding an invalid header to the lock file:
Copy code
# This is how Pants generates the lockfile:
$ pex3 lock create --style universal --resolver-version pip-2020-resolver --pip-version latest --target-system linux --target-system mac "boto3[security]" -o lock.json --indent 2

# This is how Pants generates your PEX from the lockfile:
$ pex --lock lock.json boto3 -o boto3.pex

# You need to strip the header comments from the Pants generated lock file; then:
$ pex3 lock export-subset --lock lock.json "$(pex-tools boto3.pex info | jq -r ".requirements[]")"
boto3==1.28.9 \
  --hash=sha256:01f078047eb4d238c6b9c6cc623f2af33b4ae67980c5326691e35cb5493ff6c7 \
  --hash=sha256:4cc0c6005be910e52077227e670930ab55a41ba86cdb6d1c052571d08cd4d32c
botocore==1.31.9 \
  --hash=sha256:e56ccd3536a90094ea5b176b5dd33bfe4f049efdf71af468ea1661bd424c787d \
  --hash=sha256:bd849d3ac95f1781385ed831d753a04a3ec870a59d6598175aaedd71dc2baf5f
jmespath==1.0.1 \
  --hash=sha256:02e2e4cc71b5bcab88332eebf907519190dd9e6e82107fa7f83b1003a6252980 \
  --hash=sha256:90261b206d6defd58fdd5e85f478bf633a2901798906be2ad389150c5c60edbe
s3transfer==0.6.1 \
  --hash=sha256:3c0da2d074bf35d6870ef157158641178a4204a6e689e82546083e31e0311346 \
  --hash=sha256:640bb492711f4c0c0905e1f62b6aaeb771881935ad27884852411f8e9cacbca9
python-dateutil==2.8.2 \
  --hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9 \
  --hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86
urllib3==1.26.16 \
  --hash=sha256:8d36afa7616d8ab714608411b4a3b13e58f463aee519024578e062e141dce20f \
  --hash=sha256:8f135f6502756bde6b2a9b28989df5fbe87c9970cecaa69041edcce7f0589b14
six==1.16.0 \
  --hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254 \
  --hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926
b
that’s cool! Thanks @enough-analyst-54434! The
export-subset
works perfectly for my use cass