mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-03-25 21:39:03 +02:00
lib.sh: Much safer python version check
See: https://docs.python.org/3/library/sys.html#sys.version_info The sys.version_info tuple is a more reliable way to get the version. Our previous logic assumed that Python would always output "Python versionnumber", but this may not always be how it works. We've seen this for example where Debian modifies some GNU toolchains to include Debian something in the output. Python has a standard method built in for outputting exact the information we need. In my system, what I got was this: (3, 11, 2, 'final', 0) That output was from running this command: python -c 'import sys; print(sys.version_info[:])' This is much more robust, so use this instead. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -82,7 +82,13 @@ pyver="2"
|
||||
python="python3"
|
||||
command -v python3 1>/dev/null || python="python"
|
||||
command -v $python 1>/dev/null || pyver=""
|
||||
[ -n "$pyver" ] && pyver="$($python --version | awk '{print $2}')"
|
||||
[ -z "$pyver" ] || \
|
||||
python -c 'import sys; print(sys.version_info[:])' 1>/dev/null \
|
||||
2>/dev/null || $err "Cannot determine which Python version."
|
||||
[ -n "$pyver" ] && \
|
||||
pyver="`python -c 'import sys; print(sys.version_info[:])' | \
|
||||
awk '{print $1}'`" && \
|
||||
pyver="${pyver#(}" && pyver="${pyver%,}"
|
||||
if [ "${pyver%%.*}" != "3" ]; then
|
||||
printf "Wrong python version, or python missing. Must be v 3.x.\n" 1>&2
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user