Merge "Fix tools script python warnings"
This commit is contained in:
commit
0afe476d7c
|
@ -6,3 +6,5 @@ function tools_dir {
|
||||||
export CI_TOOLS_DIR=${CI_TOOLS_DIR:-$(tools_dir)}
|
export CI_TOOLS_DIR=${CI_TOOLS_DIR:-$(tools_dir)}
|
||||||
export CI_TOOLS_ORIGINAL_PATH=${CI_TOOLS_ORIGINAL_PATH:-${PATH}}
|
export CI_TOOLS_ORIGINAL_PATH=${CI_TOOLS_ORIGINAL_PATH:-${PATH}}
|
||||||
export PATH=${CI_TOOLS_DIR}:${PATH}
|
export PATH=${CI_TOOLS_DIR}:${PATH}
|
||||||
|
|
||||||
|
export PYTHONWARNINGS=${PYTHONWARNINGS:-ignore}
|
||||||
|
|
|
@ -8,40 +8,49 @@ PYTHON_VERSION=${PYTHON_VERSION:-}
|
||||||
function python() {
|
function python() {
|
||||||
# call get_python_exe only the first time it is required
|
# call get_python_exe only the first time it is required
|
||||||
export PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-$(python_executable)}
|
export PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-$(python_executable)}
|
||||||
"${PYTHON_EXECUTABLE}" "$@"
|
if [ -x "${PYTHON_EXECUTABLE}" ]; then
|
||||||
|
"${PYTHON_EXECUTABLE}" "$@"
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function python_executable() {
|
function python_executable() {
|
||||||
local version=${PYTHON_VERSION}
|
local version=${PYTHON_VERSION:-}
|
||||||
|
local executables=( $( list_python_executables ) )
|
||||||
select_python_executables "${version}" \
|
for executable in "${executables[@]}"; do
|
||||||
$(list_python_executables "${version}") | head -1
|
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() {
|
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() {
|
function list_python_names() {
|
||||||
local version=${1:-}
|
local version=${PYTHON_VERSION}
|
||||||
if [ "${version}" != "" ]; then
|
if [ "${version}" != "" ]; then
|
||||||
echo "python${version}"
|
echo "python${version}"
|
||||||
fi
|
fi
|
||||||
|
echo python3.7
|
||||||
|
echo python3.6
|
||||||
echo python3
|
echo python3
|
||||||
echo python
|
echo python
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function select_python_executables() {
|
function fail() {
|
||||||
local version=${1:-}
|
local error=$1
|
||||||
local executable
|
|
||||||
shift
|
shift
|
||||||
for executable in "$@"; do
|
echo "$@" 1>&2
|
||||||
"${executable}" -c "${SELECT_PYTHON_EXECUTABLE_SCRIPT}" "${version}"
|
exit "${error}"
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,8 +58,13 @@ read -r -d '' SELECT_PYTHON_EXECUTABLE_SCRIPT << END_OF_SCRIPT
|
||||||
import sys
|
import sys
|
||||||
version = ".".join(str(i) for i in sys.version_info[:3])
|
version = ".".join(str(i) for i in sys.version_info[:3])
|
||||||
if version.startswith(sys.argv[1]):
|
if version.startswith(sys.argv[1]):
|
||||||
print(sys.executable)
|
exit(0)
|
||||||
|
else:
|
||||||
|
exit(1)
|
||||||
END_OF_SCRIPT
|
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 ['.']
|
args = sys.argv[1:] or ['.']
|
||||||
results = [os.path.realpath(a) for a in args]
|
results = [os.path.realpath(a) for a in args]
|
||||||
print(' '.join(results))
|
output = '\n'.join(results) + '\n'
|
||||||
|
sys.stdout.write(output)
|
||||||
|
|
Loading…
Reference in New Issue