Skip to content

Conversation

@greggdonovan
Copy link

@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
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] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
@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
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

- 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

This fixes the ModuleNotFoundError: No module named 'distutils' error
when building thrift with Python 3.12+.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@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
greggdonovan and others added 17 commits January 15, 2026 11:32
The system bison (2.3) doesn't support the %code directive.
Add homebrew's bison to GITHUB_PATH so it persists across all steps.

Co-Authored-By: Claude <noreply@anthropic.com>
make -C test/cpp TestServer

  src/TestServer.cpp:599:9: error: no viable conversion from '__bind<int &, sockaddr *, unsigned long>' to 'int'
    599 |     int rv = bind(socket_fd, (struct sockaddr*)&sa, sizeof(sa));
        |         ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@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
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!

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