ripe-magazine-21370
04/11/2025, 5:59 PMrequirements.txt + source files ?brief-engine-92399
04/11/2025, 6:26 PMripe-magazine-21370
04/11/2025, 6:29 PMbrief-engine-92399
04/11/2025, 6:39 PMbrief-engine-92399
04/11/2025, 6:40 PMgorgeous-winter-99296
04/11/2025, 6:55 PMgorgeous-winter-99296
04/11/2025, 7:04 PM$ echo "import numpy as np; print(np.array([1, 2, 3]).sum())" > script.py
$ pex -o np.pex numpy
$ ./np.pex script.py
6
In pants terms, you can use include_sources=False on a pex_binary to only package deps for the entrypoint. Feasibly you could then mount the whole src tree and run against, and as long as your deps don't change it should work.gorgeous-winter-99296
04/11/2025, 7:04 PM--loop as well.powerful-scooter-95162
04/11/2025, 7:59 PMripe-magazine-21370
04/11/2025, 8:11 PMpex_binary(name="deps", layout="packed", include_sources=False, ...)
python_distribution(name="srcs", ...)
docker_image(depends=[":deps", ":srcs"]
And then in Dockerfile
COPY ./deps.pex ./deps.pex
COPY ./srcs.whl ./srcs.whl
CMD [
"source", "./deps.pex/venv/bin/activate",
"&&",
"pip install -e ./srcs.whl",
"&&",
"my_entrypoint",
]ripe-magazine-21370
04/11/2025, 8:16 PMdeps.pex/.deps to get a bunch of wheelsripe-magazine-21370
04/11/2025, 8:21 PMripe-magazine-21370
04/11/2025, 9:30 PMserve-deps.pex and serve-srcs.pex
2. In Dockerfile, for serve-deps, stick with the recipe in the blog post that @powerful-scooter-95162 mentioned
3. For serve-srcs.pex just run COPY instead of using pextools. This will pull over the sources, ie:
RUN mkdir -p /bin/app/
RUN cp -r /serve-srcs.pex/* /bin/app/
RUN cp -r /serve-srcs.pex/.[^.]* /bin/app/
4. Use a shell script to activate the virtualenv and run your start script, eg
#! /bin/bash
echo "Sourcing /bin/app/bin/activate"
. /bin/app/bin/activate
export PYTHONPATH=/bin/app
python my_app/my_serve.pyripe-magazine-21370
04/11/2025, 9:43 PMsome-insurance-58590
04/14/2025, 5:18 PM