@@ -41,7 +41,7 @@ def _to_generic_pyver(pyver_tags):
41
41
return ['py%s' % tag [2 ] if tag .startswith ('cp' ) else tag for tag in pyver_tags ]
42
42
43
43
44
- def _convert_to_generic_platform_wheel (wheel_ctx ):
44
+ def _convert_to_generic_platform_wheel (wheel_ctx , py2_py3 , additional_platforms ):
45
45
"""Switch to generic python tags and remove ABI tags from a wheel
46
46
47
47
Convert implementation specific python tags to their generic equivalent and
@@ -51,6 +51,10 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
51
51
----------
52
52
wheel_ctx : InWheelCtx
53
53
An open wheel context
54
+ py2_py3: Bool
55
+ Whether the pyver tag shall be py2.py3 or just the one inferred from the wheel name
56
+ additional_platforms : Optional[Iterable[str]]
57
+ An optional iterable of additional platform to add to the wheel
54
58
"""
55
59
56
60
abi_tags = ['none' ]
@@ -69,7 +73,14 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
69
73
70
74
# Update wheel filename
71
75
fparts = wf .parsed_filename .groupdict ()
72
- original_platform_tags = fparts ['plat' ].split ('.' )
76
+ platform_tags = fparts ['plat' ].split ('.' )
77
+ logger .debug ('Previous platform tags: %s' , ', ' .join (platform_tags ))
78
+ if additional_platforms :
79
+ platform_tags = list (sorted (set (platform_tags + [p for p in additional_platforms ])))
80
+ fparts ['plat' ] = '.' .join (platform_tags )
81
+ logger .debug ('New platform tags ....: %s' , ', ' .join (platform_tags ))
82
+ else :
83
+ logger .debug ('No platform tags change needed.' )
73
84
74
85
original_abi_tags = fparts ['abi' ].split ('.' )
75
86
logger .debug ('Previous ABI tags: %s' , ', ' .join (original_abi_tags ))
@@ -82,6 +93,10 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
82
93
original_pyver_tags = fparts ['pyver' ].split ('.' )
83
94
logger .debug ('Previous pyver tags: %s' , ', ' .join (original_pyver_tags ))
84
95
pyver_tags = _to_generic_pyver (original_pyver_tags )
96
+ if py2_py3 :
97
+ if len (set (["py2" , "py3" ]) & set (pyver_tags )) == 0 :
98
+ raise ValueError ("pyver_tags does not contain py2 nor py3" )
99
+ pyver_tags = list (sorted (set (pyver_tags + ["py2" , "py3" ])))
85
100
if pyver_tags != original_pyver_tags :
86
101
logger .debug ('New pyver tags ....: %s' , ', ' .join (pyver_tags ))
87
102
fparts ['pyver' ] = '.' .join (pyver_tags )
@@ -106,15 +121,14 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
106
121
107
122
# Python version, C-API version combinations
108
123
pyc_apis = []
109
- for tag in in_info_tags :
110
- py_ver = '.' .join (_to_generic_pyver (tag .split ('-' )[0 ].split ('.' )))
124
+ for py_ver in pyver_tags :
111
125
abi = 'none'
112
126
pyc_apis .append ('-' .join ([py_ver , abi ]))
113
127
# unique Python version, C-API version combinations
114
128
pyc_apis = unique_by_index (pyc_apis )
115
129
116
130
# Set tags for each Python version, C-API combination
117
- updated_tags = ['-' .join (tup ) for tup in product (pyc_apis , original_platform_tags )]
131
+ updated_tags = ['-' .join (tup ) for tup in product (pyc_apis , platform_tags )]
118
132
119
133
if updated_tags != in_info_tags :
120
134
del info ['Tag' ]
@@ -128,7 +142,8 @@ def _convert_to_generic_platform_wheel(wheel_ctx):
128
142
return out_wheel
129
143
130
144
131
- def convert_to_generic_platform_wheel (wheel_path , out_dir = './dist/' , remove_original = False , verbose = 0 ):
145
+ def convert_to_generic_platform_wheel (wheel_path , out_dir = './dist/' , remove_original = False , verbose = 0 ,
146
+ py2_py3 = False , additional_platforms = None ):
132
147
logging .disable (logging .NOTSET )
133
148
if verbose >= 1 :
134
149
logging .basicConfig (level = logging .DEBUG )
@@ -140,7 +155,7 @@ def convert_to_generic_platform_wheel(wheel_path, out_dir='./dist/', remove_orig
140
155
141
156
with InWheelCtx (wheel_path ) as ctx :
142
157
ctx .out_wheel = pjoin (out_dir , wheel_fname )
143
- ctx .out_wheel = _convert_to_generic_platform_wheel (ctx )
158
+ ctx .out_wheel = _convert_to_generic_platform_wheel (ctx , py2_py3 , additional_platforms )
144
159
145
160
if remove_original :
146
161
logger .info ('Removed original wheel %s' % wheel_path )
@@ -169,13 +184,23 @@ def main():
169
184
dest = 'remove_original' ,
170
185
action = 'store_true' ,
171
186
help = 'Remove original wheel' )
187
+ p .add_argument ("--py2-py3" ,
188
+ dest = 'py2_py3' ,
189
+ action = 'store_true' ,
190
+ help = 'Remove original wheel' )
191
+ p .add_argument ("-p" ,
192
+ "--add-platform" ,
193
+ dest = 'additional_platforms' ,
194
+ action = "append" ,
195
+ help = 'Add a platform tag' )
172
196
173
197
args = p .parse_args ()
174
198
175
199
if not isfile (args .WHEEL_FILE ):
176
200
p .error ('cannot access %s. No such file' % args .WHEEL_FILE )
177
201
178
- convert_to_generic_platform_wheel (args .WHEEL_FILE , args .WHEEL_DIR , args .remove_original , args .verbose )
202
+ convert_to_generic_platform_wheel (args .WHEEL_FILE , args .WHEEL_DIR , args .remove_original , args .verbose ,
203
+ args .py2_py3 , args .additional_platforms )
179
204
180
205
181
206
if __name__ == '__main__' :
0 commit comments