-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathsetup_python_deps.sh
More file actions
105 lines (92 loc) · 2.92 KB
/
setup_python_deps.sh
File metadata and controls
105 lines (92 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash -ex
# vim: ts=4 sw=4 expandtab
#
# Script: Python Virtual Environment and Package Installer
create_venv_dir() {
local venv_dir
venv_dir=$(mktemp -td venv.XXXXXXXXXX)
trap "rm -rf ${venv_dir}" EXIT
echo "${venv_dir}"
}
create_virtualenv () {
local path=$1
if [ -d $path ]; then
echo "Will reuse existing virtual env: $path"
else
if command -v python3 > /dev/null; then
python3 -m venv $path
else
virtualenv -p python $path
fi
fi
}
pip_download() {
local venv=$1
shift
local package=$1
shift
local options=$@
if ! $venv/pip download $options --dest="$PIP_SDIST_INDEX" $package; then
# pip <8.0.0 does not have "download" command
$venv/pip install $options \
--upgrade --exists-action=i --cache-dir="$PIP_SDIST_INDEX" \
$package
fi
}
install_python_packages () {
local venv_dir=$1
shift
local venv="$venv_dir/bin"
# Use this function to create a virtualenv and install
# python packages. Pass a list of package names.
#
# Usage (with pip 24.0 [the default]):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages $TEMPVENV "to_install[@]"
#
# Usage (with pip<X.X.X [can also do ==X.X.X or !=X.X.X]):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages_no_binary $TEMPVENV "to_install[@]" "pip<X.X.X"
#
# Usage (with latest pip):
#
# to_install=( "ansible" "chacractl>=0.0.21" )
# install_python_packages $TEMPVENV "to_install[@]" latest
create_virtualenv $venv_dir
# Define and ensure the PIP cache
PIP_SDIST_INDEX="$HOME/.cache/pip"
mkdir -p $PIP_SDIST_INDEX
# Avoid UnicodeErrors when installing packages.
# See https://github.com/ceph/ceph/pull/42811
export LC_ALL=en_US.UTF-8
if [ "$2" == "latest" ]; then
echo "Ensuring latest pip is installed"
$venv/pip install -U pip
elif [[ -n $2 && "$2" != "latest" ]]; then
echo "Installing $2"
$venv/pip install "$2"
else
# This is the default for most jobs.
# See ff01d2c5 and fea10f52
echo "Installing pip 24.0"
$venv/pip install "pip==24.0"
fi
echo "Ensuring latest wheel is installed"
$venv/pip install -U wheel
echo "Updating setuptools"
pip_download $venv setuptools
pkgs=("${!1}")
for package in ${pkgs[@]}; do
echo $package
# download packages to the local pip cache
pip_download $venv $package
# install packages from the local pip cache, ignoring pypi
$venv/pip install --upgrade --exists-action=i --find-links="file://$PIP_SDIST_INDEX" --no-index $package
done
# See https://tracker.ceph.com/issues/59652
echo "Pinning urllib3 and requests"
$venv/pip install "urllib3<2.0.0"
$venv/pip install "requests<2.30.0"
}