Refael Ackermann | cc9dd0f | 2018-08-21 23:28:53 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
cclauss | be926c7 | 2019-02-01 13:51:37 | [diff] [blame] | 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. |
| 6 | # When a 'which' call is made for a specific version of Python on Travis CI, |
| 7 | # pyenv will alert which shims are available and then will fail the build. |
Refael Ackermann | cc9dd0f | 2018-08-21 23:28:53 | [diff] [blame] | 8 | _=[ 'exec' '/bin/sh' '-c' ''' |
cclauss | be926c7 | 2019-02-01 13:51:37 | [diff] [blame] | 9 | test ${TRAVIS} && exec python "$0" "$@" # workaround for pyenv on Travis CI |
Michaël Zasso | 3a076ba | 2019-10-31 11:01:26 | [diff] [blame] | 10 | which python3.8 >/dev/null && exec python3.8 "$0" "$@" |
cclauss | be926c7 | 2019-02-01 13:51:37 | [diff] [blame] | 11 | which python3.7 >/dev/null && exec python3.7 "$0" "$@" |
| 12 | which python3.6 >/dev/null && exec python3.6 "$0" "$@" |
| 13 | which python3.5 >/dev/null && exec python3.5 "$0" "$@" |
Sam Roberts | b2ccbb2 | 2019-10-23 16:55:13 | [diff] [blame] | 14 | which python2.7 >/dev/null && exec python2.7 "$0" "$@" |
Refael Ackermann | cc9dd0f | 2018-08-21 23:28:53 | [diff] [blame] | 15 | exec python "$0" "$@" |
| 16 | ''' "$0" "$@" |
| 17 | ] |
| 18 | del _ |
| 19 | |
| 20 | import sys |
cclauss | be926c7 | 2019-02-01 13:51:37 | [diff] [blame] | 21 | from distutils.spawn import find_executable |
Refael Ackermann | cc9dd0f | 2018-08-21 23:28:53 | [diff] [blame] | 22 | |
cclauss | be926c7 | 2019-02-01 13:51:37 | [diff] [blame] | 23 | print('Node configure: Found Python {0}.{1}.{2}...'.format(*sys.version_info)) |
Michaël Zasso | 3a076ba | 2019-10-31 11:01:26 | [diff] [blame] | 24 | acceptable_pythons = ((3, 8), (3, 7), (3, 6), (3, 5), (2, 7)) |
cclauss | be926c7 | 2019-02-01 13:51:37 | [diff] [blame] | 25 | if sys.version_info[:2] in acceptable_pythons: |
| 26 | import configure |
| 27 | else: |
| 28 | python_cmds = ['python{0}.{1}'.format(*vers) for vers in acceptable_pythons] |
| 29 | sys.stderr.write('Please use {0}.\n'.format(' or '.join(python_cmds))) |
| 30 | for python_cmd in python_cmds: |
| 31 | python_cmd_path = find_executable(python_cmd) |
| 32 | if python_cmd_path and 'pyenv/shims' not in python_cmd_path: |
| 33 | sys.stderr.write('\t{0} {1}\n'.format(python_cmd_path, |
| 34 | ' '.join(sys.argv[:1]))) |
Refael Ackermann | cc9dd0f | 2018-08-21 23:28:53 | [diff] [blame] | 35 | sys.exit(1) |