Skip to content

Commit beee487

Browse files
committed
Require Python 3 in bootstrap.py
If x.py was executed with Python 2, it tries to reexecute itself with Python 3 if that is available. If it isn't, we now raise an error. This may break people who have Python 3 in a nonstandard location under a nonstandard name. These people will now be forced to use `their-python3 x.py` instead of `./x.py`.
1 parent 5546cb6 commit beee487

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/bootstrap/bootstrap.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
except ImportError:
2020
lzma = None
2121

22+
assert sys.version_info.major == 3
23+
2224
if sys.platform == 'win32':
2325
EXE_SUFFIX = ".exe"
2426
else:

x.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
os.execvp("python3", ["python3"] + sys.argv)
2020
except OSError:
2121
# Python 3 isn't available, fall back to python 2
22-
pass
22+
sys.stderr.write("Could not find Python 3. If you have Python 3 available, use it to invoke x.py.")
23+
sys.stderr.write("If no Python 3 is available, consider installing it: https://www.python.org/downloads/")
24+
exit(1)
2325

2426
rust_dir = os.path.dirname(os.path.abspath(__file__))
2527
# For the import below, have Python search in src/bootstrap first.

0 commit comments

Comments
 (0)