From beee487c02b3664ee48c359c4cdb8880d30bc6c4 Mon Sep 17 00:00:00 2001 From: nils <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 17 Apr 2023 07:55:58 +0200 Subject: [PATCH] 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`. --- src/bootstrap/bootstrap.py | 2 ++ x.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 0f3a9f968268a..8e0992fd8bfd5 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -19,6 +19,8 @@ except ImportError: lzma = None +assert sys.version_info.major == 3 + if sys.platform == 'win32': EXE_SUFFIX = ".exe" else: diff --git a/x.py b/x.py index 5dee953a31899..53ebecbbbabd7 100755 --- a/x.py +++ b/x.py @@ -19,7 +19,9 @@ os.execvp("python3", ["python3"] + sys.argv) except OSError: # Python 3 isn't available, fall back to python 2 - pass + sys.stderr.write("Could not find Python 3. If you have Python 3 available, use it to invoke x.py.") + sys.stderr.write("If no Python 3 is available, consider installing it: https://www.python.org/downloads/") + exit(1) rust_dir = os.path.dirname(os.path.abspath(__file__)) # For the import below, have Python search in src/bootstrap first.