File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 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
22
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+ #
323# This file is only a "symlink" to bootstrap.py, all logic should go there.
424
525import os
626import sys
727
828# If this is python2, check if python3 is available and re-execute with that
929# 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.
1034if sys.version_info.major < 3:
1135 try:
12- # On Windows, `py -3` sometimes works.
13- # Try this first, because 'python3' sometimes tries to launch the app
14- # store on Windows
1536 os.execvp(" py" , [" py" , " -3" ] + sys.argv)
1637 except OSError:
1738 try:
You can’t perform that action at this time.
0 commit comments