From f57fba000b9f15ebcb68e898db23ef02a23eaefe Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Sun, 1 Sep 2019 17:07:47 +0200 Subject: [PATCH] Try to do the right thing on non PEP394 compliant systems PEP 394 [1] tells us that on systems with both a python 2 and 3 installed, the python 2 interpreter should be installed as python2. Unfortunately not all distributions adheres to PEP 394 (I'm looking at you, Windows) so to handle that we first try to find a 'python2', then fall back on plain 'python'. In order to not silently pick a python 3 by mistake, we check sys.version_info using the the interpreter we found. [1] https://www.python.org/dev/peps/pep-0394/ --- hg-fast-export.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/hg-fast-export.sh b/hg-fast-export.sh index 6239253..a4cb90e 100755 --- a/hg-fast-export.sh +++ b/hg-fast-export.sh @@ -26,7 +26,29 @@ SFX_MARKS="marks" SFX_HEADS="heads" SFX_STATE="state" GFI_OPTS="" -PYTHON=${PYTHON:-python2} + +if [ -z "${PYTHON}" ]; then + # $PYTHON is not set, so we try to find a working python 2.7 to + # use. PEP 394 tells us to use 'python2', otherwise try plain + # 'python'. + if command -v python2 > /dev/null; then + PYTHON="python2" + elif command -v python > /dev/null; then + PYTHON="python" + else + echo "Could not find any python interpreter, please use the 'PYTHON'" \ + "environment variable to specify the interpreter to use." + exit 1 + fi +fi + +# Check that the python specified by the user or autodetected above is +# >= 2.7 and < 3. +if ! ${PYTHON} -c 'import sys; v=sys.version_info; exit(0 if v.major == 2 and v.minor >= 7 else 1)' > /dev/null 2>&1 ; then + echo "${PYTHON} is not a working python 2.7 interpreter, please use the" \ + "'PYTHON' environment variable to specify the interpreter to use." + exit 1 +fi USAGE="[--quiet] [-r ] [--force] [-m ] [-s] [--hgtags] [-A ] [-B ] [-T ] [-M ] [-o ] [--hg-hash] [-e ]" LONG_USAGE="Import hg repository up to either tip or