Skip to content

Commit

Permalink
use sys_tags from packaging, does it cover all cases?
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Mar 29, 2020
1 parent 6ec1dd2 commit 9c6dd62
Showing 1 changed file with 74 additions and 12 deletions.
86 changes: 74 additions & 12 deletions src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
from email.generator import Generator
import distutils
from distutils.core import Command
from distutils.sysconfig import get_python_version
from distutils.sysconfig import get_python_version, get_config_var
from distutils import log as logger
from glob import iglob
from shutil import rmtree
from warnings import warn
import warnings
from zipfile import ZIP_DEFLATED, ZIP_STORED

import packaging.tags
import pkg_resources
import platform

from .pkginfo import write_pkg_info
from .metadata import pkginfo_to_metadata
Expand Down Expand Up @@ -49,6 +51,69 @@ def get_platform():
return result


def get_abbr_impl():
""" Return 'cp' for CPython and 'pp' for PyPy"""
name = platform.python_implementation().lower()
return packaging.tags.INTERPRETER_SHORT_NAMES.get(name) or name


# copied from pep425tags.py, maybe should be part of packaging.tags
def get_impl_ver():
"""Return implementation version."""
impl_ver = get_config_var("py_version_nodot")
if not impl_ver:
impl_ver = '{}{}'.format(*sys.version_info[:2])
return impl_ver


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


def get_abi_tag():
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
(CPython 2, PyPy)."""
soabi = get_config_var('SOABI')
impl = get_abbr_impl()
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' and
sys.version_info < (3, 8))) \
and sys.version_info < (3, 8):
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'
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
elif soabi and soabi.startswith('cpython-'):
abi = 'cp' + soabi.split('-')[1]
elif soabi:
abi = soabi.replace('.', '_').replace('-', '_')
else:
abi = None
return abi


def safer_name(name):
return safe_name(name).replace('-', '_')

Expand Down Expand Up @@ -181,7 +246,6 @@ def wheel_dist_name(self):
return '-'.join(components)

def get_tag(self):
from . import pep425tags
# bdist sets self.plat_name if unset, we should only use it for purepy
# wheels if the user supplied it.
if self.plat_name_supplied:
Expand All @@ -207,20 +271,18 @@ def get_tag(self):
impl = self.python_tag
tag = (impl, 'none', plat_name)
else:
impl_name = pep425tags.get_abbr_impl()
impl_ver = pep425tags.get_impl_ver()
impl_name = get_abbr_impl()
impl_ver = get_impl_ver()
impl = impl_name + impl_ver
# We don't work on CPython 3.1, 3.0.
if self.py_limited_api and (impl_name + impl_ver).startswith('cp3'):
impl = self.py_limited_api
abi_tag = 'abi3'
else:
abi_tag = str(pep425tags.get_abi_tag()).lower()
abi_tag = str(get_abi_tag()).lower()
tag = (impl, abi_tag, plat_name)
supported_tags = pep425tags.get_supported(
self.bdist_dir,
supplied_platform=plat_name if self.plat_name_supplied else None)
# XXX switch to this alternate implementation for non-pure:
supported_tags = [(t.interpreter, t.abi, t.platform)
for t in packaging.tags.sys_tags()]
if not self.py_limited_api:
assert tag == supported_tags[0], "%s != %s" % (tag, supported_tags[0])
assert tag in supported_tags, "would build wheel with unsupported tag {}".format(tag)
Expand Down Expand Up @@ -345,8 +407,8 @@ def license_paths(self):
})

if 'license_file' in metadata:
warn('The "license_file" option is deprecated. Use "license_files" instead.',
DeprecationWarning)
warnings.warn('The "license_file" option is deprecated. Use '
'"license_files" instead.', DeprecationWarning)
files.add(metadata['license_file'][1])

if 'license_file' not in metadata and 'license_files' not in metadata:
Expand Down

0 comments on commit 9c6dd62

Please sign in to comment.