Skip to content

Commit

Permalink
Use a venv for Python dependency tooling
Browse files Browse the repository at this point in the history
The version of Python installed as a system package is marked as
externally managed per PEP 668 and the pipenv Python package is not
available as a system package. Therefore we need to create a venv for
the Python packages we use for setup (pip, setuptools, wheel, and
pipenv).
  • Loading branch information
mcdonnnj committed Jan 10, 2025
1 parent 6bf44a6 commit a5a70aa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ RUN apk --no-cache add \
python3=3.12.8-r1

###
# Install the specified versions of pip, setuptools, and wheel into the system
# Python environment; install the specified version of pipenv into the system Python
# environment; set up a Python virtual environment (venv); and install the specified
# versions of pip, setuptools, and wheel into the venv.
# Create a Python virtual environment (venv) for setup (due to PEP 668); install the
# specified versions of pip, setuptools, and wheel into the setup venv; install the
# specified version of pipenv into the setup venv; create the image dependency venv;
# and install the specified versions of pip, setuptools, and wheel into the dependency
# venv.
#
# Note that we use the --no-cache-dir flag to avoid writing to a local
# cache. This results in a smaller final image, at the cost of
# slightly longer install times.
###
RUN python3 -m pip install --no-cache-dir --upgrade \
RUN python3 -m venv --system-site-packages /usr/local \
# Ensure the core Python packages are installed in the virtual environment
&& /usr/local/bin/python3 -m pip install --no-cache-dir --upgrade \
pip==${PYTHON_PIP_VERSION} \
setuptools==${PYTHON_SETUPTOOLS_VERSION} \
wheel==${PYTHON_WHEEL_VERSION} \
&& python3 -m pip install --no-cache-dir --upgrade \
&& /usr/local/bin/python3 -m pip install --no-cache-dir --upgrade \
pipenv==${PYTHON_PIPENV_VERSION} \
# Manually create the virtual environment
&& python3 -m venv ${VIRTUAL_ENV} \
Expand Down

0 comments on commit a5a70aa

Please sign in to comment.