Skip to content

lib: py: remove distutils in favor of setuptools#3007

Merged
Jens-G merged 1 commit into
apache:masterfrom
pyrox0:master
Nov 19, 2025
Merged

lib: py: remove distutils in favor of setuptools#3007
Jens-G merged 1 commit into
apache:masterfrom
pyrox0:master

Conversation

@pyrox0

@pyrox0 pyrox0 commented Jul 19, 2024

Copy link
Copy Markdown
Contributor

As distutils is removed in python 3.12, and setuptools provides the same interface, it can be switched in place with only minor changes. This allows using the thrift bindings on versions of Python 3.12 or greater, and in python environments without distutils installed(such as NixOS, which does not expose setuptools' internal distutils distribution)

  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • [ x Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

As distutils is removed in python 3.12, and setuptools provides the same
interface, it can be switched in place with minor changes. This allows
using the thrift bindings on versions of Python 3.12 or greater.

@ctubbsii ctubbsii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small incremental improvement. However, it should also be done with other modernizations, like those described in https://packaging.python.org/en/latest/guides/modernize-setup-py-project/

@Jens-G
Jens-G merged commit b4432b8 into apache:master Nov 19, 2025
@Jens-G

Jens-G commented Nov 19, 2025

Copy link
Copy Markdown
Member

@pyrox0

pyrox0 commented Nov 19, 2025

Copy link
Copy Markdown
Contributor Author

The CI runs on python 3.5(which has been deprecated since sep 2020) which does not have support for setuptools 59.0.0(released nov 2021), which is why this fails. CI even seems to use swtuptools 28.8.0, which was released in 2016!

1 similar comment
@pyrox0

pyrox0 commented Nov 19, 2025

Copy link
Copy Markdown
Contributor Author

The CI runs on python 3.5(which has been deprecated since sep 2020) which does not have support for setuptools 59.0.0(released nov 2021), which is why this fails. CI even seems to use swtuptools 28.8.0, which was released in 2016!

vikrantpuppala added a commit to vikrantpuppala/thrift that referenced this pull request Jun 6, 2026
…ds 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 a715bdf (PR apache#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-apache#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 apache#3007 (distutils -> setuptools migration).
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
vikrantpuppala added a commit to vikrantpuppala/thrift that referenced this pull request Jun 6, 2026
…ds 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 a715bdf (PR apache#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-apache#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 apache#3007 (distutils -> setuptools migration).
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Jens-G pushed a commit that referenced this pull request Jun 6, 2026
…ds 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 a715bdf (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 <vikrant.puppala@databricks.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants