@@ -132,8 +132,9 @@ def build_wheel(
132132
133133 tdp = pathlib .Path (td )
134134 twhl = list (tdp .glob ("*.whl" ))[0 ]
135- dst_whl = wheel_path / self ._fix_wheel_name (twhl . name )
135+ dst_whl = wheel_path / self ._fix_wheel_name (twhl )
136136 shutil .move (twhl , dst_whl )
137+ print ("Wrote wheel to" , dst_whl )
137138
138139 if install :
139140 # Install the wheel
@@ -147,19 +148,46 @@ def build_wheel(
147148 )
148149
149150 _adjust_wheel_tags = {
150- # pypi only accepts manylinux wheels, and we know we're compatible
151- # TODO(davo): use auditwheel to fix the tags instead
152- "linux_x86_64" : "manylinux_2_35_x86_64" ,
153- "linux_aarch64" : "manylinux_2_36_aarch64" ,
154151 # needed for compatibility with python compiled with older xcode
155152 "macosx_11_0_x86_64" : "macosx_10_16_x86_64" ,
156153 "macosx_12_0_x86_64" : "macosx_10_16_x86_64" ,
157154 }
158155
159- def _fix_wheel_name (self , name : str ) -> str :
160- for old , new in self ._adjust_wheel_tags .items ():
161- old_whl = f"{ old } .whl"
162- new_whl = f"{ new } .whl"
163- if name .endswith (old_whl ):
164- name = f"{ name [:- len (old_whl )]} { new_whl } "
156+ def _fix_wheel_name (self , wheel_path : pathlib .Path ) -> str :
157+ if sys .platform == "linux" :
158+ name = self ._fix_linux_wheel_name (wheel_path )
159+ else :
160+ name = wheel_path .name
161+ for old , new in self ._adjust_wheel_tags .items ():
162+ old_whl = f"{ old } .whl"
163+ new_whl = f"{ new } .whl"
164+ if name .endswith (old_whl ):
165+ name = f"{ name [:- len (old_whl )]} { new_whl } "
166+
165167 return name
168+
169+ def _fix_linux_wheel_name (self , wheel_path : pathlib .Path ) -> str :
170+ # inspired by https://github.com/hsorby/renamewheel, Apache license
171+
172+ from auditwheel .error import NonPlatformWheel , WheelToolsError
173+ from auditwheel .wheel_abi import analyze_wheel_abi
174+ from auditwheel .wheeltools import get_wheel_architecture , get_wheel_libc
175+
176+ try :
177+ arch = get_wheel_architecture (wheel_path .name )
178+ except (WheelToolsError , NonPlatformWheel ):
179+ arch = None
180+
181+ try :
182+ libc = get_wheel_libc (wheel_path .name )
183+ except WheelToolsError :
184+ libc = None
185+
186+ try :
187+ winfo = analyze_wheel_abi (libc , arch , wheel_path , frozenset (), True , True )
188+ except NonPlatformWheel :
189+ return wheel_path .name
190+ else :
191+ parts = wheel_path .name .split ("-" )
192+ parts [- 1 ] = winfo .overall_policy .name
193+ return "-" .join (parts ) + ".whl"
0 commit comments