-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.sh
executable file
·68 lines (57 loc) · 2.38 KB
/
init.sh
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
#!/bin/bash
set -euo pipefail
python_version="3.6"
venv_dir="venv"
numpy_version="1.19.4"
pip_version="21.2.4"
setuptools_version="57.4.0"
wheel_version="0.37.0"
build_version="0.6.0"
################################################################################
# Fail if desired Python version not available.
python${python_version} --version > /dev/null
# Create virtual env if it's not detected.
if [[ ! -d ${venv_dir} ]] ; then
python${python_version} -m venv ${venv_dir}
fi
# Activate virtual env (and prevent error about unbound variables).
set +u
source ${venv_dir}/bin/activate
set -u
# Check if pip, setuptools, wheel and build are at expected minimum versions.
echo "Checking build tools."
installed=$(pip list --local --format freeze | grep -v 'pkg-resources')
update_candidates=""
for p in pip setuptools wheel build ; do
set +e
current_version=$(echo -n "${installed}" | grep -E '^'${p}'[=><]+' | sed -E -e 's/^.*[=><]+//')
set -e
if [[ "x${current_version}" == "x" ]] ; then
update_candidates="${update_candidates} ${p}"
else
read -r current_version_maj current_version_min current_version_patch \
<<< $(echo ${current_version} | awk -F'.' '{print $1" "$2" "$3}')
desired_version=$(eval echo \$$(eval echo \${p}_version))
read -r desired_version_maj desired_version_min desired_version_patch \
<<< $(echo ${desired_version} | awk -F'.' '{print $1" "$2" "$3}')
if [[ $(echo $((${current_version_maj} < ${desired_version_maj}))) == "0" ]] ; then
if [[ $(echo $((${current_version_min} < ${desired_version_min}))) == "0" ]] ; then
if [[ $(echo $((${current_version_patch} < ${desired_version_patch}))) == "0" ]] ; then
:
else update_candidates="${update_candidates} ${p}" ; fi
else update_candidates="${update_candidates} ${p}" ; fi
else update_candidates="${update_candidates} ${p}" ; fi
fi
done
do_updates=""
for p in ${update_candidates} ; do
if [[ ${p} == "pip" ]] ; then p='pip>='${pip_version} ; fi
if [[ ${p} == "setuptools" ]] ; then p='setuptools>='${setuptools_version} ; fi
if [[ ${p} == "wheel" ]] ; then p='wheel>='${wheel_version} ; fi
if [[ ${p} == "build" ]] ; then p='build>='${build_version} ; fi
do_updates="${do_updates} ${p}"
done
if [[ "x${do_updates}" != "x" ]] ; then pip install --upgrade ${do_updates} ; fi
# Deactivate virtual env (and prevent error about unbound variables).
set +u
deactivate