1111import re
1212from collections import OrderedDict
1313from email .generator import Generator
14+ import distutils
1415from distutils .core import Command
15- from distutils .sysconfig import get_python_version
16+ from distutils .sysconfig import get_python_version , get_config_var
1617from distutils import log as logger
1718from glob import iglob
1819from shutil import rmtree
19- from warnings import warn
20+ import warnings
2021from zipfile import ZIP_DEFLATED , ZIP_STORED
2122
23+ import packaging .tags
2224import pkg_resources
25+ import platform
2326
24- from .pep425tags import get_abbr_impl , get_impl_ver , get_abi_tag , get_platform
2527from .pkginfo import write_pkg_info
2628from .metadata import pkginfo_to_metadata
2729from .wheelfile import WheelFile
28- from . import pep425tags
2930from . import __version__ as wheel_version
3031
3132
3536PY_LIMITED_API_PATTERN = r'cp3\d'
3637
3738
39+ def python_tag ():
40+ return 'py{}' .format (sys .version_info [0 ])
41+
42+
43+ # copied from pep425tags.py, is there a better way?
44+ def get_platform ():
45+ """Return our platform name 'win32', 'linux_x86_64'"""
46+ # XXX remove distutils dependency
47+ result = distutils .util .get_platform ().replace ('.' , '_' ).replace ('-' , '_' )
48+ if result == "linux_x86_64" and sys .maxsize == 2147483647 :
49+ # pip pull request #3497
50+ result = "linux_i686"
51+ return result
52+
53+
54+ def get_abbr_impl ():
55+ """ Return 'cp' for CPython and 'pp' for PyPy"""
56+ name = platform .python_implementation ().lower ()
57+ return packaging .tags .INTERPRETER_SHORT_NAMES .get (name ) or name
58+
59+
60+ # copied from pep425tags.py, maybe should be part of packaging.tags
61+ def get_impl_ver ():
62+ """Return implementation version."""
63+ impl_ver = get_config_var ("py_version_nodot" )
64+ if not impl_ver :
65+ impl_ver = '{}{}' .format (* sys .version_info [:2 ])
66+ return impl_ver
67+
68+
69+ def get_flag (var , fallback , expected = True , warn = True ):
70+ """Use a fallback method for determining SOABI flags if the needed config
71+ var is unset or unavailable."""
72+ val = get_config_var (var )
73+ if val is None :
74+ if warn :
75+ warnings .warn ("Config variable '{0}' is unset, Python ABI tag may "
76+ "be incorrect" .format (var ), RuntimeWarning , 2 )
77+ return fallback ()
78+ return val == expected
79+
80+
81+ def get_abi_tag ():
82+ """Return the ABI tag based on SOABI (if available) or emulate SOABI
83+ (CPython 2, PyPy)."""
84+ soabi = get_config_var ('SOABI' )
85+ impl = get_abbr_impl ()
86+ if not soabi and impl in ('cp' , 'pp' ) and hasattr (sys , 'maxunicode' ):
87+ d = ''
88+ m = ''
89+ u = ''
90+ if get_flag ('Py_DEBUG' ,
91+ lambda : hasattr (sys , 'gettotalrefcount' ),
92+ warn = (impl == 'cp' )):
93+ d = 'd'
94+ if get_flag ('WITH_PYMALLOC' ,
95+ lambda : impl == 'cp' ,
96+ warn = (impl == 'cp' and
97+ sys .version_info < (3 , 8 ))) \
98+ and sys .version_info < (3 , 8 ):
99+ m = 'm'
100+ if get_flag ('Py_UNICODE_SIZE' ,
101+ lambda : sys .maxunicode == 0x10ffff ,
102+ expected = 4 ,
103+ warn = (impl == 'cp' and
104+ sys .version_info < (3 , 3 ))) \
105+ and sys .version_info < (3 , 3 ):
106+ u = 'u'
107+ abi = '%s%s%s%s%s' % (impl , get_impl_ver (), d , m , u )
108+ elif soabi and soabi .startswith ('cpython-' ):
109+ abi = 'cp' + soabi .split ('-' )[1 ]
110+ elif soabi :
111+ abi = soabi .replace ('.' , '_' ).replace ('-' , '_' )
112+ else :
113+ abi = None
114+ return abi
115+
116+
38117def safer_name (name ):
39118 return safe_name (name ).replace ('-' , '_' )
40119
@@ -62,7 +141,7 @@ class bdist_wheel(Command):
62141 "temporary directory for creating the distribution" ),
63142 ('plat-name=' , 'p' ,
64143 "platform name to embed in generated filenames "
65- "(default: %s)" % get_platform (None )),
144+ "(default: %s)" % get_platform ()),
66145 ('keep-temp' , 'k' ,
67146 "keep the pseudo-installation tree around after " +
68147 "creating the distribution archive" ),
@@ -88,7 +167,7 @@ class bdist_wheel(Command):
88167 .format (', ' .join (supported_compressions ))),
89168 ('python-tag=' , None ,
90169 "Python implementation compatibility tag"
91- " (default: py%s )" % get_impl_ver ()[ 0 ] ),
170+ " (default: '%s' )" % ( python_tag ()) ),
92171 ('build-number=' , None ,
93172 "Build number for this particular version. "
94173 "As specified in PEP-0427, this must start with a digit. "
@@ -116,7 +195,7 @@ def initialize_options(self):
116195 self .group = None
117196 self .universal = False
118197 self .compression = 'deflated'
119- self .python_tag = 'py' + get_impl_ver ()[ 0 ]
198+ self .python_tag = python_tag ()
120199 self .build_number = None
121200 self .py_limited_api = False
122201 self .plat_name_supplied = False
@@ -178,7 +257,7 @@ def get_tag(self):
178257 if self .plat_name and not self .plat_name .startswith ("macosx" ):
179258 plat_name = self .plat_name
180259 else :
181- plat_name = get_platform (self . bdist_dir )
260+ plat_name = get_platform ()
182261
183262 if plat_name in ('linux-x86_64' , 'linux_x86_64' ) and sys .maxsize == 2147483647 :
184263 plat_name = 'linux_i686'
@@ -202,12 +281,8 @@ def get_tag(self):
202281 else :
203282 abi_tag = str (get_abi_tag ()).lower ()
204283 tag = (impl , abi_tag , plat_name )
205- supported_tags = pep425tags .get_supported (
206- self .bdist_dir ,
207- supplied_platform = plat_name if self .plat_name_supplied else None )
208- # XXX switch to this alternate implementation for non-pure:
209- if not self .py_limited_api :
210- assert tag == supported_tags [0 ], "%s != %s" % (tag , supported_tags [0 ])
284+ supported_tags = [(t .interpreter , t .abi , t .platform )
285+ for t in packaging .tags .sys_tags ()]
211286 assert tag in supported_tags , "would build wheel with unsupported tag {}" .format (tag )
212287 return tag
213288
@@ -330,8 +405,8 @@ def license_paths(self):
330405 })
331406
332407 if 'license_file' in metadata :
333- warn ('The "license_file" option is deprecated. Use "license_files" instead.' ,
334- DeprecationWarning )
408+ warnings . warn ('The "license_file" option is deprecated. Use '
409+ '"license_files" instead.' , DeprecationWarning )
335410 files .add (metadata ['license_file' ][1 ])
336411
337412 if 'license_file' not in metadata and 'license_files' not in metadata :
0 commit comments