From 8c36a7fce4858d6df8e4330d9c6b18ced5197679 Mon Sep 17 00:00:00 2001 From: Aarav Desai Date: Sat, 25 Oct 2025 10:30:08 -0700 Subject: [PATCH 1/4] Refine Python version checks and error messages Updated Python version checks and error handling in x.py. --- x.py | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/x.py b/x.py index 928a7496cb70e..4e6216553046f 100755 --- a/x.py +++ b/x.py @@ -2,10 +2,11 @@ # Some systems don't have `python3` in their PATH. This isn't supported by x.py directly; # they should use `x` or `x.ps1` instead. -# This file is only a "symlink" to bootstrap.py, all logic should go there. +# This file is only a "symlink" to bootstrap.py — all logic should go there. # Parts of `bootstrap.py` use the `multiprocessing` module, so this entry point # must use the normal `if __name__ == '__main__':` convention to avoid problems. + if __name__ == "__main__": import os import sys @@ -15,10 +16,7 @@ major = sys.version_info.major minor = sys.version_info.minor - # If this is python2, check if python3 is available and re-execute with that - # interpreter. Only python3 allows downloading CI LLVM. - # - # This matters if someone's system `python` is python2. + # If this is Python 2, try to re-execute using Python 3. if major < 3: try: os.execvp("py", ["py", "-3"] + sys.argv) @@ -26,28 +24,44 @@ try: os.execvp("python3", ["python3"] + sys.argv) except OSError: - # Python 3 isn't available, fall back to python 2 - pass + sys.exit( + "Error: Python 3 is required to run this script, " + "but it was not found on your system." + ) - # soft deprecation of old python versions + # Soft deprecation of old Python versions (< 3.8) skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1" - if not skip_check and (major < 3 or (major == 3 and minor < 6)): + if not skip_check and (major < 3 or (major == 3 and minor < 8)): msg = cleandoc( - """ - Using python {}.{} but >= 3.6 is recommended. Your python version - should continue to work for the near future, but this will - eventually change. If python >= 3.6 is not available on your system, - please file an issue to help us understand timelines. + f""" + Using Python {major}.{minor}, but >= 3.8 is recommended. + Your Python version should continue to work for now, + but this may change in the future. If Python >= 3.8 is + not available on your system, please file an issue to + help us understand timelines. - This message can be suppressed by setting `RUST_IGNORE_OLD_PYTHON=1` - """.format(major, minor) + This message can be suppressed by setting: + RUST_IGNORE_OLD_PYTHON=1 + """ ) - warnings.warn(msg, stacklevel=1) + warnings.warn(msg, stacklevel=2) rust_dir = os.path.dirname(os.path.abspath(__file__)) - # For the import below, have Python search in src/bootstrap first. - sys.path.insert(0, os.path.join(rust_dir, "src", "bootstrap")) + bootstrap_path = os.path.join(rust_dir, "src", "bootstrap") + + # Verify that the bootstrap path exists + if not os.path.isdir(bootstrap_path): + sys.exit(f"Error: Expected bootstrap directory not found at: {bootstrap_path}") + + # Add bootstrap path to module search path + sys.path.insert(0, bootstrap_path) - import bootstrap + try: + import bootstrap + except ImportError as e: + sys.exit(f"Error importing bootstrap module: {e}") - bootstrap.main() + try: + bootstrap.main() + except Exception as e: + sys.exit(f"Bootstrap failed: {e}") From 5e0931f31f5feb935f1c3830c4f7c98f51fdaebf Mon Sep 17 00:00:00 2001 From: Aarav Desai Date: Sat, 25 Oct 2025 10:35:19 -0700 Subject: [PATCH 2/4] Improve bootstrap import error handling and warning clarity --- x.py | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/x.py b/x.py index 4e6216553046f..8fe8be11115fa 100755 --- a/x.py +++ b/x.py @@ -2,7 +2,7 @@ # Some systems don't have `python3` in their PATH. This isn't supported by x.py directly; # they should use `x` or `x.ps1` instead. -# This file is only a "symlink" to bootstrap.py — all logic should go there. +# This file is only a "symlink" to bootstrap.py; all logic should go there. # Parts of `bootstrap.py` use the `multiprocessing` module, so this entry point # must use the normal `if __name__ == '__main__':` convention to avoid problems. @@ -16,7 +16,10 @@ major = sys.version_info.major minor = sys.version_info.minor - # If this is Python 2, try to re-execute using Python 3. + # If this is python2, check if python3 is available and re-execute with that + # interpreter. Only python3 allows downloading CI LLVM. + # + # This matters if someone's system `python` is python2. if major < 3: try: os.execvp("py", ["py", "-3"] + sys.argv) @@ -24,36 +27,32 @@ try: os.execvp("python3", ["python3"] + sys.argv) except OSError: - sys.exit( - "Error: Python 3 is required to run this script, " - "but it was not found on your system." - ) + # Python 3 isn't available, fall back to python 2 + pass - # Soft deprecation of old Python versions (< 3.8) + # Soft deprecation of old python versions skip_check = os.environ.get("RUST_IGNORE_OLD_PYTHON") == "1" - if not skip_check and (major < 3 or (major == 3 and minor < 8)): + if not skip_check and (major < 3 or (major == 3 and minor < 6)): msg = cleandoc( - f""" - Using Python {major}.{minor}, but >= 3.8 is recommended. - Your Python version should continue to work for now, - but this may change in the future. If Python >= 3.8 is - not available on your system, please file an issue to - help us understand timelines. - - This message can be suppressed by setting: - RUST_IGNORE_OLD_PYTHON=1 """ + Using python {}.{} but >= 3.6 is recommended. Your python version + should continue to work for the near future, but this will + eventually change. If python >= 3.6 is not available on your system, + please file an issue to help us understand timelines. + + This message can be suppressed by setting `RUST_IGNORE_OLD_PYTHON=1` + """.format(major, minor) ) warnings.warn(msg, stacklevel=2) rust_dir = os.path.dirname(os.path.abspath(__file__)) bootstrap_path = os.path.join(rust_dir, "src", "bootstrap") - # Verify that the bootstrap path exists + # Ensure bootstrap directory exists for clearer errors if not os.path.isdir(bootstrap_path): - sys.exit(f"Error: Expected bootstrap directory not found at: {bootstrap_path}") + sys.exit(f"Error: expected bootstrap directory not found at {bootstrap_path}") - # Add bootstrap path to module search path + # For the import below, have Python search in src/bootstrap first. sys.path.insert(0, bootstrap_path) try: @@ -61,7 +60,4 @@ except ImportError as e: sys.exit(f"Error importing bootstrap module: {e}") - try: - bootstrap.main() - except Exception as e: - sys.exit(f"Bootstrap failed: {e}") + bootstrap.main() From 9d1b1b6b2f1a0cfea3525400dbb071175d2e99c7 Mon Sep 17 00:00:00 2001 From: Aarav Desai Date: Sun, 26 Oct 2025 11:57:37 -0700 Subject: [PATCH 3/4] Fix Python 2.7 compatibility: replace f-strings with .format() --- x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x.py b/x.py index 8fe8be11115fa..ed80260b98c14 100755 --- a/x.py +++ b/x.py @@ -50,7 +50,7 @@ # Ensure bootstrap directory exists for clearer errors if not os.path.isdir(bootstrap_path): - sys.exit(f"Error: expected bootstrap directory not found at {bootstrap_path}") + sys.exit("Error: expected bootstrap directory not found at {}".format(bootstrap_path)) # For the import below, have Python search in src/bootstrap first. sys.path.insert(0, bootstrap_path) @@ -58,6 +58,6 @@ try: import bootstrap except ImportError as e: - sys.exit(f"Error importing bootstrap module: {e}") + sys.exit("Error importing bootstrap module: {}".format(e)) bootstrap.main() From f2b8eb5de265d0097c3321f635d0d26867f87e1d Mon Sep 17 00:00:00 2001 From: Aarav Desai Date: Sun, 26 Oct 2025 12:08:02 -0700 Subject: [PATCH 4/4] Fix Python formatting to match ruff style --- x.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x.py b/x.py index ed80260b98c14..7c5b665a10391 100755 --- a/x.py +++ b/x.py @@ -50,7 +50,9 @@ # Ensure bootstrap directory exists for clearer errors if not os.path.isdir(bootstrap_path): - sys.exit("Error: expected bootstrap directory not found at {}".format(bootstrap_path)) + sys.exit( + "Error: expected bootstrap directory not found at {}".format(bootstrap_path) + ) # For the import below, have Python search in src/bootstrap first. sys.path.insert(0, bootstrap_path)