Skip to content

Commit 8de1a45

Browse files
committed
refreactor(py bindings): use modern setuptools, allow build_ext (copy files), disable purelib
1 parent 9fcc746 commit 8de1a45

2 files changed

Lines changed: 36 additions & 20 deletions

File tree

bindings/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=42", "wheel"]
2+
requires = ["setuptools>=70"]
33
build-backend = "setuptools.build_meta"
44

55
[project]

bindings/python/setup.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
from typing import Tuple
44

55
from setuptools import setup
6-
7-
try:
8-
from setuptools.command.bdist_wheel import bdist_wheel
9-
except ImportError:
10-
from wheel.bdist_wheel import bdist_wheel # type: ignore
6+
from setuptools.command.bdist_wheel import bdist_wheel
7+
from setuptools.command.build_ext import build_ext
8+
from setuptools.dist import Distribution
119

1210

1311
def copy_binary_files(net_rid: str):
@@ -30,6 +28,18 @@ def copy_binary_files(net_rid: str):
3028
shutil.copy(os.path.join(publish_dir, item), os.path.join(target_dir, item))
3129

3230

31+
def copy_binary_files_plat(platform_tag: str):
32+
if platform_tag.startswith("win"):
33+
net_rid = BDIST_TAG_MAP_WIN[platform_tag]
34+
elif platform_tag.startswith("macosx"):
35+
net_rid = next((v for k, v in BDIST_TAG_MAP_MAC.items() if platform_tag.endswith(k)))
36+
else:
37+
net_rid = next((v for k, v in BDIST_TAG_MAP_LINUX.items() if platform_tag.endswith(k)))
38+
if "musllinux" in platform_tag:
39+
net_rid = net_rid.replace("-", "-musl-")
40+
copy_binary_files(net_rid)
41+
42+
3343
# see:
3444
# https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
3545
BDIST_TAG_MAP_WIN = {
@@ -48,31 +58,37 @@ def copy_binary_files(net_rid: str):
4858

4959

5060
class bdist_wheel_abi3(bdist_wheel):
51-
def finalize_options(self):
52-
super().finalize_options()
53-
self.root_is_pure = False
54-
5561
def run(self):
5662
platform_tag = self.get_tag()[2]
57-
if platform_tag.startswith("win"):
58-
net_rid = BDIST_TAG_MAP_WIN[platform_tag]
59-
elif platform_tag.startswith("macosx"):
60-
net_rid = next((v for k, v in BDIST_TAG_MAP_MAC.items() if platform_tag.endswith(k)))
61-
else:
62-
net_rid = next((v for k, v in BDIST_TAG_MAP_LINUX.items() if platform_tag.endswith(k)))
63-
if "musllinux" in platform_tag:
64-
net_rid = net_rid.replace("-", "-musl-")
65-
copy_binary_files(net_rid)
63+
copy_binary_files_plat(platform_tag)
6664
super().run()
6765

6866
def get_tag(self) -> Tuple[str, str, str]:
67+
self.root_is_pure = False
6968
python, abi, plat = super().get_tag()
69+
self.root_is_pure = True
7070
if python.startswith("cp"):
7171
# on CPython, our wheels are abi3 and compatible back to 3.7
7272
return "cp36", "abi3", plat
7373
return python, abi, plat
7474

7575

76+
class build_ext_c(build_ext):
77+
def run(self):
78+
platform_tag = self.plat_name.replace("-", "_")
79+
copy_binary_files_plat(platform_tag)
80+
super().run()
81+
82+
83+
class UnpureDistribution(Distribution):
84+
"""Distribution which is not marked as pure, so that wheels are built as platform-specific"""
85+
86+
def is_pure(self) -> bool:
87+
return False
88+
89+
7690
setup(
77-
cmdclass={"bdist_wheel": bdist_wheel_abi3},
91+
cmdclass={"bdist_wheel": bdist_wheel_abi3, "build_ext": build_ext_c},
92+
distclass=UnpureDistribution,
93+
zip_safe=False,
7894
)

0 commit comments

Comments
 (0)