2ca350deb916f452740d1f9d66d1afe560c54a0e
[releng/global-jjb.git] / shell / python-tools-install.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2018 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 echo "---> python-tools-install.sh"
12
13 set -eufo pipefail
14
15 # Souce the python version from lf-env.sh if available.
16 python="python3"
17 if [[ -f ~/lf-env.sh ]]; then
18     # shellcheck source=/dev/null
19     source ~/lf-env.sh
20     lf-activate-venv --python "$python" lftools
21     # Save the virtualenv path
22     # shellcheck disable=SC2154
23     echo "$lf_venv" > "/tmp/.os_lf_venv"
24 elif [[ -d /opt/pyenv ]]; then
25     echo "Setup up pyenv"
26     export PYENV_ROOT="/opt/pyenv"
27     export PATH="$PYENV_ROOT/bin:$PATH"
28     pyenv versions
29     if command -v pyenv 1>/dev/null 2>&1; then
30         eval "$(pyenv init - --no-rehash)"
31         pyenv local "$python"
32     fi
33 fi
34
35 # This script will typically be called during pre-build & post-build.
36 # Create the user venv during pre-build.
37 if [[ ! -f /tmp/pre-build-complete ]]; then
38     requirements_file=$(mktemp /tmp/requirements-XXXXXX)
39
40     # Note: To test lftools master branch change the lftools configuration below in
41     #       the requirements file from "lftools[openstack]~=#.##.#" to
42     #       git+https://github.com/lfit/releng-lftools.git#egg=lftools[openstack]
43
44     echo "Generating Requirements File"
45     cat << 'EOF' > "$requirements_file"
46 openstacksdk<0.99
47 python-heatclient
48 python-openstackclient
49 python-magnumclient
50 kubernetes
51 niet~=1.4.2
52 cryptography<3.4
53 yq
54
55 # PINNED INDIRECT DEPENDENCIES
56 # ============================
57 # The libraries listed below should be considered workarounds and thus need
58 # to have a link to a JIRA and any relevant pkg versions and support packages
59 # necessary so that future maintainers of this file can make decisions to
60 # remove the workarounds in the future.
61 importlib-resources<2.0.0  # virtualenv 20.0.21 requires importlib-resources<2.0.0 (RELENG-2993)
62 pyparsing<3.0.0 # httplib2 0.20.1 requires pyparsing<3,>=2.4.2
63 urllib3~=1.26.15 # python-jenkins-1.8.0 requires urllib3-1.26
64 EOF
65
66     #Python 3.5 in Ubuntu 16.04 workaround
67     if [[ -f /etc/lsb-release ]]; then
68         # shellcheck disable=SC1091
69         source /etc/lsb-release
70         if [[ $DISTRIB_RELEASE == "16.04" && $DISTRIB_ID == "Ubuntu" ]]; then
71             echo "WARNING: Python projects should move to Ubuntu 18.04 to continue receiving support"
72             echo "zipp==1.1.0" >> "$requirements_file"
73         fi
74     fi
75
76     python3 -m pip install --quiet --upgrade pip
77     # TODO: temporarily pinning setuptools to avoid plugin version format issues
78     # https://github.com/pypa/setuptools/issues/3772#issuecomment-1384342813
79     python3 -m pip install --quiet --no-warn-script-location --upgrade setuptools==65.7.0
80     python3 -m pip install --quiet --no-warn-script-location --upgrade lftools[openstack] urllib3~=1.26.15
81     python3 -m pip install --quiet --no-warn-script-location --upgrade \
82         --upgrade-strategy eager -r "$requirements_file"
83     # installs are silent, show version details in log
84     python3 --version
85     python3 -m pip --version
86     python3 -m pip freeze
87
88     rm -rf "$requirements_file"
89     touch /tmp/pre-build-complete
90 fi