-
Notifications
You must be signed in to change notification settings - Fork 8k
feat(tools): allow to specify python binary by ESP_PYTHON_CUSTOM environment… (IDFGH-16803) #17880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
c2a568f
0865ae6
de48e9e
9826934
c05b5bf
35764cb
6d70a27
9d3eee7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,20 +5,27 @@ | |
| set OLDEST_PYTHON_SUPPORTED_MAJOR 3 | ||
| set OLDEST_PYTHON_SUPPORTED_MINOR 10 | ||
|
|
||
| set -x ESP_PYTHON python | ||
| if test -z "$ESP_PYTHON" | ||
| set PYTHON_CANDIDATES python3 python python3.10 python3.11 python3.12 python3.13 | ||
| else | ||
| echo "Reading ESP_PYTHON from environment: \"$ESP_PYTHON\"" | ||
| set PYTHON_CANDIDATES $ESP_PYTHON | ||
| end | ||
| set -e ESP_PYTHON # Unset it. Will assign after candidate check | ||
|
|
||
| for p_cmd in python3 python python3.10 python3.11 python3.12 python3.13; | ||
| for p_cmd in $PYTHON_CANDIDATES | ||
| $p_cmd --version >/dev/null 2>&1; or continue | ||
| echo "Checking \"$p_cmd\" ..." | ||
|
|
||
| $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 | ||
| set -x ESP_PYTHON $p_cmd | ||
|
||
| break | ||
| end | ||
| set -e PYTHON_CANDIDATES | ||
|
|
||
| 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 echo "Python $OLDEST_PYTHON_SUPPORTED_MAJOR.$OLDEST_PYTHON_SUPPORTED_MINOR+ is not installed! Please see the documentation for how to install it." >&2 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Misleading Python Version Error MessageWhen a user specifies |
||
| test -n "$ESP_PYTHON"; or exit 1 | ||
|
|
||
| $ESP_PYTHON --version | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,28 +3,36 @@ | |
| # 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 is looking for python version same or greater than minimal required version on path | ||
| # 1. If environment variable ESP_PYTHON already set, script uses that python binary, otherwise, looks 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 | ||
|
|
||
| OLDEST_PYTHON_SUPPORTED_MAJOR=3 | ||
| OLDEST_PYTHON_SUPPORTED_MINOR=10 | ||
|
|
||
| ESP_PYTHON=python | ||
|
|
||
| for p_cmd in python3 python python3.10 python3.11 python3.12 python3.13; do | ||
| $p_cmd --version >/dev/null 2>&1 || continue | ||
| if [[ -z "$ESP_PYTHON" ]]; then | ||
| PYTHON_CANDIDATES=(python3 python python3.10 python3.11 python3.12 python3.13) | ||
| else | ||
| echo "Reading ESP_PYTHON from environment: \"$ESP_PYTHON\"" | ||
| PYTHON_CANDIDATES=("$ESP_PYTHON") | ||
| fi | ||
| ESP_PYTHON= # Unset it. Will assign after candidate check | ||
|
|
||
| for p_cmd in "${PYTHON_CANDIDATES[@]}"; do | ||
| "$p_cmd" --version >/dev/null 2>&1 || continue | ||
| echo "Checking \"$p_cmd\" ..." | ||
|
|
||
| $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 | ||
| "$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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Inconsistent Python Version Validation LogicThe version validation checks major and minor versions independently, creating inconsistent behavior for future Python versions. Python 4.0-4.9 would be rejected (minor < 10) while Python 4.10+ would be accepted, even though Python 4.x may have breaking changes. The logic should either accept all Python 4+ versions or only Python 3.10+, not create an arbitrary cutoff at 4.10. |
||
|
|
||
| ESP_PYTHON=$p_cmd | ||
| export ESP_PYTHON="$p_cmd" | ||
| break | ||
| done | ||
| unset PYTHON_CANDIDATES | ||
|
|
||
| $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." | ||
| [[ -n "$ESP_PYTHON" ]] && "$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." >&2 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Misleading Python Version Error MessageWhen a user specifies |
||
| exit 1 | ||
| } | ||
| echo "\"$ESP_PYTHON\" has been detected" | ||
Uh oh!
There was an error while loading. Please reload this page.