File tree 1 file changed +25
-4
lines changed
1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change 1
- #!/usr/bin/env python
1
+ #! /usr/bin/env bash
2
2
3
+ # Modern Linux and macOS systems commonly only have a thing called `python3` and
4
+ # not `python`, while Windows commonly does not have `python3`, so we cannot
5
+ # directly use python in the shebang and have it consistently work. Instead we
6
+ # embed some bash to look for a python to run the rest of the script.
7
+ #
8
+ # On Windows, `py -3` sometimes works. We need to try it first because `python3`
9
+ # sometimes tries to launch the app store on Windows.
10
+ ' ' ' ' :
11
+ for PYTHON in " py -3" python3 python python2; do
12
+ if command -v $PYTHON > /dev/null; then
13
+ exec $PYTHON " $0 " " $@ "
14
+ break
15
+ fi
16
+ done
17
+ echo " $0 : error: did not find python installed" >&2
18
+ exit 1
19
+ ' ' '
20
+
21
+ # The rest of this file is Python.
22
+ #
3
23
# This file is only a "symlink" to bootstrap.py, all logic should go there.
4
24
5
25
import os
6
26
import sys
7
27
8
28
# If this is python2, check if python3 is available and re-execute with that
9
29
# interpreter.
30
+ #
31
+ # `./x.py` would not normally benefit from this because the bash above tries
32
+ # python3 before 2, but this matters if someone ran `python x.py` and their
33
+ # system' s ` python` is python2.
10
34
if sys.version_info.major < 3:
11
35
try:
12
- # On Windows, `py -3` sometimes works.
13
- # Try this first, because 'python3' sometimes tries to launch the app
14
- # store on Windows
15
36
os.execvp(" py" , [" py" , " -3" ] + sys.argv)
16
37
except OSError:
17
38
try:
You can’t perform that action at this time.
0 commit comments