[gtk-osx] Better options for base python.



commit bbcd8f107029722fd081bceda95f36cfef185dcd
Author: John Ralls <jralls ceridwen us>
Date:   Sun Oct 31 11:13:28 2021 -0700

    Better options for base python.
    
    Use $PYTHON if it's set, otherwise prefer python3 to python as Apple
    is (as of macOS 12) still setting python to python2.
    
    Set PIP="$PYTHON -m pip" instead of a path that might point to a shell
    script that requires a particular $PYTHONPATH.

 gtk-osx-setup.sh | 42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/gtk-osx-setup.sh b/gtk-osx-setup.sh
index d052b435..7cbbc719 100755
--- a/gtk-osx-setup.sh
+++ b/gtk-osx-setup.sh
@@ -98,17 +98,41 @@ if test ! -f "`eval echo $PIP_CONFIG_FILE`" ; then
     export PIP_CONFIG_FILE="$PIP_CONFIG_DIR/pip.conf"
     mkdir -p "$PIP_CONFIG_DIR"
 fi
-PIP=`which pip`
-if test ! -x "`eval echo $PIP`" ; then
-    mv=`python --version 2>&1 | cut -b 12-13`
-    if test $mv -lt 11 ; then
-        curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o "$DEVPREFIX/get-pip.py"
-        python "$DEVPREFIX/get-pip.py" --user
-        rm "$DEVPREFIX/get-pip.py"
+# What flavor of python is available?
+
+if test "x$PYTHON" = "x"; then
+    PYTHON3=`which python3`
+    if test "x$PYTHON3" != "x"; then
+        PYTHON=$PYTHON3
+        PYVER=3
+    else
+        PYTHON=`which python`
+        if test "x$PYTHON" != "x"; then
+            PYVER=`python --version 2>&1 | cut -d ' ' -f 2 | cut -d . -f 1`
+        else
+            echo "No Python interpreter found, quitting."
+            exit 1
+        fi
+    fi
+else
+    PYVER=`$PYTHON --version 2>&1 | cut -d ' ' -f 2 | cut -d . -f 1`
+fi
+
+PIP="$PYTHON -m pip"
+pip_name=`$PIP --version | cut -d ' ' -f 1`
+if test "x$pip_name" != "xpip"; then
+    if test a $PYVER -eq 2; then
+        mv=`$PYTHON --version 2>&1 |  cut -d ' ' -f 2 | cut -d . -f 3`
+        if test $mv -lt 11 ; then
+            curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o "$DEVPREFIX/get-pip.py"
+            $PYTHON "$DEVPREFIX/get-pip.py" --user
+            rm "$DEVPREFIX/get-pip.py"
+        else
+            $PYTHON -m ensurepip --user
+        fi
     else
-        python -m ensurepip --user
+        $PYTHON -m ensurepip --user
     fi
-    PIP="$PYTHONUSERBASE/bin/pip"
 fi
 $PIP install --upgrade --user pip
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]