From afe11f09a612f19ac4ecda5b3f92d0fb02d48456 Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Fri, 5 Jun 2026 06:59:29 +0000 Subject: [PATCH] THRIFT-6067: [py] Remove sys.exit() from setup.py to fix PEP 517 builds on setuptools < 69 thrift ships sdist-only, so every pip install builds lib/py/setup.py via the PEP 517 in-process backend. setup.py calls sys.exit(0) on its build success paths. setuptools' build_meta.run_setup() runs setup.py with exec(). On setuptools < 69 the resulting SystemExit propagates and terminates the build backend before it writes pip's result file: OSError: [Errno 2] No such file or directory: '.../output.json' setuptools >= 69 added a try/except SystemExit that swallows exit code 0 while emitting a SetuptoolsDeprecationWarning: 'Running setup.py directly as CLI tool is deprecated. Please avoid using sys.exit(0) or similar statements that don't fit in the paradigm of a configuration file.' (see setuptools build_meta and https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html). Because thrift has no wheels, any environment with setuptools < 69 cannot install thrift 0.23.0 (seen on runtime images bundling setuptools 68). The sys.exit() calls were added incidentally in a715bdff (PR #3330, 'THRIFT-5923: UUID python', 2025-10-30) with no rationale in the commit, PR description, or review. Before that commit setup.py used plain try/except control flow with no sys.exit() and built on all setuptools versions. Fix: restore the pre-#3330 control flow (try the C-extension build; on BuildFailed fall back to the pure-Python build; let any remaining failure propagate). No sys.exit() in setup.py. Behavior for consumers is unchanged. Related: THRIFT-5915 / PR #3007 (distutils -> setuptools migration). Signed-off-by: Vikrant Puppala Co-authored-by: Claude Opus 4.8 --- lib/py/setup.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/lib/py/setup.py b/lib/py/setup.py index 8b1a7beee15..ca77ec08adf 100644 --- a/lib/py/setup.py +++ b/lib/py/setup.py @@ -144,10 +144,7 @@ def run_setup(with_binary): try: - with_binary = True - run_setup(with_binary) - sys.exit(0) - + run_setup(with_binary=True) except BuildFailed: print() print('*' * 80) @@ -155,17 +152,6 @@ def run_setup(with_binary): print("Attempting to build without the extension now") print('*' * 80) print() - -# Retry but without the binary -try: - run_setup(False) - sys.exit(0) - -except BuildFailed: - print() - print('*' * 80) - print("An error occurred while trying to compile without the C extension enabled") - print("Build failed") - print('*' * 80) - print() - sys.exit(1) + # Fall back to the pure-Python build. If this also fails, let the + # exception propagate so the build backend reports the real error. + run_setup(with_binary=False)