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

Skip to content

Commit ed73c20

Browse files
greggdonovanclaude
andcommitted
Fix Python 3.12 build issues in thrift Python
- 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 <[email protected]>
1 parent b8f7e5b commit ed73c20

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

contrib/fb303/py/setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
#
2121

2222
import sys
23-
try:
24-
from setuptools import setup, Extension
25-
except:
26-
from distutils.core import setup, Extension, Command
23+
24+
from setuptools import Extension, setup
2725

2826
setup(name='thrift_fb303',
2927
version='1.0.0',

lib/py/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0"]
3+
build-backend = "setuptools.build_meta"

lib/py/setup.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
#
2121

2222
import sys
23-
try:
24-
from setuptools import setup, Extension
25-
except Exception:
26-
from distutils.core import setup, Extension
2723

28-
from distutils.command.build_ext import build_ext
29-
from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError
24+
from setuptools import Extension, setup
25+
from setuptools.command.build_ext import build_ext
26+
from setuptools.errors import CompileError, ExecError, PlatformError
3027

3128
# Fix to build sdist under vagrant
3229
import os
@@ -39,9 +36,9 @@
3936
include_dirs = ['src']
4037
if sys.platform == 'win32':
4138
include_dirs.append('compat/win32')
42-
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError, IOError)
39+
ext_errors = (CompileError, ExecError, PlatformError, IOError)
4340
else:
44-
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
41+
ext_errors = (CompileError, ExecError, PlatformError)
4542

4643

4744
class BuildFailed(Exception):
@@ -52,7 +49,7 @@ class ve_build_ext(build_ext):
5249
def run(self):
5350
try:
5451
build_ext.run(self)
55-
except DistutilsPlatformError:
52+
except PlatformError:
5653
raise BuildFailed()
5754

5855
def build_extension(self, ext):

lib/py/src/ext/endian.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#else
3030
#include <netinet/in.h>
3131

32+
#ifndef ntohll
3233
static inline unsigned long long ntohll(unsigned long long n) {
3334
union {
3435
unsigned long long f;
@@ -43,8 +44,11 @@ static inline unsigned long long ntohll(unsigned long long n) {
4344
| static_cast<unsigned long long>(u.t[5]) << 16
4445
| static_cast<unsigned long long>(u.t[6]) << 8 | static_cast<unsigned long long>(u.t[7]);
4546
}
47+
#endif
4648

49+
#ifndef htonll
4750
#define htonll(n) ntohll(n)
51+
#endif
4852

4953
#endif // !_WIN32
5054

0 commit comments

Comments
 (0)