mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Update detect_python SH
This commit is contained in:
parent
171b4ec13a
commit
addd647f41
@ -2,24 +2,22 @@
|
||||
#
|
||||
# This is a port of detect_python.sh. More information are provided there.
|
||||
|
||||
set -x ESP_PYTHON python
|
||||
set OLDEST_PYTHON_SUPPORTED_MAJOR 3
|
||||
set OLDEST_PYTHON_SUPPORTED_MINOR 7
|
||||
|
||||
for p_cmd in python python3;
|
||||
for p_cmd in python3 python python3.7 python3.8 python3.9 python3.10 python3.11 python3.12;
|
||||
$p_cmd --version >/dev/null 2>&1; or continue
|
||||
echo "Checking \"$p_cmd\" ..."
|
||||
|
||||
set res ($p_cmd -c "import sys; print(sys.version_info.major)")
|
||||
if [ "$res" = "3" ]
|
||||
set -x ESP_PYTHON $p_cmd
|
||||
break
|
||||
end
|
||||
$p_cmd -c "import sys; exit(1) if sys.version_info.major < int(\"$OLDEST_PYTHON_SUPPORTED_MAJOR\") else exit(0);"; or continue
|
||||
$p_cmd -c "import sys; exit(1) if sys.version_info.minor < int(\"$OLDEST_PYTHON_SUPPORTED_MINOR\") else exit(0);"; or continue
|
||||
|
||||
set ESP_PYTHON $p_cmd
|
||||
break
|
||||
end
|
||||
|
||||
test -n "$ESP_PYTHON"; or echo "Python $OLDEST_PYTHON_SUPPORTED_MAJOR.$OLDEST_PYTHON_SUPPORTED_MINOR+ is not installed! Please see the documentation for how to install it."
|
||||
test -n "$ESP_PYTHON"; or exit 1
|
||||
|
||||
$ESP_PYTHON --version
|
||||
if [ $status -ne 0 ]
|
||||
echo "\"$ESP_PYTHON\" is not installed! Please see the documentation for how to install it."
|
||||
# The following exit skips the rest of this file but won't exit fish where the script was sourced. This is not a
|
||||
# fatal issue.
|
||||
exit 1
|
||||
end
|
||||
|
||||
echo "\"$ESP_PYTHON\" has been detected"
|
||||
echo "$ESP_PYTHON has been detected"
|
||||
|
@ -3,22 +3,26 @@
|
||||
# This is a helper script for detecting Python executables in the PATH. It is intended to be used for determining
|
||||
# which Python should be used with idf_tools.py for installing tools and exporting environment variables.
|
||||
#
|
||||
# 1. The script will set variable ESP_PYTHON to "python" if it is of version 3.
|
||||
# 2. Otherwise, "python3" will be exported if it exists.
|
||||
# 3. The script will fall-back to "python" as the last resort and fail if it doesn't exist.
|
||||
# 1. The script is looking for python version same or greater than minimal required version on path
|
||||
# 2. If required version of python is found it is assigned to environmental variable `ESP_PYTHON`
|
||||
# 3. If required version of python is not found, script will fail
|
||||
|
||||
ESP_PYTHON=python
|
||||
OLDEST_PYTHON_SUPPORTED_MAJOR=3
|
||||
OLDEST_PYTHON_SUPPORTED_MINOR=7
|
||||
|
||||
for p_cmd in python python3
|
||||
do
|
||||
for p_cmd in python3 python python3.7 python3.8 python3.9 python3.10 python3.11 python3.12; do
|
||||
$p_cmd --version >/dev/null 2>&1 || continue
|
||||
echo "Checking \"$p_cmd\" ..."
|
||||
|
||||
if [ "$($p_cmd -c "import sys; print(sys.version_info.major)")" = 3 ]; then
|
||||
ESP_PYTHON=$p_cmd
|
||||
break
|
||||
fi
|
||||
$p_cmd -c "import sys; exit(1) if sys.version_info.major < int(\"$OLDEST_PYTHON_SUPPORTED_MAJOR\") else exit(0);" || continue
|
||||
$p_cmd -c "import sys; exit(1) if sys.version_info.minor < int(\"$OLDEST_PYTHON_SUPPORTED_MINOR\") else exit(0);" || continue
|
||||
|
||||
ESP_PYTHON=$p_cmd
|
||||
break
|
||||
done
|
||||
|
||||
$ESP_PYTHON --version || { echo "\"$ESP_PYTHON\" is not installed! Please see the documentation for how to install it."; exit 1; }
|
||||
|
||||
$ESP_PYTHON --version 2>/dev/null || {
|
||||
echo "Python ${OLDEST_PYTHON_SUPPORTED_MAJOR}.${OLDEST_PYTHON_SUPPORTED_MINOR}+ is not installed! Please see the documentation for how to install it."
|
||||
exit 1
|
||||
}
|
||||
echo "\"$ESP_PYTHON\" has been detected"
|
||||
|
Loading…
Reference in New Issue
Block a user