Skip to content

Commit d143307

Browse files
committed
build: find Python 3 or Python 2 in configure
1 parent 94c944d commit d143307

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

configure

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
#!/bin/sh
22

3-
# Locate python2 interpreter and re-execute the script. Note that the
4-
# mix of single and double quotes is intentional, as is the fact that
5-
# the ] goes on a new line.
3+
# Locate an acceptable python interpreter and then re-execute the script.
4+
# Note that the mix of single and double quotes is intentional,
5+
# as is the fact that the ] goes on a new line.
66
_=[ 'exec' '/bin/sh' '-c' '''
7+
test ${TRAVIS} && exec python "$0" "$@" # workaround for pyenv on Travis CI
78
which python2.7 >/dev/null && exec python2.7 "$0" "$@"
8-
which python2 >/dev/null && exec python2 "$0" "$@"
9+
which python3.7 >/dev/null && exec python3.7 "$0" "$@"
10+
which python3.6 >/dev/null && exec python3.6 "$0" "$@"
11+
which python3.5 >/dev/null && exec python3.5 "$0" "$@"
912
exec python "$0" "$@"
1013
''' "$0" "$@"
1114
]
1215
del _
1316

1417
import sys
15-
from distutils.spawn import find_executable as which
16-
if sys.version_info[:2] != (2, 7):
17-
sys.stderr.write('Please use Python 2.7')
18+
from distutils.spawn import find_executable
1819

19-
python2 = which('python2') or which('python2.7')
20-
21-
if python2:
22-
sys.stderr.write(':\n\n')
23-
sys.stderr.write(' ' + python2 + ' ' + ' '.join(sys.argv))
24-
25-
sys.stderr.write('\n')
20+
print('Node configure: Found Python {0}.{1}.{2}...'.format(*sys.version_info))
21+
acceptable_pythons = ((2, 7), (3, 7), (3, 6), (3, 5))
22+
if sys.version_info[:2] in acceptable_pythons:
23+
import configure
24+
else:
25+
python_cmds = ['python{0}.{1}'.format(*vers) for vers in acceptable_pythons]
26+
sys.stderr.write('Please use {0}.\n'.format(' or '.join(python_cmds)))
27+
for python_cmd in python_cmds:
28+
python_cmd_path = find_executable(python_cmd)
29+
if python_cmd_path and 'pyenv/shims' not in python_cmd_path:
30+
sys.stderr.write('\t{0} {1}\n'.format(python_cmd_path,
31+
' '.join(sys.argv[:1])))
2632
sys.exit(1)
27-
28-
import configure

0 commit comments

Comments
 (0)