many-night-18726
08/18/2024, 5:17 PMpants export ...
and stored in dist/export/python/virtualenvs/...
? I’d like to make the export of the venv a dependancy of the creation of the docker image, which needs to copy the python interpreter.
I was thinking about doing something like this, but pants can’t run another pants command :
run_shell_command(
name="generate_venv",
command="pants export --export-resolve='[\"python-default\"]'",
workdir="/",
)
docker_image(
name="docker_im",
dependencies=["src/repo:generate_venv"],
)
$ pants run src/repo:generate_venv
Another pants invocation is running. Will wait up to 60.0 seconds for it to finish before giving up.
billions-toddler-52776
08/18/2024, 6:53 PMsquare-psychiatrist-19087
08/18/2024, 9:05 PMhappy-kitchen-89482
08/19/2024, 2:43 AMhappy-kitchen-89482
08/19/2024, 2:43 AMexport
is specifically for humans/developers to use, e.g., so there’s something to point an IDE atmany-night-18726
08/19/2024, 7:09 AMpip install
for example, and not have to re-export everytime i want to use a new package. I don’t know if PEX files are flexible enough for thismany-night-18726
08/19/2024, 7:11 AMsquare-psychiatrist-19087
08/19/2024, 8:13 AMsquare-psychiatrist-19087
08/19/2024, 8:15 AMmany-night-18726
08/19/2024, 3:29 PMpants export
, you get a full usable venv. I tried to use a PEX binary target to export my lockfile to a venv the same way as pants export, but i can’t manage to get it the same way
pex_binary(
name="venv",
layout='loose',
dependencies=[":python_requirements"],
resolve="python-default",
venv_site_packages_copies=True,
)
This is what i get with pex_binary :
$ tree -a -L 3 dist/src.ml/ml-venv.pex/
dist/src.ml/ml-venv.pex/
├── .bootstrap
│ └── pex
│ ├── argparse.py
│ ├── asserts.py
│ ├── atomic_directory.py
│ ├── attrs.py
│ ├── auth.py
│ ├── bootstrap.py
│ ├── commands
│ ├── common.py
│ ├── compatibility.py
│ ├── compiler.py
│ ├── dependency_manager.py
│ ├── dist_metadata.py
│ ├── enum.py
│ ├── environment.py
│ ├── exclude_configuration.py
│ ├── executor.py
│ ├── fetcher.py
│ ├── finders.py
│ ├── fingerprinted_distribution.py
│ ├── hashing.py
│ ├── inherit_path.py
│ ├── __init__.py
│ ├── interpreter_constraints.py
│ ├── interpreter.py
│ ├── jobs.py
│ ├── layout.py
│ ├── __main__.py
│ ├── network_configuration.py
│ ├── orderedset.py
│ ├── pep_376.py
│ ├── pep_425.py
│ ├── pep_427.py
│ ├── pep_440.py
│ ├── pep_503.py
│ ├── pep_508.py
│ ├── pex_bootstrapper.py
│ ├── pex_builder.py
│ ├── pex_info.py
│ ├── pex.py
│ ├── pex_warnings.py
│ ├── platforms.py
│ ├── pth.py
│ ├── pyenv.py
│ ├── rank.py
│ ├── requirements.py
│ ├── resolver.py
│ ├── result.py
│ ├── sh_boot.py
│ ├── sorted_tuple.py
│ ├── targets.py
│ ├── third_party
│ ├── tools
│ ├── tracer.py
│ ├── typing.py
│ ├── util.py
│ ├── variables.py
│ ├── vendor
│ ├── venv
│ ├── version.py
│ ├── wheel.py
│ └── ziputils.py
├── .deps
│ ├── iniconfig-2.0.0-py3-none-any.whl
│ │ ├── iniconfig
│ │ ├── iniconfig-2.0.0.dist-info
│ │ └── .layout.json
│ ├── numpy-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
│ │ ├── .layout.json
│ │ ├── numpy
│ │ ├── numpy-2.0.1.dist-info
│ │ ├── numpy.libs
│ │ └── .prefix
│ ├── packaging-24.1-py3-none-any.whl
│ │ ├── .layout.json
│ │ ├── packaging
│ │ └── packaging-24.1.dist-info
│ ├── pluggy-1.5.0-py3-none-any.whl
│ │ ├── .layout.json
│ │ ├── pluggy
│ │ └── pluggy-1.5.0.dist-info
│ └── pytest-8.3.2-py3-none-any.whl
│ ├── .layout.json
│ ├── .prefix
│ ├── py.py
│ ├── _pytest
│ ├── pytest
│ └── pytest-8.3.2.dist-info
├── __main__.py
├── __pex__
│ └── __init__.py
└── PEX-INFO
And this is what i expected to get instead, a virtual environment file structure :
$ tree -a -L 2 dist/export/python/virtualenvs/python-default/3.12.4/
dist/export/python/virtualenvs/python-default/3.12.4/
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── Activate.ps1
│ ├── dotenv
│ ├── editorconfig
│ ├── f2py
│ ├── faker
│ ├── ff
│ ├── flask
│ ├── fonttools
│ ├── functions-framework
│ ├── functions_framework
│ ├── functions-framework-python
│ ├── functions_framework_python
│ ├── gunicorn
│ ├── httpx
│ ├── js-beautify
│ ├── litestar
│ ├── markdown-it
│ ├── normalizer
│ ├── pip
│ ├── pip3
│ ├── pip3.12
│ ├── pyftmerge
│ ├── pyftsubset
│ ├── pygmentize
│ ├── pyrsa-decrypt
│ ├── pyrsa-encrypt
│ ├── pyrsa-keygen
│ ├── pyrsa-priv2pub
│ ├── pyrsa-sign
│ ├── pyrsa-verify
│ ├── py.test
│ ├── pytest
│ ├── python -> python3.12
│ ├── python3 -> python3.12
│ ├── python3.12 -> /home/gregoire/.asdf/installs/python/3.12.4/bin/python3.12
│ ├── rich-click
│ ├── tb-gcp-uploader
│ ├── tqdm
│ ├── ttx
│ ├── uvicorn
│ ├── watchfiles
│ └── watchmedo
├── include
│ └── python3.12
├── lib
│ └── python3.12
├── lib64 -> lib
├── __main__.py
├── pex -> __main__.py
├── PEX-INFO
├── .pex-venv-scope
├── pyvenv.cfg
└── share
└── man
square-psychiatrist-19087
08/19/2024, 3:30 PMmany-night-18726
08/19/2024, 3:31 PMsquare-psychiatrist-19087
08/19/2024, 3:31 PM"RUN PEX_TOOLS=1 /usr/local/bin/python3.10 /binary.pex venv --scope=deps --compile /bin/app",
many-night-18726
08/19/2024, 3:32 PMsquare-psychiatrist-19087
08/19/2024, 3:32 PMmany-night-18726
08/19/2024, 3:43 PMsquare-psychiatrist-19087
08/19/2024, 3:43 PMmany-night-18726
08/19/2024, 3:44 PMsquare-psychiatrist-19087
08/19/2024, 3:45 PMsquare-psychiatrist-19087
08/19/2024, 3:45 PMpants export
directlymany-night-18726
08/19/2024, 3:59 PMsquare-psychiatrist-19087
08/19/2024, 5:50 PMpants export
is slow only the first time. But even simpler - when you have the venv, isn't it ready to use any time after that? why do you need the image?many-night-18726
08/19/2024, 5:54 PMsquare-psychiatrist-19087
08/19/2024, 5:55 PMsquare-psychiatrist-19087
08/19/2024, 5:55 PMmany-night-18726
08/20/2024, 5:56 PM1 - install pants
2 - pull my repo
3 - generate the python environment with pants export, which fills up the pants cache
4 - delete the repo, but keep the Pants cache
So now the cache has all the dependancies needed to regenerate the interpreter fast, when you run docker run
Thanks for your help @square-psychiatrist-19087square-psychiatrist-19087
08/20/2024, 5:56 PM