11
11
import re
12
12
from collections import OrderedDict
13
13
from email .generator import Generator
14
+ import distutils
14
15
from distutils .core import Command
15
- from distutils .sysconfig import get_python_version
16
+ from distutils .sysconfig import get_python_version , get_config_var
16
17
from distutils import log as logger
17
18
from glob import iglob
18
19
from shutil import rmtree
19
- from warnings import warn
20
+ import warnings
20
21
from zipfile import ZIP_DEFLATED , ZIP_STORED
21
22
23
+ import packaging .tags
22
24
import pkg_resources
25
+ import platform
23
26
24
- from .pep425tags import get_abbr_impl , get_impl_ver , get_abi_tag , get_platform
25
27
from .pkginfo import write_pkg_info
26
28
from .metadata import pkginfo_to_metadata
27
29
from .wheelfile import WheelFile
28
- from . import pep425tags
29
30
from . import __version__ as wheel_version
30
31
31
32
35
36
PY_LIMITED_API_PATTERN = r'cp3\d'
36
37
37
38
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
+
38
117
def safer_name (name ):
39
118
return safe_name (name ).replace ('-' , '_' )
40
119
@@ -62,7 +141,7 @@ class bdist_wheel(Command):
62
141
"temporary directory for creating the distribution" ),
63
142
('plat-name=' , 'p' ,
64
143
"platform name to embed in generated filenames "
65
- "(default: %s)" % get_platform (None )),
144
+ "(default: %s)" % get_platform ()),
66
145
('keep-temp' , 'k' ,
67
146
"keep the pseudo-installation tree around after " +
68
147
"creating the distribution archive" ),
@@ -88,7 +167,7 @@ class bdist_wheel(Command):
88
167
.format (', ' .join (supported_compressions ))),
89
168
('python-tag=' , None ,
90
169
"Python implementation compatibility tag"
91
- " (default: py%s )" % get_impl_ver ()[ 0 ] ),
170
+ " (default: '%s' )" % ( python_tag ()) ),
92
171
('build-number=' , None ,
93
172
"Build number for this particular version. "
94
173
"As specified in PEP-0427, this must start with a digit. "
@@ -116,7 +195,7 @@ def initialize_options(self):
116
195
self .group = None
117
196
self .universal = False
118
197
self .compression = 'deflated'
119
- self .python_tag = 'py' + get_impl_ver ()[ 0 ]
198
+ self .python_tag = python_tag ()
120
199
self .build_number = None
121
200
self .py_limited_api = False
122
201
self .plat_name_supplied = False
@@ -178,7 +257,7 @@ def get_tag(self):
178
257
if self .plat_name and not self .plat_name .startswith ("macosx" ):
179
258
plat_name = self .plat_name
180
259
else :
181
- plat_name = get_platform (self . bdist_dir )
260
+ plat_name = get_platform ()
182
261
183
262
if plat_name in ('linux-x86_64' , 'linux_x86_64' ) and sys .maxsize == 2147483647 :
184
263
plat_name = 'linux_i686'
@@ -202,12 +281,8 @@ def get_tag(self):
202
281
else :
203
282
abi_tag = str (get_abi_tag ()).lower ()
204
283
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 ()]
211
286
assert tag in supported_tags , "would build wheel with unsupported tag {}" .format (tag )
212
287
return tag
213
288
@@ -330,8 +405,8 @@ def license_paths(self):
330
405
})
331
406
332
407
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 )
335
410
files .add (metadata ['license_file' ][1 ])
336
411
337
412
if 'license_file' not in metadata and 'license_files' not in metadata :
0 commit comments