Skip to content

Commit 63d239f

Browse files
committed
1. Provide a fallback mechanism for determining ABI flags if config vars
are unavailable, but issue a warning if this is used. 2. Explicitly handle the case where the unicode detection finds wide unicode but this is a 3.3+ build (necessary due to #1) 3. Fix tests broken due to pypa#2.
1 parent 1b5b4ac commit 63d239f

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

pip/pep425tags.py

+31-4
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,42 @@ def get_impl_version_info():
5555
return sys.version_info[0], sys.version_info[1]
5656

5757

58+
def get_flag(var, fallback, expected=True, warn=True):
59+
"""Use a fallback method for determining SOABI flags if the needed config
60+
var is unset or unavailable."""
61+
val = get_config_var(var)
62+
if val is None:
63+
if warn:
64+
warnings.warn("Config variable '{0}' is unset, Python ABI tag may "
65+
"be incorrect".format(var), RuntimeWarning, 2)
66+
return fallback()
67+
return val == expected
68+
69+
5870
def get_abi_tag():
5971
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
6072
(CPython 2, PyPy)."""
6173
soabi = get_config_var('SOABI')
6274
impl = get_abbr_impl()
63-
if not soabi and impl in ('cp', 'pp'):
64-
d = 'd' if get_config_var('Py_DEBUG') else ''
65-
m = 'm' if get_config_var('WITH_PYMALLOC') else ''
66-
u = 'u' if get_config_var('Py_UNICODE_SIZE') == 4 else ''
75+
if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'):
76+
d = ''
77+
m = ''
78+
u = ''
79+
if get_flag('Py_DEBUG',
80+
lambda: hasattr(sys, 'gettotalrefcount'),
81+
warn=(impl == 'cp')):
82+
d = 'd'
83+
if get_flag('WITH_PYMALLOC',
84+
lambda: impl == 'cp',
85+
warn=(impl == 'cp')):
86+
m = 'm'
87+
if get_flag('Py_UNICODE_SIZE',
88+
lambda: sys.maxunicode == 0x10ffff,
89+
expected=4,
90+
warn=(impl == 'cp' and
91+
sys.version_info < (3, 3))) \
92+
and sys.version_info < (3, 3):
93+
u = 'u'
6794
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
6895
elif soabi and soabi.startswith('cpython-'):
6996
abi = 'cp' + soabi.split('-')[1]

tests/unit/test_wheel.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for wheel binary packages and .dist-info."""
22
import os
3+
import sys
34

45
import pytest
56
from mock import patch, Mock
@@ -317,26 +318,28 @@ def abi_tag_unicode(self, flags, config_vars):
317318
config_vars.update({'SOABI': None})
318319
base = pip.pep425tags.get_abbr_impl() + pip.pep425tags.get_impl_ver()
319320

320-
config_vars.update({'Py_UNICODE_SIZE': 2})
321-
mock_gcf = self.mock_get_config_var(**config_vars)
322-
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
323-
abi_tag = pip.pep425tags.get_abi_tag()
324-
assert abi_tag == base + flags
325-
326-
config_vars.update({'Py_UNICODE_SIZE': 4})
327-
mock_gcf = self.mock_get_config_var(**config_vars)
328-
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
329-
abi_tag = pip.pep425tags.get_abi_tag()
330-
assert abi_tag == base + flags + 'u'
331-
332-
# On Python >= 3.3, UCS-4 is essentially permanently enabled, and
333-
# Py_UNICODE_SIZE is None. SOABI on these builds does not include the
334-
# 'u' so manual SOABI detection should not do so either.
335-
config_vars.update({'Py_UNICODE_SIZE': None})
336-
mock_gcf = self.mock_get_config_var(**config_vars)
337-
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
338-
abi_tag = pip.pep425tags.get_abi_tag()
339-
assert abi_tag == base + flags
321+
if sys.version_info < (3, 3):
322+
config_vars.update({'Py_UNICODE_SIZE': 2})
323+
mock_gcf = self.mock_get_config_var(**config_vars)
324+
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
325+
abi_tag = pip.pep425tags.get_abi_tag()
326+
assert abi_tag == base + flags
327+
328+
config_vars.update({'Py_UNICODE_SIZE': 4})
329+
mock_gcf = self.mock_get_config_var(**config_vars)
330+
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
331+
abi_tag = pip.pep425tags.get_abi_tag()
332+
assert abi_tag == base + flags + 'u'
333+
334+
else:
335+
# On Python >= 3.3, UCS-4 is essentially permanently enabled, and
336+
# Py_UNICODE_SIZE is None. SOABI on these builds does not include
337+
# the 'u' so manual SOABI detection should not do so either.
338+
config_vars.update({'Py_UNICODE_SIZE': None})
339+
mock_gcf = self.mock_get_config_var(**config_vars)
340+
with patch('pip.pep425tags.sysconfig.get_config_var', mock_gcf):
341+
abi_tag = pip.pep425tags.get_abi_tag()
342+
assert abi_tag == base + flags
340343

341344
def test_broken_sysconfig(self):
342345
"""

0 commit comments

Comments
 (0)