-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always install into a python venv in ci containers #12663
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,28 +18,77 @@ | |
|
||
set -e | ||
set -u | ||
# Used for debugging RVM build | ||
set -x | ||
set -o pipefail | ||
|
||
# install python and pip, don't modify this, modify install_python_package.sh | ||
set -x | ||
|
||
if [ -z "${TVM_VENV+x}" ]; then | ||
echo "ERROR: expect TVM_VENV env var to be set" | ||
exit 2 | ||
fi | ||
|
||
apt-get update | ||
apt-install-and-clear -y python-dev | ||
|
||
# python 3.6 | ||
# Ensure lsb-release is installed. | ||
apt-install-and-clear -y \ | ||
lsb-core | ||
|
||
release=$(lsb_release -sc) | ||
if [ "${release}" == "bionic" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we use miniconda instead of the distribution's Python + venv? The end result would be the same but we would be able to say "we use version X of Python in CI" instead of "it depends" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I was migrating teams off of conda I used pyenv which would compose into our system with Poetry? |
||
PYTHON_VERSION=3.7 | ||
elif [ "${release}" == "focal" ]; then | ||
PYTHON_VERSION=3.8 | ||
else | ||
echo "Don't know which version of python to install for lsb-release ${release}" | ||
exit 2 | ||
fi | ||
|
||
# Install python and pip. Don't modify this to add Python package dependencies, | ||
# instead modify install_python_package.sh | ||
apt-install-and-clear -y software-properties-common | ||
apt-install-and-clear -y \ | ||
acl \ | ||
python${PYTHON_VERSION} \ | ||
python${PYTHON_VERSION}-dev \ | ||
python3-pip \ | ||
python${PYTHON_VERSION}-venv | ||
|
||
add-apt-repository -y ppa:deadsnakes/ppa | ||
apt-get update | ||
apt-install-and-clear -y python-pip python-dev python3.6 python3.6-dev | ||
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 | ||
|
||
# Allow disabling user site-packages, even with sudo; this makes it harder to repro CI failures | ||
# locally because it's hard to tell what might be in this directory. | ||
echo "Defaults env_keep += \"PYTHONNOUSERSITE\"" >/etc/sudoers.d/91-preserve-python-nousersite | ||
export PYTHONNOUSERSITE=1 | ||
|
||
venv_dir="$(python3 -c "import os.path;print(os.path.dirname(\"${TVM_VENV}\"))")" | ||
mkdir -p "${venv_dir}" | ||
python3 -mvenv "${TVM_VENV}" | ||
. "${TVM_VENV}/bin/activate" | ||
|
||
# Update pip to match version used to produce requirements-hashed.txt. This step | ||
# is necessary so that pip's dependency solver is recent. | ||
pip_spec=$(cat /install/python/bootstrap/lockfiles/constraints-${PYTHON_VERSION}.txt | grep 'pip==') | ||
pip3 install -U --require-hashes -r <(echo "${pip_spec}") \ | ||
-c /install/python/bootstrap/lockfiles/constraints-${PYTHON_VERSION}.txt | ||
|
||
rm -f /usr/bin/python3 && ln -s /usr/bin/python3.6 /usr/bin/python3 | ||
# Python configuration | ||
pip3 config set global.no-cache-dir true # Never cache packages | ||
|
||
# python 3.7 | ||
apt-install-and-clear -y python3.7 | ||
# Now install the remaining base packages. | ||
pip3 install \ | ||
--require-hashes \ | ||
-r /install/python/bootstrap/lockfiles/constraints-${PYTHON_VERSION}.txt | ||
|
||
# Install pip | ||
wget -q https://bootstrap.pypa.io/get-pip.py && python3.7 get-pip.py | ||
addgroup tvm-venv | ||
chgrp -R tvm-venv "${TVM_VENV}" | ||
setfacl -R -d -m group:tvm-venv:rwx "${TVM_VENV}" | ||
|
||
# Pin pip and setuptools versions | ||
pip3 install pip==19.3.1 setuptools==58.4.0 | ||
# Prevent further use of pip3 via the system. | ||
# There may be multiple (i.e. from python3-pip apt package and pip3 install -U). | ||
deactivate | ||
while [ "$(which pip3)" != "" ]; do | ||
rm "$(which pip3)" | ||
done | ||
while [ "$(which pip)" != "" ]; do | ||
rm "$(which pip)" | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.