diskimage-builder/diskimage_builder/elements/pip-and-virtualenv/environment.d/51-pip-and-virutalenv-default.bash
Ian Wienand 18215274d8 pip-and-virtualenv : deprecate source for CentOS 8, new variables
As described inline, deprecate the "source" install for CentOS 8.
Overwriting the packaged tools has long been a pain-point in our
images, and the best outcome is just not to play the game [1].

However, the landscape remains complicated.  For example, RHEL/CentOS
8 introduces the separate "platform-python" binary, which seems like
the right tool to install platform tools like "glean" (simple-init)
with.  However, platform-python doesn't have virtualenv (only the
inbuilt venv).

So that every element doesn't have to hard-code in workarounds for
these various layouts, create two new variables DIB_PYTHON_PIP and
DIB_PYTHON_VIRTUALENV to just "do the right thing".  If you need is
"install a pip package" or "create a virtualenv" this should work on
all the platforms we support.  If you know more specifically what you
want (e.g. must be a python3 virtualenv) then nothing stops elements
calling that directly (e.g. python3 -m virtualenv create); these are
just helper wrappers for base elements that need to be broadly
compatible.

[1] http://lists.openstack.org/pipermail/openstack-infra/2019-September/006483.html

Change-Id: Ia267a60eecfa8f4071dd477d86daebe07e9a7e38
2019-10-03 00:22:18 +00:00

34 lines
1.4 KiB
Bash

# Due to the many historical problems mixing python2/3 versions and
# upgrading packaged system pip/setuptools/virtualenv binaries with
# upstream non-packaged versions, we wish to avoid this completely on
# modern distros.
if [[ $DISTRO_NAME =~ (centos|rhel) && $DIB_RELEASE -ge 8 ]]; then
export DIB_INSTALLTYPE_pip_and_virtualenv=${DIB_INSTALLTYPE_pip_and_virtualenv:-package}
if [[ ${DIB_INSTALLTYPE_pip_and_virtualenv} == "source" ]]; then
echo "*** pip-and-virtualenv does not support 'source' install for $DISTRO_NAME/$DIB_RELEASE"
exit 1
fi
fi
# The default variables setup below are only useful during the phases
# that dib-python exists
if [[ ! -e /usr/local/bin/dib-python ]]; then
return 0
fi
# NOTE(ianw): you don't want to call "dib-python -m pip" because that
# can leave behind interpreters #!/usr/local/bin/dib-python in
# scripts. De-reference the link
_dib_python_path=$(readlink /usr/local/bin/dib-python)
export DIB_PYTHON_PIP="$_dib_python_path -m pip"
# We make an opinionated, but simplifying decision here that on
# Python3 platforms, just use venv. There are some corner cases that
# the external "virtualenv" package still handles better, but for most
# purposes "venv" should be fine.
if [[ $DIB_PYTHON_VERSION == 3 ]]; then
export DIB_PYTHON_VIRTUALENV="$_dib_python_path -m venv"
else
export DIB_PYTHON_VIRTUALENV="$_dib_python_path -m virtualenv"
fi