From: Daan De Meyer Date: Wed, 11 Feb 2026 19:41:21 +0000 (+0100) Subject: bin/mkosi: Beef up interpreter searching logic X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8cf017b5ba4df7e5abcb7450d75dd51a1695f81;p=thirdparty%2Fmkosi.git bin/mkosi: Beef up interpreter searching logic Let's search for any installed interpreter that's sufficiently new. --- diff --git a/bin/mkosi b/bin/mkosi index d5223fdc8..9abee8f13 100755 --- a/bin/mkosi +++ b/bin/mkosi @@ -8,12 +8,26 @@ command="$(basename "${BASH_SOURCE[0]//-/.}")" if [ -z "$MKOSI_INTERPRETER" ]; then # Note the check seems to be inverted here because the if branch is # executed when the exit status is 0 which is equal to False in Python. - if python3 -c "import sys; sys.exit(sys.version_info < (3, 9))"; then + if python3 -c 'import sys; sys.exit(sys.version_info < (3, 9))'; then MKOSI_INTERPRETER=python3 - elif command -v python3.9 >/dev/null; then - MKOSI_INTERPRETER=python3.9 else - echo "mkosi needs python 3.9 or newer (found $(python3 --version))" + # python3 is not found or too old, search $PATH for the newest interpreter. + candidate="$( + IFS=: + for dir in $PATH; do + for bin in "$dir"/python3*; do + [ -x "$bin" ] && basename "$bin" + done + done | sort --unique --version-sort --reverse | head --lines=1 + )" + + if [ -n "$candidate" ] && "$candidate" -c 'import sys; sys.exit(sys.version_info < (3, 9))'; then + MKOSI_INTERPRETER="$candidate" + fi + fi + + if [ -z "$MKOSI_INTERPRETER" ]; then + echo "mkosi needs python 3.10 or newer (found $(python3 --version 2>&1 || echo 'no python3'))" exit 1 fi fi