tobiko/tools/ci/python
Federico Ressi 1929871d16 Allow to pick python version in CI tools
Change-Id: I96c1e26af6aaefa26b164ed9dd9ff0e29fb702af
2019-11-18 09:05:58 +00:00

57 lines
1.1 KiB
Bash
Executable File

#!/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 "$@"