From ea9e23bf4691dfe912c1ff58344321821b581610 Mon Sep 17 00:00:00 2001 From: Matthew Hawkins Date: Fri, 19 May 2017 11:11:25 +1000 Subject: [PATCH] Preference Python 3 Make Python 3 the preferred option, and ensure pip is correctly invoked on systems like Debian that support coexistent python installations. Assume on other systems that we either win with Python 3 by default, or we were going to lose in any case and just fall back to python 2. --- upgrade.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/upgrade.sh b/upgrade.sh index 53e0c1db6..e2b94b253 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -20,9 +20,17 @@ COMMAND="${PREFIX}find . -name \"*.pyc\" -delete" echo "Cleaning up stale Python bytecode ($COMMAND)..." eval $COMMAND -# Fall back to pip3 if pip is missing -PIP="pip" -type $PIP >/dev/null 2>&1 || PIP="pip3" +# Prefer Python 3 +PIP=pip +if type -P pip3 >/dev/null 2>&1; then + # We're likely on something Debian-based with numbered coexistent pythons. + # If we're running 3.4 or better, use pip3 and invoke scripts with python3 + pip_version=$(pip3 --version | sed -e 's/.*(python \(.*\))/\1/') + if [[ ${pip_version:0:1} == 3 && ${pip_version:2:1} -gt 3 ]]; then + PIP=pip3 + find . -type f -name '*.py' -execdir sed -i -e '1s/python/python3/' {} + + fi +fi # Install any new Python packages COMMAND="${PREFIX}${PIP} install -r requirements.txt --upgrade"