Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@greggdonovan
Copy link
Contributor

@greggdonovan greggdonovan commented Dec 22, 2025

JIRA link for THRIFT-5915

Summary:

  • Switch Python setup scripts to use setuptools instead of stdlib distutils (Python 3.12 removed distutils).
  • Use setuptools._distutils errors for build_ext error handling when available.
  • Guard ntohll/htonll definitions in lib/py/src/ext/endian.h to avoid macOS macro collisions that break C++ builds.
  • Update tornado, twisted, and zope to the minimum versions that support Python 3.12.

Why:

  • Python 3.12 no longer ships distutils, causing thrift builds from sdist to fail during wheel build.
  • On macOS, system headers define ntohll/htonll macros; the local inline definitions collided, causing compilation failures.

Validation:

  • Built a wheel from lib/py with Python 3.12 successfully after the changes.

Related issues:

  • THRIFT-5899 - "Python tests fail for the Appveyor MSVC builds". My PR updates MSVC to 2022 and tests with Python 3.12. This is green/passing, so maybe we'll be able to close that JIRA too?

N.B.: there are multiple commits at the moment but I will squash them to a single commit before merge per guidelines.

try:
from setuptools import setup, Extension
except:
from distutils.core import setup, Extension, Command
Copy link
Member

Choose a reason for hiding this comment

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

should we keep this (but remove Command, looks like that's unused) as fallback for earlier versions of python? (although I'm not familiar of what scenario will have no setuptools but distutils)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look, @fishy! Do you know what the Thrift support guidelines are for older python versions? e.g. We have a followup PR to add better type support, ty type checking, etc. but that's dependent on more modern python versions. The guidelines in LANGUAGES.md appear pretty outdated (i.e. python 3.6.8 is the latest supported).

Would we be open to specifying that EOL python versions are not supported (currently 3.9 and older are EOL, with 3.10 scheduled to go EOL in October 2026)? That would make it much easier to evolve type support and modernize the codebase.

In this case, I think relying on setuptools >= 61.0 and dropping distutils limits us to python 3.7+, which seems very reasonable.

Copy link
Member

Choose a reason for hiding this comment

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

there's no single support guideline for older language versions (each language has their own), but don't support EOL versions is a very reasonable and common approach.

try:
from setuptools import setup, Extension
except Exception:
from distutils.core import setup, Extension
Copy link
Member

Choose a reason for hiding this comment

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

same question here regarding fallback to earlier versions of python

@Jens-G Jens-G added the python label Jan 7, 2026
phlax added a commit to envoyproxy/envoy that referenced this pull request Jan 8, 2026
switching to just building as a source allows us to patch in
apache/thrift#3276

once that has landed/published we can switch back to pypi


Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: phlax <[email protected]>
@mergeable mergeable bot added the github_actions Pull requests that update GitHub Actions code label Jan 14, 2026
run: make -C test/py check

lib-python-macos:
needs: compiler-macos
Copy link
Member

Choose a reason for hiding this comment

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

can this also be a matrix instead? (I'm not familiar with github actions enough so it's totally fine if this is not supported)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fishy Thanks - let me give it a try.

runs-on: macos-14
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
Copy link
Member

Choose a reason for hiding this comment

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

if needs cannot be a matrix, I wonder whether we can define this as a "variable" somewhere in this yaml, so when we change the supported python versions in the future we only need to change one place.


- name: Python setup
run: |
python -m pip install --upgrade pip setuptools wheel flake8 tornado twisted zope.interface
Copy link
Member

Choose a reason for hiding this comment

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

similar here on possibility to define the list as a variable

@mergeable mergeable bot added the c++ label Jan 14, 2026
@greggdonovan greggdonovan changed the title Fix Python 3.12 build issues in thrift Python THRIFT-5915: Fix Python 3.12 build issues in thrift Python Jan 15, 2026
@mergeable mergeable bot added the nodejs label Jan 15, 2026
@greggdonovan greggdonovan marked this pull request as ready for review January 15, 2026 17:18
@greggdonovan greggdonovan requested a review from fishy January 15, 2026 17:18
@greggdonovan
Copy link
Contributor Author

@fishy - I think this is ready for another look. I have another PR I'm working on for THRIFT-5537 - "drop eol python versions" - but it probably makes sense to keep that separate. Thanks!

Copy link
Member

@fishy fishy left a comment

Choose a reason for hiding this comment

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

looks like everything is working now! thank you.

can you please squash the commits so I can merge it?

strategy:
matrix:
os: *macos_versions
python-version: *python_versions
Copy link
Member

Choose a reason for hiding this comment

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

nice

- Add pyproject.toml with setuptools build requirement for PEP 517 compliance
- Replace distutils imports with setuptools equivalents
- Use setuptools error names directly (CompileError, ExecError, PlatformError)
- Fix macOS header collision with ntohll/htonll macros in endian.h
- Add a matrix of MacOS versions (macos-15-intel, macos-14, macos-15,
  macos-26)
- Add a matrix of non-EOL Python versions for testing
- Remove MSVC2015 from the test matrix (very old).
- Support MSVC2022, the latest in AppVeyor.
- Upgrade tornado, twisted, and zope.interface versions to the first
  that support Python 3.12.
- Try to make the test_socket, RunClientServer, and TestServer tests less flaky.

This fixes the ModuleNotFoundError: No module named 'distutils' error
when building thrift with Python 3.12+.
@greggdonovan
Copy link
Contributor Author

can you please squash the commits so I can merge it?

Done! Thanks for taking a look. I have a PR coming after this one to clean up the old Python versions (including old py2 code). Thanks for all the help!

@fishy fishy merged commit 62ec929 into apache:master Jan 29, 2026
66 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ github_actions Pull requests that update GitHub Actions code nodejs python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants