2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2022 The Linux Foundation and others.
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 # vim: sw=4 ts=4 sts=4 et ft=sh :
15 echo "---> install-robotframework-py3.sh"
19 REQUIRED_PYTHON="3.7.0"
23 # Allows for the comparison of two Python version strings
27 # shellcheck disable=SC2206
28 local V1=($1) V2=($2) I
29 for ((I=0 ; I<${#V1[*]} || I<${#V2[*]} ; I++)) ; do
30 [[ ${V1[$I]:-0} -lt ${V2[$I]:-0} ]] && echo -1 && return
31 [[ ${V1[$I]:-0} -gt ${V2[$I]:-0} ]] && echo 1 && return
35 # Checks if first version/string is greater than or equal to the second
38 [[ ! $(ver_cmp "$1" "$2") -eq -1 ]]
41 ### Main script entry point
43 # Check for required Python versions and activate/warn appropriately
44 # Use PYENV for selecting the latest python version, if available
45 if [[ -d "/opt/pyenv" ]]; then
47 export PYENV_ROOT="/opt/pyenv"
48 export PATH="$PYENV_ROOT/bin:$PATH"
50 if command -v pyenv 1>/dev/null 2>&1; then
51 eval "$(pyenv init - --no-rehash)"
52 # Choose the latest numeric Python version from installed list
53 version=$(pyenv versions --bare | sed '/^[^0-9]/d' |\
55 pyenv local "${version}"
59 # Store the active/current Python3 version
60 PYTHON_VERSION=$(python3 --version | awk '{print $2}')
62 # Check that the required minimum version has been met
63 if ! (ver_ge "${PYTHON_VERSION}" "${REQUIRED_PYTHON}"); then
64 echo "Warning: possible Python version problem"
65 echo "Python ${PYTHON_VERSION} does not meet requirement: ${REQUIRED_PYTHON}"
68 if (python3 -m robot.run --version > /dev/null 2>&1); then
69 echo "Working robot framework found; no installation necessary"
70 echo "Installed under Python version: ${PYTHON_VERSION}"
75 # Create a requirements file; keep it around for potential later use
76 # Versions and dependencies below have been carefully tested for Python3
77 cat << 'EOF' > "requirements.txt"
87 selenium<4.6.0,>=4.0.0
89 robotframework-httplibrary
90 robotframework-requests==0.9.3
91 robotframework-selenium2library
92 robotframework-sshlibrary
94 # Module jsonpath is needed by current AAA idmlite suite.
96 # Modules for longevity framework robot library
97 elasticsearch<8.0.0,>=7.0.0
99 # Module for pyangbind used by lispflowmapping project
101 # Module for iso8601 datetime format
103 # Module for TemplatedRequests.robot library
105 # Module for backup-restore support library
113 # Protobuf requires Python >=3.7
120 # Additional package dependencies for ONAP project
121 # odltools for extra debugging
123 # ERROR: odltools 0.1.34 has requirement requests~=2.19.1,
124 # but you'll have requests 2.28.1 which is incompatible.
129 if [[ -f ~/lf-env.sh ]]; then
130 echo "Installing robot-framework using LF common tooling"
131 # shellcheck disable=SC1090
134 # Create a virtual environment for robot tests and make sure setuptools & wheel
135 # are up-to-date in addition to pip
136 lf-activate-venv --python python3 --venv-file "${WORKSPACE}/.robot3_venv" \
141 # Install the robot framework and other dependencies
142 python3 -m pip install -r requirements.txt
144 # Save the virtual environment in ROBOT3_VENV
145 ROBOT3_VENV="$(cat "${WORKSPACE}/.robot3_venv")"
148 echo "Installing robot-framework in a virtual environment"
149 if [[ -z "${WORKSPACE}" ]]; then
150 # Use a temporary folder location
152 ROBOT3_VENV=$(mktemp -d --suffix=-robot3_venv)
154 ROBOT3_VENV="${WORKSPACE}/.robot3_venv"
157 # The --system-site-packages parameter allows us to pick up system level
158 # installed packages. This allows us to bake matplotlib which takes very long
159 # to install into the image.
160 python3 -m venv --system-site-packages "${ROBOT3_VENV}"
161 source "${ROBOT3_VENV}/bin/activate"
163 echo "Installing robot-framework using basic methods"
164 python3 -m pip install -r requirements.txt
167 # Store the virtual environment location
168 echo "ROBOT3_VENV=${ROBOT3_VENV}" >> "${WORKSPACE}/env.properties"
170 # Display versioning/debugging output
172 python3 -m pip freeze
173 python3 -m robot.run --version || :