From 510074cb1e62fd8ef4c2be01abf6864e62092400 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Wed, 16 Oct 2024 14:49:24 +0530 Subject: [PATCH 1/2] update installation for check for python ver compatibility --- syftbox/server/templates/install.sh | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/syftbox/server/templates/install.sh b/syftbox/server/templates/install.sh index 44c97a8e..1d284ba9 100755 --- a/syftbox/server/templates/install.sh +++ b/syftbox/server/templates/install.sh @@ -116,6 +116,36 @@ install_syftbox() { fi } +#!/bin/bash + +check_python_version() { + # Try python3, if it exists; otherwise, fall back to python + if check_cmd python3; then + python_command="python3" + elif check_cmd python; then + python_command="python" + else + echo "Python is not installed." + return 1 + fi + + # Get the Python version (major and minor) + python_version=$($python_command --version 2>&1 | awk '{print $2}') + + # Extract major and minor version numbers + major_version=$(echo "$python_version" | cut -d. -f1) + minor_version=$(echo "$python_version" | cut -d. -f2) + + # Check if Python version is greater than or equal to 3.10 + if [ "$major_version" -eq 3 ] && [ "$minor_version" -ge 10 ] || [ "$major_version" -gt 3 ]; then + echo "$python_command version is greater than or equal to 3.10" + + else + err "Your python version $major_version.$minor_version <= 3.10. Please install Python >= 3.10." + fi +} + + pre_install() { # ----- pre-install checks ---- # uv doesn't really need python, @@ -123,6 +153,10 @@ pre_install() { # need_python # if you see this message, you're good to go + + # check if python version is >= 3.10 + check_python_version + echo " ____ __ _ ____ / ___| _ _ / _| |_| __ ) _____ __ From e2dd44887667cb2bf2276e9a1da53f5efc1ec1fb Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Wed, 16 Oct 2024 16:25:40 +0530 Subject: [PATCH 2/2] move python command check to a different function - simplify version check command --- syftbox/server/templates/install.sh | 49 ++++++++++++++++------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/syftbox/server/templates/install.sh b/syftbox/server/templates/install.sh index 1d284ba9..992ec670 100755 --- a/syftbox/server/templates/install.sh +++ b/syftbox/server/templates/install.sh @@ -51,6 +51,20 @@ downloader() { fi } +get_python_command() { + # check if either python3 or python is available + # and return the python command + + if check_cmd python3; then + echo "python3" + elif check_cmd python; then + echo "python" + else + err "need 'python' or 'python3' (command not found)" + fi +} + + need_python() { # check if either python3 or python is available if ! check_cmd python && ! check_cmd python3 @@ -116,33 +130,24 @@ install_syftbox() { fi } -#!/bin/bash check_python_version() { # Try python3, if it exists; otherwise, fall back to python - if check_cmd python3; then - python_command="python3" - elif check_cmd python; then - python_command="python" - else - echo "Python is not installed." + python_command=$(get_python_command) + + # Check if python_command is empty (meaning no python was found) + if [ -z "$python_command" ]; then return 1 fi - # Get the Python version (major and minor) - python_version=$($python_command --version 2>&1 | awk '{print $2}') - - # Extract major and minor version numbers - major_version=$(echo "$python_version" | cut -d. -f1) - minor_version=$(echo "$python_version" | cut -d. -f2) + # Check if the python version is >= 3.10 + pyver_check=$($python_command -c "import sys; print((sys.version_info[:2] >= (3, 10)))") - # Check if Python version is greater than or equal to 3.10 - if [ "$major_version" -eq 3 ] && [ "$minor_version" -ge 10 ] || [ "$major_version" -gt 3 ]; then - echo "$python_command version is greater than or equal to 3.10" - - else - err "Your python version $major_version.$minor_version <= 3.10. Please install Python >= 3.10." + # Check if Python version not is greater than or equal to 3.10 + if [ "$pyver_check" = "False" ]; then + err "Minimum python version is 3.10. Found: $($python_command -V)" fi + } @@ -150,13 +155,13 @@ pre_install() { # ----- pre-install checks ---- # uv doesn't really need python, # ... but incase we want we can toggle this on - # need_python - - # if you see this message, you're good to go + # need_python # check if python version is >= 3.10 check_python_version + # if you see this message, you're good to go + echo " ____ __ _ ____ / ___| _ _ / _| |_| __ ) _____ __