-
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 6 commits
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 |
|---|---|---|
|
|
@@ -3,28 +3,48 @@ | |
| # 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_CUSTOM 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 | ||
|
|
||
| detect_python () { | ||
|
|
||
| OLDEST_PYTHON_SUPPORTED_MAJOR=3 | ||
| OLDEST_PYTHON_SUPPORTED_MINOR=10 | ||
|
|
||
| ESP_PYTHON=python | ||
| PYTHON_CANDIDATES="python3 | ||
| python | ||
| python3.10 | ||
| python3.11 | ||
| python3.12 | ||
| python3.13" | ||
|
|
||
| if [ -n "$ESP_PYTHON_CUSTOM" ]; then | ||
| echo "Reading ESP_PYTHON_CUSTOM from environment: \"$ESP_PYTHON_CUSTOM\"" | ||
| PYTHON_CANDIDATES="$ESP_PYTHON_CUSTOM" | ||
| fi | ||
|
|
||
| for p_cmd in python3 python python3.10 python3.11 python3.12 python3.13; do | ||
| $p_cmd --version >/dev/null 2>&1 || continue | ||
| while IFS= read -r p_cmd; 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 | ||
| ESP_PYTHON="$p_cmd" | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break | ||
| done | ||
| done << EOF | ||
| $PYTHON_CANDIDATES | ||
| EOF | ||
|
|
||
| $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 | ||
| } | ||
| unset PYTHON_CANDIDATES | ||
|
|
||
| if [ -z "$ESP_PYTHON" ]; then | ||
| 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 |
||
| return 1 | ||
| fi | ||
| echo "\"$ESP_PYTHON\" has been detected" | ||
| export ESP_PYTHON | ||
|
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: Bash version doesn't display Python versionThe bash version no longer displays the Python version after detection, while the fish version still does at line 32. The old bash code ran |
||
|
|
||
| } | ||
| detect_python | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Misleading Python Version Error Message
When a user specifies
ESP_PYTHONpointing to a Python binary that doesn't meet version requirements, the error message "Python 3.10+ is not installed!" is misleading. Python 3.10+ might be installed on the system, but the user-specified binary doesn't meet requirements. The error should distinguish between these cases to avoid confusion.