Blob Blame History Raw
From 08ad53f2bdb8ef3a1cc02ff8a423d5a6da434dff Mon Sep 17 00:00:00 2001
From: Dave Dykstra <2129743+DrDaveD@users.noreply.github.com>
Date: Sun, 15 Jul 2018 14:43:57 -0500
Subject: [PATCH] prefer python3 if present

---
 configure.ac                              | 29 +++++++++++++++--------
 etc/configure_transform.py                |  9 ++++++-
 libexec/helpers/checks/1-bash-hiddens.py  | 10 +++++++-
 libexec/helpers/checks/1-cache-content.py | 10 +++++++-
 libexec/helpers/checks/1-docker.py        | 10 +++++++-
 libexec/helpers/checks/3-cve.py           | 10 +++++++-
 libexec/python/helpers/json/add.py        | 10 +++++++-
 libexec/python/helpers/json/delete.py     | 10 +++++++-
 libexec/python/helpers/json/dump.py       | 10 +++++++-
 libexec/python/helpers/json/get.py        | 10 +++++++-
 libexec/python/helpers/json/inspect.py    | 10 +++++++-
 libexec/python/import.py                  | 10 +++++++-
 libexec/python/pull.py                    | 10 +++++++-
 libexec/python/shub/api.py                | 10 +++++++-
 libexec/python/size.py                    | 10 +++++++-
 15 files changed, 144 insertions(+), 24 deletions(-)

diff --git a/configure.ac b/configure.ac
index b4c76cda3..836fb44bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -299,23 +299,32 @@ AM_COND_IF([FOUND_MKSQUASHFS],,[AC_MSG_WARN([mksquashfs not found - needed at ru
 # PYTHON
 # ---------------------------------------------------------------------
 
-AC_CHECK_PROG(PYTHON_CHECK,python,yes)
-if test x"$PYTHON_CHECK" != x"yes" ; then
-    AC_MSG_ERROR([Please install python before installing.])
+_PYTHON_EXEC=""
+AC_CHECK_PROG(PYTHON_CHECK,python3,yes)
+if test x"$PYTHON_CHECK" = x"yes" ; then
+    _PYTHON_EXEC=python3
 else
+    AC_CHECK_PROG(PYTHON_CHECK,python,yes)
+    if test x"$PYTHON_CHECK" = x"yes" ; then
+        _PYTHON_EXEC=python
+    else
+        AC_MSG_ERROR([Please install python before installing.])
+    fi
+fi
 
+if test x"$_PYTHON_EXEC" != ""; then
     PYTHON_MODULES="base64 datetime glob hashlib io itertools json math multiprocessing pickle pwd re shutil signal subprocess stat sys tarfile tempfile time"
     for PYTHON_MODULE in $PYTHON_MODULES; do
         AC_MSG_CHECKING([for the $PYTHON_MODULE python module])
-	    python_module_result=`python -c "import $PYTHON_MODULE" 2>&1`
-	    if test -z "$python_module_result"; then
-		AC_MSG_RESULT([yes])
-	    else
-		AC_MSG_RESULT([no])
-		AC_MSG_ERROR([cannot import Python module $PYTHON_MODULE.
+            python_module_result=`$_PYTHON_EXEC -c "import $PYTHON_MODULE" 2>&1`
+            if test -z "$python_module_result"; then
+                AC_MSG_RESULT([yes])
+            else
+                AC_MSG_RESULT([no])
+                AC_MSG_ERROR([cannot import Python module $PYTHON_MODULE.
                               Please check your Python installation. The error was:
                               $python_module_result])
-	    fi
+            fi
     done
 
 fi
diff --git a/etc/configure_transform.py b/etc/configure_transform.py
index 2d28114f1..42b165156 100755
--- a/etc/configure_transform.py
+++ b/etc/configure_transform.py
@@ -1,4 +1,11 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
 
 '''
 Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
diff --git a/libexec/helpers/checks/1-bash-hiddens.py b/libexec/helpers/checks/1-bash-hiddens.py
index fabca4bd9..b9e385104 100755
--- a/libexec/helpers/checks/1-bash-hiddens.py
+++ b/libexec/helpers/checks/1-bash-hiddens.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 #
 # Copyright (c) 2017-2018, SyLabs, Inc. All rights reserved.
 # Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
diff --git a/libexec/helpers/checks/1-cache-content.py b/libexec/helpers/checks/1-cache-content.py
index d31c2829a..f08555511 100755
--- a/libexec/helpers/checks/1-cache-content.py
+++ b/libexec/helpers/checks/1-cache-content.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 #
 # Copyright (c) 2017-2018, SyLabs, Inc. All rights reserved.
 # Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
diff --git a/libexec/helpers/checks/1-docker.py b/libexec/helpers/checks/1-docker.py
index 224506311..e4914a6a5 100755
--- a/libexec/helpers/checks/1-docker.py
+++ b/libexec/helpers/checks/1-docker.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 #
 # Copyright (c) 2017-2018, SyLabs, Inc. All rights reserved.
 # Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
diff --git a/libexec/helpers/checks/3-cve.py b/libexec/helpers/checks/3-cve.py
index 319e90673..94829b102 100755
--- a/libexec/helpers/checks/3-cve.py
+++ b/libexec/helpers/checks/3-cve.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 #
 # Copyright (c) 2017-2018, SyLabs, Inc. All rights reserved.
 # Copyright (c) 2017, SingularityWare, LLC. All rights reserved.
diff --git a/libexec/python/helpers/json/add.py b/libexec/python/helpers/json/add.py
index 9b533464d..0dab042ae 100644
--- a/libexec/python/helpers/json/add.py
+++ b/libexec/python/helpers/json/add.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/helpers/json/delete.py b/libexec/python/helpers/json/delete.py
index 0975e4e60..c2c95f95c 100644
--- a/libexec/python/helpers/json/delete.py
+++ b/libexec/python/helpers/json/delete.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/helpers/json/dump.py b/libexec/python/helpers/json/dump.py
index a1411565b..93c21ebf5 100644
--- a/libexec/python/helpers/json/dump.py
+++ b/libexec/python/helpers/json/dump.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/helpers/json/get.py b/libexec/python/helpers/json/get.py
index 355be9040..4e8a066ee 100644
--- a/libexec/python/helpers/json/get.py
+++ b/libexec/python/helpers/json/get.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/helpers/json/inspect.py b/libexec/python/helpers/json/inspect.py
index 85cbe47d5..40a836502 100644
--- a/libexec/python/helpers/json/inspect.py
+++ b/libexec/python/helpers/json/inspect.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/import.py b/libexec/python/import.py
index e67dda121..37dd22289 100644
--- a/libexec/python/import.py
+++ b/libexec/python/import.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/pull.py b/libexec/python/pull.py
index c3af8d4d0..21d967ca1 100644
--- a/libexec/python/pull.py
+++ b/libexec/python/pull.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/shub/api.py b/libexec/python/shub/api.py
index ce7574a1f..67d375e73 100644
--- a/libexec/python/shub/api.py
+++ b/libexec/python/shub/api.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''
 
diff --git a/libexec/python/size.py b/libexec/python/size.py
index 34331fd27..3e8ee385a 100644
--- a/libexec/python/size.py
+++ b/libexec/python/size.py
@@ -1,4 +1,12 @@
-#!/usr/bin/env python
+#!/bin/bash
+# the following line is the start of a comment to python and a no-op to bash
+''':'
+if type python3 >/dev/null 2>&1; then
+    exec python3 "$0" "$@"
+fi
+exec python "$0" "$@"
+'''
+
 
 '''