Skip to content

Commit c8cac2a

Browse files
committed
Choose the version of python at runtime (portable version)
- Try `py -3` first for windows compatibility - Fall back to `python3` if `py` doesn't work
1 parent 18d27b2 commit c8cac2a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

x.py

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
import os
66
import sys
7+
8+
# If this is python2, check if python3 is available and re-execute with that
9+
# interpreter.
10+
if sys.version_info.major < 3:
11+
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+
os.execvp("py", ["py", "-3"] + sys.argv)
16+
except OSError:
17+
try:
18+
os.execvp("python3", ["python3"] + sys.argv)
19+
except OSError:
20+
# Python 3 isn't available, fall back to python 2
21+
pass
22+
723
rust_dir = os.path.dirname(os.path.abspath(__file__))
824
sys.path.append(os.path.join(rust_dir, "src", "bootstrap"))
925

0 commit comments

Comments
 (0)