diff options
| author | Zack <zmasi21@gmail.com> | 2026-11-28 13:59:35 -0800 |
|---|---|---|
| committer | Zack <zmasi21@gmail.com> | 2026-11-28 13:59:35 -0800 |
| commit | 06e5327291abf9ab43e85c6e08ab2bb4f3a7ac2d (patch) | |
| tree | ee03ea999daa390dcf669fe3d83a701d9c354b07 /scripts/launcher_python.sh | |
| parent | f77b4d80d0483027a978511d1d77d58a9523e43a (diff) | |
| parent | c7753ed98a56677f10e34078b37eab0540e190ec (diff) | |
Merge origin/main into fix/rdna2spirv-f16-interp-computed-ij
Diffstat (limited to 'scripts/launcher_python.sh')
| -rw-r--r-- | scripts/launcher_python.sh | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/scripts/launcher_python.sh b/scripts/launcher_python.sh new file mode 100644 index 000000000..a469f34ec --- /dev/null +++ b/scripts/launcher_python.sh | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | # Sourced by the POSIX launchers. Search for versioned Python names on PATH so a new Python minor | ||
| 2 | # release works even if the system's unversioned python3 still points to an older interpreter. | ||
| 3 | exec_leonida_python() { | ||
| 4 | remaining=${PATH-} | ||
| 5 | best_minor=11 | ||
| 6 | best_python= | ||
| 7 | while :; do | ||
| 8 | directory=${remaining%%:*} | ||
| 9 | for candidate in "${directory:-.}"/python3.*; do | ||
| 10 | [ -f "$candidate" ] && [ -x "$candidate" ] || continue | ||
| 11 | name=${candidate##*/} | ||
| 12 | minor=${name#python3.} | ||
| 13 | case $minor in | ||
| 14 | 0*|''|*[!0-9]*) continue ;; | ||
| 15 | esac | ||
| 16 | # Invoke by name to keep PATH precedence if that version appears in more than one directory. | ||
| 17 | if [ "$minor" -gt "$best_minor" ] 2>/dev/null && leonida_python_is_supported "$name"; then | ||
| 18 | best_minor=$minor | ||
| 19 | best_python=$name | ||
| 20 | fi | ||
| 21 | done | ||
| 22 | case $remaining in | ||
| 23 | *:*) remaining=${remaining#*:} ;; | ||
| 24 | *) break ;; | ||
| 25 | esac | ||
| 26 | done | ||
| 27 | |||
| 28 | if [ -n "$best_python" ]; then | ||
| 29 | exec "$best_python" -I "$@" | ||
| 30 | fi | ||
| 31 | for name in python3 python; do | ||
| 32 | if leonida_python_is_supported "$name"; then | ||
| 33 | exec "$name" -I "$@" | ||
| 34 | fi | ||
| 35 | done | ||
| 36 | } | ||
| 37 | |||
| 38 | leonida_python_is_supported() { | ||
| 39 | "$1" -I -c 'import sys; sys.exit(0 if sys.version_info >= (3, 12) else 1)' >/dev/null 2>&1 | ||
| 40 | } | ||