@@ -43,13 +43,20 @@ def configure_parser(sub_parsers):
43
43
p .add_argument (
44
44
"--plat" ,
45
45
action = EnvironmentDefault ,
46
+ required = False ,
46
47
metavar = "PLATFORM" ,
47
48
env = "AUDITWHEEL_PLAT" ,
48
49
dest = "PLAT" ,
49
50
help = "Desired target platform. See the available platforms under the "
50
- f'PLATFORMS section below. (default: "{ highest_policy } ")' ,
51
+ f'PLATFORMS section below. (default on current arch : "{ highest_policy } ")' ,
51
52
choices = policy_names ,
52
- default = highest_policy ,
53
+ default = None ,
54
+ )
55
+ p .add_argument (
56
+ "--best-plat" ,
57
+ action = "store_true" ,
58
+ dest = "BEST_PLAT" ,
59
+ help = "Automatically determine the best target platform." ,
53
60
)
54
61
p .add_argument (
55
62
"-L" ,
@@ -115,26 +122,36 @@ def execute(args, p):
115
122
for wheel_file in args .WHEEL_FILE :
116
123
if not isfile (wheel_file ):
117
124
p .error ("cannot access %s. No such file" % wheel_file )
125
+ wheel_policy .set_platform_from_wheel (wheel_file )
118
126
119
127
logger .info ("Repairing %s" , basename (wheel_file ))
120
128
121
- if not exists (args .WHEEL_DIR ):
122
- os .makedirs (args .WHEEL_DIR )
123
-
124
129
try :
125
130
wheel_abi = analyze_wheel_abi (wheel_policy , wheel_file , exclude )
126
131
except NonPlatformWheel :
127
132
logger .info (NonPlatformWheel .LOG_MESSAGE )
128
133
return 1
129
134
135
+ if args .BEST_PLAT :
136
+ if args .PLAT :
137
+ p .error ("Cannot specify both --best-plat and --plat" )
138
+ args .PLAT = wheel_abi .overall_tag
139
+
140
+ if not exists (args .WHEEL_DIR ):
141
+ os .makedirs (args .WHEEL_DIR )
142
+
143
+ highest_policy = wheel_policy .get_policy_name (wheel_policy .priority_highest )
144
+ if args .PLAT is None :
145
+ args .PLAT = highest_policy
130
146
policy = wheel_policy .get_policy_by_name (args .PLAT )
131
147
reqd_tag = policy ["priority" ]
132
148
133
149
if reqd_tag > wheel_policy .get_priority_by_name (wheel_abi .sym_tag ):
134
150
msg = (
135
151
'cannot repair "%s" to "%s" ABI because of the presence '
136
152
"of too-recent versioned symbols. You'll need to compile "
137
- "the wheel on an older toolchain." % (wheel_file , args .PLAT )
153
+ "the wheel on an older toolchain or pick a newer platform."
154
+ % (wheel_file , args .PLAT )
138
155
)
139
156
p .error (msg )
140
157
@@ -184,3 +201,6 @@ def execute(args, p):
184
201
185
202
if out_wheel is not None :
186
203
logger .info ("\n Fixed-up wheel written to %s" , out_wheel )
204
+
205
+ if args .BEST_PLAT :
206
+ args .PLAT = None
0 commit comments