@@ -928,17 +928,7 @@ def tag_platform(self):
928928 ret = ret .replace ('-' , '_' ).replace ('.' , '_' ).lower ()
929929 log0 (f'From sysconfig.get_platform(): { ret = } .' )
930930
931- # We need to patch things on MacOS.
932- #
933- # E.g. `foo-1.2.3-cp311-none-macosx_13_x86_64.whl`
934- # causes `pip` to fail with: `not a supported wheel on this
935- # platform`. We seem to need to add `_0` to the OS version.
936- #
937- m = re .match ( '^(macosx_[0-9]+)(_[^0-9].+)$' , ret )
938- if m :
939- ret2 = f'{ m .group (1 )} _0{ m .group (2 )} '
940- log0 (f'After macos patch, changing from { ret !r} to { ret2 !r} .' )
941- ret = ret2
931+ ret = _macos_fixup_platform_tag (ret )
942932
943933 log0 ( f'tag_platform(): returning { ret = } .' )
944934 assert '-' not in ret
@@ -2623,6 +2613,37 @@ def macos_patch( library, *sublibraries):
26232613 subprocess .run ( f'otool -L { library } ' , shell = 1 , check = 1 )
26242614
26252615
2616+ def _macos_fixup_platform_tag (tag ):
2617+ '''
2618+ Patch up platform tag on MacOS.
2619+
2620+ E.g. `foo-1.2.3-cp311-none-macosx_13_x86_64.whl` causes `pip` to fail with:
2621+ `not a supported wheel on this platform`. We seem to need to add `_0` to
2622+ the OS version.
2623+
2624+ And we replace trailing `universal2` with x86_64 or arm64, because we don't
2625+ create universal wheels.
2626+
2627+ >>> pt = _macos_fixup_platform_tag('macosx_10_13_universal2')
2628+ >>> assert pt == f'macosx_10_13_{platform.machine()}'
2629+ >>> pt = _macos_fixup_platform_tag('macosx_13_universal2')
2630+ >>> assert pt == f'macosx_13_0_{platform.machine()}', f'{pt=}'
2631+ '''
2632+ m = re .match ( '^macosx_([0-9_]+)_([^0-9].+)$' , tag )
2633+ if not m :
2634+ return tag
2635+ a = m .group (1 )
2636+ if '_' not in a :
2637+ a += '_0'
2638+ b = m .group (2 )
2639+ if b == 'universal2' :
2640+ # Replace with x86_64 or arm64.
2641+ b = platform .machine ()
2642+ ret = f'macosx_{ a } _{ b } '
2643+ #log0(f'Changing from {tag=} to {ret=}.')
2644+ return ret
2645+
2646+
26262647# Internal helpers.
26272648#
26282649
0 commit comments