Skip to content

Commit 5741598

Browse files
committed
Add macOS arm64 & universal2 compatible wheel
1 parent a75ec97 commit 5741598

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

scikit-ci.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,25 @@ test:
117117
commands:
118118
# Convert to generic platform wheel
119119
- python: |
120-
import glob, sys
120+
import glob, os, sys
121121
sys.path.insert(0, "./scripts")
122122
from convert_to_generic_platform_wheel import convert_to_generic_platform_wheel
123123
wheels = glob.glob("dist/*.whl")
124+
additional_platforms = []
125+
if "MACOSX_DEPLOYMENT_TARGET" in os.environ:
126+
target = tuple(int(p) for p in os.environ["MACOSX_DEPLOYMENT_TARGET"].split("."))
127+
if target == (10, 13):
128+
# let's add universal2 platform for this wheel.
129+
# given pip support for universal2 was added after arm64 introduction
130+
# let's also add arm64 platform.
131+
# They're were also issues with pip not picking up some universal2 wheels, tag twice
132+
additional_platforms = [
133+
"macosx_10_13_universal2",
134+
"macosx_11_0_universal2",
135+
"macosx_11_0_arm64",
136+
]
124137
for wheel in wheels:
125-
convert_to_generic_platform_wheel(wheel, remove_original=True)
138+
convert_to_generic_platform_wheel(wheel, remove_original=True, additional_platforms=additional_platforms)
126139
127140
appveyor:
128141
commands:

scripts/convert_to_generic_platform_wheel.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _to_generic_pyver(pyver_tags):
4141
return ['py%s' % tag[2] if tag.startswith('cp') else tag for tag in pyver_tags]
4242

4343

44-
def _convert_to_generic_platform_wheel(wheel_ctx):
44+
def _convert_to_generic_platform_wheel(wheel_ctx, additional_platforms):
4545
"""Switch to generic python tags and remove ABI tags from a wheel
4646
4747
Convert implementation specific python tags to their generic equivalent and
@@ -51,6 +51,8 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
5151
----------
5252
wheel_ctx : InWheelCtx
5353
An open wheel context
54+
additional_platforms : Optional[Iterable[str]]
55+
An optional iterable of additional platform to add to the wheel
5456
"""
5557

5658
abi_tags = ['none']
@@ -69,7 +71,14 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
6971

7072
# Update wheel filename
7173
fparts = wf.parsed_filename.groupdict()
72-
original_platform_tags = fparts['plat'].split('.')
74+
platform_tags = fparts['plat'].split('.')
75+
logger.debug('Previous platform tags: %s', ', '.join(platform_tags))
76+
if additional_platforms:
77+
platform_tags = list(sorted(set(platform_tags + [p for p in additional_platforms])))
78+
fparts['plat'] = '.'.join(platform_tags)
79+
logger.debug('New platform tags ....: %s', ', '.join(platform_tags))
80+
else:
81+
logger.debug('No platform tags change needed.')
7382

7483
original_abi_tags = fparts['abi'].split('.')
7584
logger.debug('Previous ABI tags: %s', ', '.join(original_abi_tags))
@@ -114,7 +123,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
114123
pyc_apis = unique_by_index(pyc_apis)
115124

116125
# Set tags for each Python version, C-API combination
117-
updated_tags = ['-'.join(tup) for tup in product(pyc_apis, original_platform_tags)]
126+
updated_tags = ['-'.join(tup) for tup in product(pyc_apis, platform_tags)]
118127

119128
if updated_tags != in_info_tags:
120129
del info['Tag']
@@ -128,7 +137,7 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
128137
return out_wheel
129138

130139

131-
def convert_to_generic_platform_wheel(wheel_path, out_dir='./dist/', remove_original=False, verbose=0):
140+
def convert_to_generic_platform_wheel(wheel_path, out_dir='./dist/', remove_original=False, verbose=0, additional_platforms=None):
132141
logging.disable(logging.NOTSET)
133142
if verbose >= 1:
134143
logging.basicConfig(level=logging.DEBUG)
@@ -140,7 +149,7 @@ def convert_to_generic_platform_wheel(wheel_path, out_dir='./dist/', remove_orig
140149

141150
with InWheelCtx(wheel_path) as ctx:
142151
ctx.out_wheel = pjoin(out_dir, wheel_fname)
143-
ctx.out_wheel = _convert_to_generic_platform_wheel(ctx)
152+
ctx.out_wheel = _convert_to_generic_platform_wheel(ctx, additional_platforms)
144153

145154
if remove_original:
146155
logger.info('Removed original wheel %s' % wheel_path)
@@ -175,7 +184,7 @@ def main():
175184
if not isfile(args.WHEEL_FILE):
176185
p.error('cannot access %s. No such file' % args.WHEEL_FILE)
177186

178-
convert_to_generic_platform_wheel(args.WHEEL_FILE, args.WHEEL_DIR, args.remove_original, args.verbose)
187+
convert_to_generic_platform_wheel(args.WHEEL_FILE, args.WHEEL_DIR, args.remove_original, args.verbose, additional_platforms)
179188

180189

181190
if __name__ == '__main__':

0 commit comments

Comments
 (0)