c81736092f7e05e55ac721ca7fb8d2301ea53ab9
[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     source ~/lf-env.sh
19     lf-activate-venv --python "$python" lftools
20 elif [[ -d /opt/pyenv ]]; then
21     echo "---> Setting up pyenv"
22     export PYENV_ROOT="/opt/pyenv"
23     export PATH="$PYENV_ROOT/bin:$PATH"
24     pyenv versions
25     if command -v pyenv 1>/dev/null 2>&1; then
26         eval "$(pyenv init - --no-rehash)"
27         pyenv local "$python"
28     fi
29 fi
30
31 # This script will typically be called during pre-build & post-build.
32 # Create the user venv during pre-build.
33 if [[ ! -f /tmp/pre-build-complete ]]; then
34     requirements_file=$(mktemp /tmp/requirements-XXXXXX)
35
36     # Note: To test lftools master branch change the lftools configuration below in
37     #       the requirements file from "lftools[openstack]~=#.##.#" to
38     #       git+https://github.com/lfit/releng-lftools.git#egg=lftools[openstack]
39
40     echo "Generating Requirements File"
41     cat << 'EOF' > "$requirements_file"
42 openstacksdk<0.99
43 python-heatclient
44 python-openstackclient
45 python-magnumclient
46 kubernetes
47 niet~=1.4.2
48 cryptography<3.4
49 yq
50
51 # PINNED INDIRECT DEPENDENCIES
52 # ============================
53 # The libraries listed below should be considered workarounds and thus need
54 # to have a link to a JIRA and any relevant pkg versions and support packages
55 # necessary so that future maintainers of this file can make decisions to
56 # remove the workarounds in the future.
57 importlib-resources<2.0.0  # virtualenv 20.0.21 requires importlib-resources<2.0.0 (RELENG-2993)
58 pyparsing<3.0.0 # httplib2 0.20.1 requires pyparsing<3,>=2.4.2
59 EOF
60
61     #Python 3.5 in Ubuntu 16.04 workaround
62     if [[ -f /etc/lsb-release ]]; then
63         # shellcheck disable=SC1091
64         source /etc/lsb-release
65         if [[ $DISTRIB_RELEASE == "16.04" && $DISTRIB_ID == "Ubuntu" ]]; then
66             echo "WARNING: Python projects should move to Ubuntu 18.04 to continue receiving support"
67             echo "zipp==1.1.0" >> "$requirements_file"
68         fi
69     fi
70
71     python3 -m pip install --quiet --upgrade pip
72     python3 -m pip install --quiet --no-warn-script-location --upgrade setuptools
73     python3 -m pip install --quiet --no-warn-script-location --upgrade lftools[openstack]
74     python3 -m pip install --quiet --no-warn-script-location --upgrade \
75         --upgrade-strategy eager -r "$requirements_file"
76     # installs are silent, show version details in log
77     python3 --version
78     python3 -m pip --version
79     python3 -m pip freeze
80
81     rm -rf "$requirements_file"
82     touch /tmp/pre-build-complete
83 fi