2012-10-12 10:36:05 +02:00
|
|
|
"""Generate and work with PEP 425 Compatibility Tags."""
|
2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
2012-10-12 10:36:05 +02:00
|
|
|
|
2014-01-12 22:22:18 +01:00
|
|
|
import re
|
2012-10-12 10:36:05 +02:00
|
|
|
import sys
|
2013-07-24 02:18:26 +02:00
|
|
|
import warnings
|
2012-10-12 10:36:05 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
import sysconfig
|
|
|
|
except ImportError: # pragma nocover
|
|
|
|
# Python < 2.7
|
|
|
|
import distutils.sysconfig as sysconfig
|
|
|
|
import distutils.util
|
|
|
|
|
2014-01-12 22:22:18 +01:00
|
|
|
_osx_arch_pat = re.compile(r'(.+)_(\d+)_(\d+)_(.+)')
|
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
|
2015-09-04 05:37:32 +02:00
|
|
|
def get_config_var(var):
|
|
|
|
try:
|
|
|
|
return sysconfig.get_config_var(var)
|
|
|
|
except IOError as e: # Issue #1074
|
|
|
|
warnings.warn("{0}".format(e), RuntimeWarning)
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
def get_abbr_impl():
|
|
|
|
"""Return abbreviated implementation name."""
|
|
|
|
if hasattr(sys, 'pypy_version_info'):
|
|
|
|
pyimpl = 'pp'
|
|
|
|
elif sys.platform.startswith('java'):
|
|
|
|
pyimpl = 'jy'
|
|
|
|
elif sys.platform == 'cli':
|
|
|
|
pyimpl = 'ip'
|
|
|
|
else:
|
|
|
|
pyimpl = 'cp'
|
|
|
|
return pyimpl
|
|
|
|
|
|
|
|
|
|
|
|
def get_impl_ver():
|
|
|
|
"""Return implementation version."""
|
2015-09-04 05:37:32 +02:00
|
|
|
impl_ver = get_config_var("py_version_nodot")
|
2015-09-03 18:32:51 +02:00
|
|
|
if not impl_ver or get_abbr_impl() == 'pp':
|
|
|
|
impl_ver = ''.join(map(str, get_impl_version_info()))
|
|
|
|
return impl_ver
|
|
|
|
|
|
|
|
|
|
|
|
def get_impl_version_info():
|
|
|
|
"""Return sys.version_info-like tuple for use in decrementing the minor
|
|
|
|
version."""
|
|
|
|
if get_abbr_impl() == 'pp':
|
|
|
|
# as per https://github.com/pypa/pip/issues/2882
|
|
|
|
return (sys.version_info[0], sys.pypy_version_info.major,
|
|
|
|
sys.pypy_version_info.minor)
|
|
|
|
else:
|
|
|
|
return sys.version_info[0], sys.version_info[1]
|
|
|
|
|
|
|
|
|
2015-11-04 14:11:13 +01:00
|
|
|
def get_impl_tag():
|
|
|
|
"""
|
|
|
|
Returns the Tag for this specific implementation.
|
|
|
|
"""
|
|
|
|
return "{0}{1}".format(get_abbr_impl(), get_impl_ver())
|
|
|
|
|
|
|
|
|
2015-10-13 21:58:03 +02:00
|
|
|
def get_flag(var, fallback, expected=True, warn=True):
|
|
|
|
"""Use a fallback method for determining SOABI flags if the needed config
|
|
|
|
var is unset or unavailable."""
|
|
|
|
val = get_config_var(var)
|
|
|
|
if val is None:
|
|
|
|
if warn:
|
|
|
|
warnings.warn("Config variable '{0}' is unset, Python ABI tag may "
|
|
|
|
"be incorrect".format(var), RuntimeWarning, 2)
|
|
|
|
return fallback()
|
|
|
|
return val == expected
|
|
|
|
|
|
|
|
|
2015-09-03 18:32:51 +02:00
|
|
|
def get_abi_tag():
|
|
|
|
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
|
|
|
|
(CPython 2, PyPy)."""
|
2015-09-04 05:37:32 +02:00
|
|
|
soabi = get_config_var('SOABI')
|
2015-09-03 18:32:51 +02:00
|
|
|
impl = get_abbr_impl()
|
2015-10-13 21:58:03 +02:00
|
|
|
if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'):
|
|
|
|
d = ''
|
|
|
|
m = ''
|
|
|
|
u = ''
|
|
|
|
if get_flag('Py_DEBUG',
|
|
|
|
lambda: hasattr(sys, 'gettotalrefcount'),
|
|
|
|
warn=(impl == 'cp')):
|
|
|
|
d = 'd'
|
|
|
|
if get_flag('WITH_PYMALLOC',
|
|
|
|
lambda: impl == 'cp',
|
|
|
|
warn=(impl == 'cp')):
|
|
|
|
m = 'm'
|
|
|
|
if get_flag('Py_UNICODE_SIZE',
|
|
|
|
lambda: sys.maxunicode == 0x10ffff,
|
|
|
|
expected=4,
|
|
|
|
warn=(impl == 'cp' and
|
|
|
|
sys.version_info < (3, 3))) \
|
|
|
|
and sys.version_info < (3, 3):
|
|
|
|
u = 'u'
|
2015-09-03 18:32:51 +02:00
|
|
|
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
|
|
|
|
elif soabi and soabi.startswith('cpython-'):
|
2015-09-03 19:09:41 +02:00
|
|
|
abi = 'cp' + soabi.split('-')[1]
|
2015-09-03 18:32:51 +02:00
|
|
|
elif soabi:
|
2015-09-03 19:09:41 +02:00
|
|
|
abi = soabi.replace('.', '_').replace('-', '_')
|
2015-09-03 18:32:51 +02:00
|
|
|
else:
|
|
|
|
abi = None
|
|
|
|
return abi
|
2012-10-12 10:36:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_platform():
|
|
|
|
"""Return our platform name 'win32', 'linux_x86_64'"""
|
|
|
|
# XXX remove distutils dependency
|
|
|
|
return distutils.util.get_platform().replace('.', '_').replace('-', '_')
|
|
|
|
|
|
|
|
|
2013-06-30 20:15:03 +02:00
|
|
|
def get_supported(versions=None, noarch=False):
|
2012-10-12 10:36:05 +02:00
|
|
|
"""Return a list of supported tags for each version specified in
|
|
|
|
`versions`.
|
|
|
|
|
2013-04-02 07:44:46 +02:00
|
|
|
:param versions: a list of string versions, of the form ["33", "32"],
|
2012-10-12 10:36:05 +02:00
|
|
|
or None. The first version will be assumed to support our ABI.
|
|
|
|
"""
|
|
|
|
supported = []
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
# Versions must be given with respect to the preference
|
|
|
|
if versions is None:
|
|
|
|
versions = []
|
2015-09-03 18:32:51 +02:00
|
|
|
version_info = get_impl_version_info()
|
|
|
|
major = version_info[:-1]
|
2012-10-12 10:36:05 +02:00
|
|
|
# Support all previous minor Python versions.
|
2015-09-03 18:32:51 +02:00
|
|
|
for minor in range(version_info[-1], -1, -1):
|
|
|
|
versions.append(''.join(map(str, major + (minor,))))
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
impl = get_abbr_impl()
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
abis = []
|
2013-07-28 05:46:55 +02:00
|
|
|
|
2015-09-03 18:32:51 +02:00
|
|
|
abi = get_abi_tag()
|
|
|
|
if abi:
|
|
|
|
abis[0:0] = [abi]
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
abi3s = set()
|
|
|
|
import imp
|
|
|
|
for suffix in imp.get_suffixes():
|
|
|
|
if suffix[0].startswith('.abi'):
|
|
|
|
abi3s.add(suffix[0].split('.', 2)[1])
|
|
|
|
|
|
|
|
abis.extend(sorted(list(abi3s)))
|
|
|
|
|
|
|
|
abis.append('none')
|
|
|
|
|
2013-06-30 20:15:03 +02:00
|
|
|
if not noarch:
|
|
|
|
arch = get_platform()
|
2014-01-12 22:22:18 +01:00
|
|
|
if sys.platform == 'darwin':
|
2014-03-07 02:51:51 +01:00
|
|
|
# support macosx-10.6-intel on macosx-10.9-x86_64
|
2014-01-12 22:22:18 +01:00
|
|
|
match = _osx_arch_pat.match(arch)
|
|
|
|
if match:
|
|
|
|
name, major, minor, actual_arch = match.groups()
|
2014-02-24 07:59:57 +01:00
|
|
|
actual_arches = [actual_arch]
|
2014-03-07 02:51:51 +01:00
|
|
|
if actual_arch in ('i386', 'ppc'):
|
|
|
|
actual_arches.append('fat')
|
2014-02-24 07:59:57 +01:00
|
|
|
if actual_arch in ('i386', 'x86_64'):
|
|
|
|
actual_arches.append('intel')
|
2014-03-07 02:51:51 +01:00
|
|
|
if actual_arch in ('ppc64', 'x86_64'):
|
|
|
|
actual_arches.append('fat64')
|
2015-10-05 20:52:53 +02:00
|
|
|
if actual_arch in ('i386', 'ppc', 'x86_64'):
|
|
|
|
actual_arches.append('fat32')
|
2014-02-24 07:59:57 +01:00
|
|
|
if actual_arch in ('i386', 'x86_64', 'intel', 'ppc', 'ppc64'):
|
|
|
|
actual_arches.append('universal')
|
|
|
|
tpl = '{0}_{1}_%i_%s'.format(name, major)
|
|
|
|
arches = []
|
2015-10-05 20:53:14 +02:00
|
|
|
for m in reversed(range(int(minor) + 1)):
|
2014-02-24 07:59:57 +01:00
|
|
|
for a in actual_arches:
|
|
|
|
arches.append(tpl % (m, a))
|
2014-01-12 22:22:18 +01:00
|
|
|
else:
|
|
|
|
# arch pattern didn't match (?!)
|
|
|
|
arches = [arch]
|
|
|
|
else:
|
|
|
|
arches = [arch]
|
2013-07-28 05:46:55 +02:00
|
|
|
|
2013-06-30 20:15:03 +02:00
|
|
|
# Current version, current API (built specifically for our Python):
|
|
|
|
for abi in abis:
|
2014-01-12 22:22:18 +01:00
|
|
|
for arch in arches:
|
|
|
|
supported.append(('%s%s' % (impl, versions[0]), abi, arch))
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2015-03-18 02:01:40 +01:00
|
|
|
# Has binaries, does not use the Python API:
|
2015-03-17 22:40:28 +01:00
|
|
|
supported.append(('py%s' % (versions[0][0]), 'none', arch))
|
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
# No abi / arch, but requires our implementation:
|
|
|
|
for i, version in enumerate(versions):
|
|
|
|
supported.append(('%s%s' % (impl, version), 'none', 'any'))
|
|
|
|
if i == 0:
|
2013-04-02 07:44:46 +02:00
|
|
|
# Tagged specifically as being cross-version compatible
|
2012-10-12 10:36:05 +02:00
|
|
|
# (with just the major version specified)
|
2013-04-02 07:44:46 +02:00
|
|
|
supported.append(('%s%s' % (impl, versions[0][0]), 'none', 'any'))
|
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
# No abi / arch, generic Python
|
|
|
|
for i, version in enumerate(versions):
|
|
|
|
supported.append(('py%s' % (version,), 'none', 'any'))
|
|
|
|
if i == 0:
|
|
|
|
supported.append(('py%s' % (version[0]), 'none', 'any'))
|
2013-04-02 07:44:46 +02:00
|
|
|
|
2012-10-12 10:36:05 +02:00
|
|
|
return supported
|
|
|
|
|
2013-04-02 07:44:46 +02:00
|
|
|
supported_tags = get_supported()
|
2013-06-30 20:15:03 +02:00
|
|
|
supported_tags_noarch = get_supported(noarch=True)
|
2015-11-04 14:11:13 +01:00
|
|
|
|
|
|
|
implementation_tag = get_impl_tag()
|