Skip to content

Commit 868671a

Browse files
committed
Merge pull request #1465 from minrk/osxarch
Support earlier OS X versions in wheels
2 parents 736400d + 27f4471 commit 868671a

File tree

2 files changed

+116
-2
lines changed

2 files changed

+116
-2
lines changed

pip/pep425tags.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Generate and work with PEP 425 Compatibility Tags."""
22

3+
import re
34
import sys
45
import warnings
56

@@ -10,6 +11,8 @@
1011
import distutils.sysconfig as sysconfig
1112
import distutils.util
1213

14+
_osx_arch_pat = re.compile(r'(.+)_(\d+)_(\d+)_(.+)')
15+
1316

1417
def get_abbr_impl():
1518
"""Return abbreviated implementation name."""
@@ -77,10 +80,37 @@ def get_supported(versions=None, noarch=False):
7780

7881
if not noarch:
7982
arch = get_platform()
83+
if sys.platform == 'darwin':
84+
# support macosx-10.6-intel on macosx-10.9-x86_64
85+
match = _osx_arch_pat.match(arch)
86+
if match:
87+
name, major, minor, actual_arch = match.groups()
88+
actual_arches = [actual_arch]
89+
if actual_arch in ('i386', 'ppc'):
90+
actual_arches.append('fat')
91+
if actual_arch in ('i386', 'x86_64'):
92+
actual_arches.append('intel')
93+
if actual_arch in ('i386', 'ppc', 'x86_64'):
94+
actual_arches.append('fat3')
95+
if actual_arch in ('ppc64', 'x86_64'):
96+
actual_arches.append('fat64')
97+
if actual_arch in ('i386', 'x86_64', 'intel', 'ppc', 'ppc64'):
98+
actual_arches.append('universal')
99+
tpl = '{0}_{1}_%i_%s'.format(name, major)
100+
arches = []
101+
for m in range(int(minor) + 1):
102+
for a in actual_arches:
103+
arches.append(tpl % (m, a))
104+
else:
105+
# arch pattern didn't match (?!)
106+
arches = [arch]
107+
else:
108+
arches = [arch]
80109

81110
# Current version, current API (built specifically for our Python):
82111
for abi in abis:
83-
supported.append(('%s%s' % (impl, versions[0]), abi, arch))
112+
for arch in arches:
113+
supported.append(('%s%s' % (impl, versions[0]), abi, arch))
84114

85115
# No abi / arch, but requires our implementation:
86116
for i, version in enumerate(versions):

tests/unit/test_wheel.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mock import patch, Mock
66

77
from pip._vendor import pkg_resources
8-
from pip import wheel
8+
from pip import pep425tags, wheel
99
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
1010
from pip.util import unpack_file
1111

@@ -149,6 +149,90 @@ def test_not_supported_version(self):
149149
w = wheel.Wheel('simple-0.1-py2-none-any.whl')
150150
assert not w.supported(tags=[('py1', 'none', 'any')])
151151

152+
@patch('sys.platform', 'darwin')
153+
@patch('pip.pep425tags.get_abbr_impl', lambda: 'cp')
154+
@patch('pip.pep425tags.get_platform', lambda: 'macosx_10_9_intel')
155+
def test_supported_osx_version(self):
156+
"""
157+
Wheels built for OS X 10.6 are supported on 10.9
158+
"""
159+
tags = pep425tags.get_supported(['27'], False)
160+
w = wheel.Wheel('simple-0.1-cp27-none-macosx_10_6_intel.whl')
161+
assert w.supported(tags=tags)
162+
w = wheel.Wheel('simple-0.1-cp27-none-macosx_10_9_intel.whl')
163+
assert w.supported(tags=tags)
164+
165+
@patch('sys.platform', 'darwin')
166+
@patch('pip.pep425tags.get_abbr_impl', lambda: 'cp')
167+
@patch('pip.pep425tags.get_platform', lambda: 'macosx_10_6_intel')
168+
def test_not_supported_osx_version(self):
169+
"""
170+
Wheels built for OS X 10.9 are not supported on 10.6
171+
"""
172+
tags = pep425tags.get_supported(['27'], False)
173+
w = wheel.Wheel('simple-0.1-cp27-none-macosx_10_9_intel.whl')
174+
assert not w.supported(tags=tags)
175+
176+
@patch('sys.platform', 'darwin')
177+
@patch('pip.pep425tags.get_abbr_impl', lambda: 'cp')
178+
def test_supported_multiarch_darwin(self):
179+
"""
180+
Multi-arch wheels (intel) are supported on components (i386, x86_64)
181+
"""
182+
with patch('pip.pep425tags.get_platform',
183+
lambda: 'macosx_10_5_universal'):
184+
universal = pep425tags.get_supported(['27'], False)
185+
with patch('pip.pep425tags.get_platform',
186+
lambda: 'macosx_10_5_intel'):
187+
intel = pep425tags.get_supported(['27'], False)
188+
with patch('pip.pep425tags.get_platform',
189+
lambda: 'macosx_10_5_x86_64'):
190+
x64 = pep425tags.get_supported(['27'], False)
191+
with patch('pip.pep425tags.get_platform',
192+
lambda: 'macosx_10_5_i386'):
193+
i386 = pep425tags.get_supported(['27'], False)
194+
with patch('pip.pep425tags.get_platform',
195+
lambda: 'macosx_10_5_ppc'):
196+
ppc = pep425tags.get_supported(['27'], False)
197+
with patch('pip.pep425tags.get_platform',
198+
lambda: 'macosx_10_5_ppc64'):
199+
ppc64 = pep425tags.get_supported(['27'], False)
200+
201+
w = wheel.Wheel('simple-0.1-cp27-none-macosx_10_5_intel.whl')
202+
assert w.supported(tags=intel)
203+
assert w.supported(tags=x64)
204+
assert w.supported(tags=i386)
205+
assert not w.supported(tags=universal)
206+
assert not w.supported(tags=ppc)
207+
assert not w.supported(tags=ppc64)
208+
w = wheel.Wheel('simple-0.1-cp27-none-macosx_10_5_universal.whl')
209+
assert w.supported(tags=universal)
210+
assert w.supported(tags=intel)
211+
assert w.supported(tags=x64)
212+
assert w.supported(tags=i386)
213+
assert w.supported(tags=ppc)
214+
assert w.supported(tags=ppc64)
215+
216+
@patch('sys.platform', 'darwin')
217+
@patch('pip.pep425tags.get_abbr_impl', lambda: 'cp')
218+
def test_not_supported_multiarch_darwin(self):
219+
"""
220+
Single-arch wheels (x86_64) are not supported on multi-arch (intel)
221+
"""
222+
with patch('pip.pep425tags.get_platform',
223+
lambda: 'macosx_10_5_universal'):
224+
universal = pep425tags.get_supported(['27'], False)
225+
with patch('pip.pep425tags.get_platform',
226+
lambda: 'macosx_10_5_intel'):
227+
intel = pep425tags.get_supported(['27'], False)
228+
229+
w = wheel.Wheel('simple-0.1-cp27-none-macosx_10_5_i386.whl')
230+
assert not w.supported(tags=intel)
231+
assert not w.supported(tags=universal)
232+
w = wheel.Wheel('simple-0.1-cp27-none-macosx_10_5_x86_64.whl')
233+
assert not w.supported(tags=intel)
234+
assert not w.supported(tags=universal)
235+
152236
def test_support_index_min(self):
153237
"""
154238
Test results from `support_index_min`

0 commit comments

Comments
 (0)