Fix tools script python warnings
Change-Id: Ibdcd957ef689efd3ca0bd4ee729eb9f1e767413a
This commit is contained in:
parent
a9e9d5ee60
commit
71b25c3483
@ -6,3 +6,5 @@ function 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}
|
||||
|
||||
export PYTHONWARNINGS=${PYTHONWARNINGS:-ignore}
|
||||
|
@ -8,40 +8,49 @@ 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}" "$@"
|
||||
if [ -x "${PYTHON_EXECUTABLE}" ]; then
|
||||
"${PYTHON_EXECUTABLE}" "$@"
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function python_executable() {
|
||||
local version=${PYTHON_VERSION}
|
||||
|
||||
select_python_executables "${version}" \
|
||||
$(list_python_executables "${version}") | head -1
|
||||
local version=${PYTHON_VERSION:-}
|
||||
local executables=( $( list_python_executables ) )
|
||||
for executable in "${executables[@]}"; do
|
||||
if "${executable}" -c "${SELECT_PYTHON_EXECUTABLE_SCRIPT}" "${version}"; then
|
||||
echo "${executable}"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
fail 1 "No such Python executable (PYTHON_VERSION=${PYTHON_VERSION})"
|
||||
}
|
||||
|
||||
|
||||
function list_python_executables() {
|
||||
PATH=${CI_TOOLS_ORIGINAL_PATH} which $(list_python_names "${version}")
|
||||
PATH=${CI_TOOLS_ORIGINAL_PATH} which $(list_python_names) 2> /dev/null
|
||||
}
|
||||
|
||||
|
||||
function list_python_names() {
|
||||
local version=${1:-}
|
||||
local version=${PYTHON_VERSION}
|
||||
if [ "${version}" != "" ]; then
|
||||
echo "python${version}"
|
||||
fi
|
||||
echo python3.7
|
||||
echo python3.6
|
||||
echo python3
|
||||
echo python
|
||||
}
|
||||
|
||||
|
||||
function select_python_executables() {
|
||||
local version=${1:-}
|
||||
local executable
|
||||
function fail() {
|
||||
local error=$1
|
||||
shift
|
||||
for executable in "$@"; do
|
||||
"${executable}" -c "${SELECT_PYTHON_EXECUTABLE_SCRIPT}" "${version}"
|
||||
done
|
||||
echo "$@" 1>&2
|
||||
exit "${error}"
|
||||
}
|
||||
|
||||
|
||||
@ -49,8 +58,13 @@ 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)
|
||||
exit(0)
|
||||
else:
|
||||
exit(1)
|
||||
END_OF_SCRIPT
|
||||
|
||||
|
||||
python "$@"
|
||||
if [ $(basename "$0") == python ]; then
|
||||
set -euo pipefail
|
||||
python "$@"
|
||||
fi
|
||||
|
@ -5,4 +5,5 @@ import sys
|
||||
|
||||
args = sys.argv[1:] or ['.']
|
||||
results = [os.path.realpath(a) for a in args]
|
||||
print(' '.join(results))
|
||||
output = '\n'.join(results) + '\n'
|
||||
sys.stdout.write(output)
|
||||
|
Loading…
x
Reference in New Issue
Block a user