summaryrefslogtreecommitdiff
path: root/include/lib.sh
diff options
context:
space:
mode:
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>2025-04-21 13:01:37 +0300
committerAlper Nebi Yasak <alpernebiyasak@gmail.com>2025-04-21 17:45:25 +0300
commita18d287a81ec2a0fc018cf61cfa150308ccdeb4d (patch)
tree636f7dbc4b753edb0273058660ab063ead0b9829 /include/lib.sh
parentc7569a67145a9534b14f477e088bb60e4330f9be (diff)
lib.sh: Fix python3 detection when 'python' is python2
Properly set $pyver to "3" when we detect we can use python3. In the following version checks, use the $python we detected instead of a 'python' from PATH because the latter might be a python2 while still co-existing with a python3. Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Diffstat (limited to 'include/lib.sh')
-rw-r--r--include/lib.sh10
1 files changed, 7 insertions, 3 deletions
diff --git a/include/lib.sh b/include/lib.sh
index 21066ecc..47b16100 100644
--- a/include/lib.sh
+++ b/include/lib.sh
@@ -99,13 +99,17 @@ done
pyver="2"
python="python3"
-command -v python3 1>/dev/null || python="python"
+if command -v python3 1>/dev/null; then
+ pyver="3"
+else
+ python="python"
+fi
command -v $python 1>/dev/null || pyver=""
[ -z "$pyver" ] || \
- python -c 'import sys; print(sys.version_info[:])' 1>/dev/null \
+ $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[:])' | \
+ pyver="`$python -c 'import sys; print(sys.version_info[:])' | \
awk '{print $1}'`" && \
pyver="${pyver#(}" && pyver="${pyver%,}"
if [ "${pyver%%.*}" != "3" ]; then