33from typing import Tuple
44
55from 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
1311def 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
3545BDIST_TAG_MAP_WIN = {
@@ -48,31 +58,37 @@ def copy_binary_files(net_rid: str):
4858
4959
5060class 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+
7690setup (
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