Outside of the `export` goal, if I want to create ...
# general
p
Outside of the
export
goal, if I want to create a virtualenv with wheels built by pants, but use the versions locked in the pex lockfile, how might I do that? I assume there's something in PEX to do that? I couldn't find anything about lockfiles in the pex docs.
h
Is this for use in a plugin?
e
If you 1st strip the damn headers Pants adds to the lockfile, which make it invalid JSON, you can then:
Copy code
PEX_TOOLS=1 pex --python /use/exactly/this/python --lock the.lock [optional requirements strings to subset the lock; otherwise you get everything] --include-tools -- venv create/it/right/here
@proud-dentist-22844 Pex docs should basically be considered its CLI --help until I get time to devote later this year.
👍 1
p
Is this for use in a plugin?
Not necessarily. I'm thinking of a couple of different things. • When using the wheels as library (a key thing I want to allow by publishing to pypi), I want the requirements to be very broad. • When installing the wheels together as an application, I want all the requirements to be installed using the precise versions listed in the lockfile. When installing the application in a virtualenv, I can't use: • Export: because I can't specify a path in /opt, it has to be under the workspace directory. • Just install the wheels with pip, because then pip won't use the already locked deps.
e
Aha. Just make a
pex_binary(... include_tools=True)
target and
pants package
that.
p
I will try running your sample via PEX. Thank you John
e
Then run
PEX_TOOLS=1 my.pex venv right/here
No need to muck with lockfiles that way, they'll get used automatically.
p
Huh. I hadn't considered using a pex_binary. I'll have to play with that
e
You don't need the second manual step if you only care about a venv but not where it lives.
In that case instead of
include_tools=True
use
execution_mode="venv"
and then you can just run the PEX binary directly.
p
Yes, for backwards compatibility I have to care about the venv at a particular location.
e
It will create a venv transparently on 1st run.
Gotcha.
p
Eventually, I hope to remove that assumption about the path.
e
Again, tack on
--help
after the
venv
tool subcommand to learn the options.
p
Will do. Thank you!