Allow to pick python version in CI tools
Change-Id: I96c1e26af6aaefa26b164ed9dd9ff0e29fb702af
This commit is contained in:
parent
1fa8dfe997
commit
1929871d16
@ -1,3 +1,4 @@
|
||||
tox_dir: /opt/stack/tobiko
|
||||
tox_envlist: scenario
|
||||
tox_extra_args: ''
|
||||
tox_python_version: ''
|
||||
|
@ -1,6 +1,8 @@
|
||||
- name: Run Tobiko
|
||||
command: tools/ci/tox -e {{tox_envlist}} {{tox_extra_args}}
|
||||
args:
|
||||
chdir: "{{tox_dir}}"
|
||||
- name: Run Tobiko test cases
|
||||
shell:
|
||||
chdir: "{{ tox_dir }}"
|
||||
cmd: |
|
||||
export PYTHON_VERSION={{ tox_python_version }}
|
||||
tools/ci/tox -e "{{ tox_envlist }}" {{ tox_extra_args }}
|
||||
become: true
|
||||
become_user: stack
|
||||
|
@ -1,3 +1,8 @@
|
||||
CI_TOOLS_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
CI_TOOLS_DIR=$("${CI_TOOLS_DIR}/realpath" "${CI_TOOLS_DIR}")
|
||||
PATH=${CI_TOOLS_DIR}:${PATH}
|
||||
function tools_dir {
|
||||
local tools_dir=$(dirname "${BASH_SOURCE[0]}")
|
||||
PATH=${CI_TOOLS_ORIGINAL_PATH:-${PATH}} "${tools_dir}/realpath" "${tools_dir}"
|
||||
}
|
||||
|
||||
export CI_TOOLS_DIR=${CI_TOOLS_DIR:-$(tools_dir)}
|
||||
export CI_TOOLS_ORIGINAL_PATH=${CI_TOOLS_ORIGINAL_PATH:-${PATH}}
|
||||
export PATH=${CI_TOOLS_DIR}:${PATH}
|
||||
|
56
tools/ci/python
Executable file
56
tools/ci/python
Executable file
@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
|
||||
source $(dirname "$0")/activate
|
||||
|
||||
PYTHON_VERSION=${PYTHON_VERSION:-}
|
||||
|
||||
|
||||
function python() {
|
||||
# call get_python_exe only the first time it is required
|
||||
export PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-$(python_executable)}
|
||||
"${PYTHON_EXECUTABLE}" "$@"
|
||||
}
|
||||
|
||||
|
||||
function python_executable() {
|
||||
local version=${PYTHON_VERSION}
|
||||
|
||||
select_python_executables "${version}" \
|
||||
$(list_python_executables "${version}") | head -1
|
||||
}
|
||||
|
||||
|
||||
function list_python_executables() {
|
||||
PATH=${CI_TOOLS_ORIGINAL_PATH} which $(list_python_names "${version}")
|
||||
}
|
||||
|
||||
|
||||
function list_python_names() {
|
||||
local version=${1:-}
|
||||
if [ "${version}" != "" ]; then
|
||||
echo "python${version}"
|
||||
fi
|
||||
echo python3
|
||||
echo python
|
||||
}
|
||||
|
||||
|
||||
function select_python_executables() {
|
||||
local version=${1:-}
|
||||
local executable
|
||||
shift
|
||||
for executable in "$@"; do
|
||||
"${executable}" -c "${SELECT_PYTHON_EXECUTABLE_SCRIPT}" "${version}"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
read -r -d '' SELECT_PYTHON_EXECUTABLE_SCRIPT << END_OF_SCRIPT
|
||||
import sys
|
||||
version = ".".join(str(i) for i in sys.version_info[:3])
|
||||
if version.startswith(sys.argv[1]):
|
||||
print(sys.executable)
|
||||
END_OF_SCRIPT
|
||||
|
||||
|
||||
python "$@"
|
@ -6,7 +6,8 @@ source $(dirname "$0")/activate
|
||||
|
||||
|
||||
# Prefer python 3 over python 2
|
||||
TOX_BASE_PYTHON=${PYTHON:-$(which python3 || which python)}
|
||||
export PYTHON_VERSION=${PYTHON_VERSION:-3}
|
||||
TOX_BASE_PYTHON=${PYTHON:-${CI_TOOLS_DIR}/python}
|
||||
TOX_VIRTUAL_ENV=$(realpath "${TOX_VIRTUAL_ENV:-.tox/tox}")
|
||||
|
||||
|
||||
@ -47,7 +48,7 @@ function tox_setup {
|
||||
|
||||
function tox_install_deps {
|
||||
if ! "${TOX_BASE_PYTHON}" -m pip --version; then
|
||||
curl https://bootstrap.pypa.io/get-pip.py --user | "${TOX_BASE_PYTHON}"
|
||||
curl https://bootstrap.pypa.io/get-pip.py | "${TOX_BASE_PYTHON}" - --user
|
||||
fi
|
||||
if ! "${TOX_BASE_PYTHON}" -m virtualenv --version; then
|
||||
"${TOX_BASE_PYTHON}" -m pip install --user virtualenv
|
||||
|
@ -17,6 +17,7 @@
|
||||
- x/tobiko
|
||||
timeout: 7200
|
||||
vars:
|
||||
tox_python_version: 3
|
||||
devstack_localrc:
|
||||
MULTI_HOST: 0
|
||||
USE_PYTHON3: true
|
||||
@ -225,6 +226,7 @@
|
||||
devstack_localrc:
|
||||
# CentOS has no support for Python3
|
||||
USE_PYTHON3: false
|
||||
tox_python_version: 2
|
||||
|
||||
|
||||
- job:
|
||||
|
Loading…
Reference in New Issue
Block a user