Skip to content

Commit 1b50800

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

2 files changed

Lines changed: 23 additions & 16 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: 22 additions & 15 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):
@@ -48,12 +46,19 @@ def copy_binary_files(net_rid: str):
4846

4947

5048
class bdist_wheel_abi3(bdist_wheel):
51-
def finalize_options(self):
52-
super().finalize_options()
49+
def get_tag(self) -> Tuple[str, str, str]:
5350
self.root_is_pure = False
51+
python, abi, plat = super().get_tag()
52+
self.root_is_pure = True
53+
if python.startswith("cp"):
54+
# on CPython, our wheels are abi3 and compatible back to 3.7
55+
return "cp36", "abi3", plat
56+
return python, abi, plat
57+
5458

59+
class build_ext_c(build_ext):
5560
def run(self):
56-
platform_tag = self.get_tag()[2]
61+
platform_tag = self.plat_name.replace("-", "_")
5762
if platform_tag.startswith("win"):
5863
net_rid = BDIST_TAG_MAP_WIN[platform_tag]
5964
elif platform_tag.startswith("macosx"):
@@ -65,14 +70,16 @@ def run(self):
6570
copy_binary_files(net_rid)
6671
super().run()
6772

68-
def get_tag(self) -> Tuple[str, str, str]:
69-
python, abi, plat = super().get_tag()
70-
if python.startswith("cp"):
71-
# on CPython, our wheels are abi3 and compatible back to 3.7
72-
return "cp36", "abi3", plat
73-
return python, abi, plat
73+
74+
class UnpureDistribution(Distribution):
75+
"""Distribution which is not marked as pure, so that wheels are built as platform-specific"""
76+
77+
def is_pure(self) -> bool:
78+
return False
7479

7580

7681
setup(
77-
cmdclass={"bdist_wheel": bdist_wheel_abi3},
82+
cmdclass={"bdist_wheel": bdist_wheel_abi3, "build_ext": build_ext_c},
83+
distclass=UnpureDistribution,
84+
zip_safe=False,
7885
)

0 commit comments

Comments
 (0)