From 62272d5b24e7f505a02175de3c56ecc287557d2a Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Wed, 25 Jun 2025 11:17:15 +0800 Subject: [PATCH] [BE][Easy][setup] wrap over long error messages and redirect them to `stderr` in `setup.py` (#156043) Pull Request resolved: https://github.com/pytorch/pytorch/pull/156043 Approved by: https://github.com/jingsh --- setup.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index b4ebc92f5926..3950fc540a11 100644 --- a/setup.py +++ b/setup.py @@ -235,7 +235,9 @@ import sys if sys.platform == "win32" and sys.maxsize.bit_length() == 31: print( - "32-bit Windows Python runtime is not supported. Please switch to 64-bit Python." + "32-bit Windows Python runtime is not supported. " + "Please switch to 64-bit Python.", + file=sys.stderr, ) sys.exit(-1) @@ -246,7 +248,9 @@ python_min_version = (3, 9, 0) python_min_version_str = ".".join(map(str, python_min_version)) if sys.version_info < python_min_version: print( - f"You are using Python {platform.python_version()}. Python >={python_min_version_str} is required." + f"You are using Python {platform.python_version()}. " + f"Python >={python_min_version_str} is required.", + file=sys.stderr, ) sys.exit(-1) @@ -377,12 +381,12 @@ sys.argv = filtered_args if VERBOSE_SCRIPT: - def report(*args): - print(*args) + def report(*args, file=sys.stderr, **kwargs): + print(*args, file=file, **kwargs) else: - def report(*args): + def report(*args, **kwargs): pass # Make distutils respect --quiet too @@ -678,8 +682,8 @@ class build_ext(setuptools.command.build_ext.build_ext): break def run(self): - # Report build options. This is run after the build completes so # `CMakeCache.txt` exists and we can get an - # accurate report on what is used and what is not. + # Report build options. This is run after the build completes so # `CMakeCache.txt` exists + # and we can get an accurate report on what is used and what is not. cmake_cache_vars = defaultdict(lambda: False, cmake.get_cmake_cache_variables()) if cmake_cache_vars["USE_NUMPY"]: report("-- Building with NumPy bindings") @@ -987,7 +991,8 @@ def get_cmake_cache_vars(): try: return defaultdict(lambda: False, cmake.get_cmake_cache_variables()) except FileNotFoundError: - # CMakeCache.txt does not exist. Probably running "python setup.py clean" over a clean directory. + # CMakeCache.txt does not exist. + # Probably running "python setup.py clean" over a clean directory. return defaultdict(lambda: False) @@ -1178,7 +1183,8 @@ def print_box(msg): def main(): if BUILD_LIBTORCH_WHL and BUILD_PYTHON_ONLY: raise RuntimeError( - "Conflict: 'BUILD_LIBTORCH_WHL' and 'BUILD_PYTHON_ONLY' can't both be 1. Set one to 0 and rerun." + "Conflict: 'BUILD_LIBTORCH_WHL' and 'BUILD_PYTHON_ONLY' can't both be 1. " + "Set one to 0 and rerun." ) install_requires = [ "filelock",