From 75fef5132bcbeee1b4d1f308f5af67f02af8839c Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Wed, 28 Jun 2017 17:22:47 +0200 Subject: [PATCH] tools: Factorize Python detection code --- tools/common.sh | 17 +++++++++++++++++ tools/local_install.sh | 18 +----------------- tools/local_run.sh | 18 +----------------- tools/make_man.sh | 18 +----------------- tools/run_tests.sh | 39 +++++++++++---------------------------- tools/weboob_lint.sh | 18 +----------------- 6 files changed, 32 insertions(+), 96 deletions(-) create mode 100644 tools/common.sh diff --git a/tools/common.sh b/tools/common.sh new file mode 100644 index 0000000000..74870d0349 --- /dev/null +++ b/tools/common.sh @@ -0,0 +1,17 @@ +VER=2 +if [ "$1" = -3 ]; then + VER=3 + shift +fi + +if [ -z "${PYTHON}" ]; then + which python >/dev/null 2>&1 && PYTHON=$(which python) + which python$VER >/dev/null 2>&1 && PYTHON=$(which python$VER) + if [ $VER -eq 2 ]; then + which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7) + else + which python3.4 >/dev/null 2>&1 && PYTHON=$(which python3.4) + which python3.5 >/dev/null 2>&1 && PYTHON=$(which python3.5) + which python3.6 >/dev/null 2>&1 && PYTHON=$(which python3.6) + fi +fi diff --git a/tools/local_install.sh b/tools/local_install.sh index 34d3b97f3c..f723b47039 100755 --- a/tools/local_install.sh +++ b/tools/local_install.sh @@ -1,23 +1,7 @@ #!/bin/sh set -e -VER=2 -if [ "$1" = -3 ]; then - VER=3 - shift -fi - -if [ -z "${PYTHON}" ]; then - which python >/dev/null 2>&1 && PYTHON=$(which python) - which python$VER >/dev/null 2>&1 && PYTHON=$(which python$VER) - if [ $VER -eq 2 ]; then - which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7) - else - which python3.4 >/dev/null 2>&1 && PYTHON=$(which python3.4) - which python3.5 >/dev/null 2>&1 && PYTHON=$(which python3.5) - which python3.6 >/dev/null 2>&1 && PYTHON=$(which python3.6) - fi -fi +. "$(dirname $0)/common.sh" $PYTHON "$(dirname $0)/stale_pyc.py" diff --git a/tools/local_run.sh b/tools/local_run.sh index 5fb19dd640..12d245fec8 100755 --- a/tools/local_run.sh +++ b/tools/local_run.sh @@ -1,23 +1,7 @@ #!/bin/sh set -e -VER=2 -if [ "$1" = -3 ]; then - VER=3 - shift -fi - -if [ -z "${PYTHON}" ]; then - which python >/dev/null 2>&1 && PYTHON=$(which python) - which python$VER >/dev/null 2>&1 && PYTHON=$(which python$VER) - if [ $VER -eq 2 ]; then - which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7) - else - which python3.4 >/dev/null 2>&1 && PYTHON=$(which python3.4) - which python3.5 >/dev/null 2>&1 && PYTHON=$(which python3.5) - which python3.6 >/dev/null 2>&1 && PYTHON=$(which python3.6) - fi -fi +. "$(dirname $0)/common.sh" $PYTHON "$(dirname $0)/stale_pyc.py" diff --git a/tools/make_man.sh b/tools/make_man.sh index ede9a4980c..f343cf31b8 100755 --- a/tools/make_man.sh +++ b/tools/make_man.sh @@ -3,23 +3,7 @@ # stop on failure set -e -VER=2 -if [ "$1" = -3 ]; then - VER=3 - shift -fi - -if [ -z "${PYTHON}" ]; then - which python >/dev/null 2>&1 && PYTHON=$(which python) - which python$VER >/dev/null 2>&1 && PYTHON=$(which python$VER) - if [ $VER -eq 2 ]; then - which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7) - else - which python3.4 >/dev/null 2>&1 && PYTHON=$(which python3.4) - which python3.5 >/dev/null 2>&1 && PYTHON=$(which python3.5) - which python3.6 >/dev/null 2>&1 && PYTHON=$(which python3.6) - fi -fi +. "$(dirname $0)/common.sh" # Use C local to avoid local dates in headers export LANG=en_US.utf8 diff --git a/tools/run_tests.sh b/tools/run_tests.sh index 2dac9bc8e2..6964296f26 100755 --- a/tools/run_tests.sh +++ b/tools/run_tests.sh @@ -10,12 +10,19 @@ # stop on failure set -e -VER=2 -if [ "$1" = -3 ]; then - VER=3 - shift +. "$(dirname $0)/common.sh" + +if [ -z "${PYTHON}" ]; then + echo "Python required" + exit 1 fi +if ! $PYTHON -c "import nose" 2>/dev/null; then + echo "python-nose required" + exit 1 +fi + + # path to sources WEBOOB_DIR=$(cd $(dirname $0)/.. && pwd -P) @@ -61,30 +68,6 @@ else WEBOOB_CI_TARGET="" fi - -# find executables -if [ -z "${PYTHON}" ]; then - which python >/dev/null 2>&1 && PYTHON=$(which python) - which python$VER >/dev/null 2>&1 && PYTHON=$(which python$VER) - if [ $VER -eq 2 ]; then - which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7) - else - which python3.4 >/dev/null 2>&1 && PYTHON=$(which python3.4) - which python3.5 >/dev/null 2>&1 && PYTHON=$(which python3.5) - which python3.6 >/dev/null 2>&1 && PYTHON=$(which python3.6) - fi -fi - -if [ -z "${PYTHON}" ]; then - echo "Python required" - exit 1 -fi - -if ! $PYTHON -c "import nose" 2>/dev/null; then - echo "python-nose required" - exit 1 -fi - # do not allow undefined variables anymore set -u if [ -f "${WEBOOB_BACKENDS}" ]; then diff --git a/tools/weboob_lint.sh b/tools/weboob_lint.sh index 1628b12e74..0aecba52d7 100755 --- a/tools/weboob_lint.sh +++ b/tools/weboob_lint.sh @@ -3,23 +3,7 @@ # stop on failure set -e -VER=2 -if [ "$1" = -3 ]; then - VER=3 - shift -fi - -if [ -z "${PYTHON}" ]; then - which python >/dev/null 2>&1 && PYTHON=$(which python) - which python$VER >/dev/null 2>&1 && PYTHON=$(which python$VER) - if [ $VER -eq 2 ]; then - which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7) - else - which python3.4 >/dev/null 2>&1 && PYTHON=$(which python3.4) - which python3.5 >/dev/null 2>&1 && PYTHON=$(which python3.5) - which python3.6 >/dev/null 2>&1 && PYTHON=$(which python3.6) - fi -fi +. "$(dirname $0)/common.sh" [ -z "${TMPDIR}" ] && TMPDIR="/tmp" -- GitLab