@@ -43,13 +43,19 @@ 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
+ )
54
+ p .add_argument (
55
+ "--best-plat" ,
56
+ action = "store_true" ,
57
+ dest = "BEST_PLAT" ,
58
+ help = "Automatically determine the best target platform." ,
53
59
)
54
60
p .add_argument (
55
61
"-L" ,
@@ -115,26 +121,36 @@ def execute(args, p):
115
121
for wheel_file in args .WHEEL_FILE :
116
122
if not isfile (wheel_file ):
117
123
p .error ("cannot access %s. No such file" % wheel_file )
124
+ wheel_policy .set_platform_from_wheel (wheel_file )
118
125
119
126
logger .info ("Repairing %s" , basename (wheel_file ))
120
127
121
- if not exists (args .WHEEL_DIR ):
122
- os .makedirs (args .WHEEL_DIR )
123
-
124
128
try :
125
129
wheel_abi = analyze_wheel_abi (wheel_policy , wheel_file , exclude )
126
130
except NonPlatformWheel :
127
131
logger .info (NonPlatformWheel .LOG_MESSAGE )
128
132
return 1
129
133
134
+ if args .BEST_PLAT :
135
+ if args .PLAT :
136
+ p .error ("Cannot specify both --best-plat and --plat" )
137
+ args .PLAT = wheel_abi .overall_tag
138
+
139
+ if not exists (args .WHEEL_DIR ):
140
+ os .makedirs (args .WHEEL_DIR )
141
+
142
+ highest_policy = wheel_policy .get_policy_name (wheel_policy .priority_highest )
143
+ if args .PLAT is None :
144
+ args .PLAT = highest_policy
130
145
policy = wheel_policy .get_policy_by_name (args .PLAT )
131
146
reqd_tag = policy ["priority" ]
132
147
133
148
if reqd_tag > wheel_policy .get_priority_by_name (wheel_abi .sym_tag ):
134
149
msg = (
135
150
'cannot repair "%s" to "%s" ABI because of the presence '
136
151
"of too-recent versioned symbols. You'll need to compile "
137
- "the wheel on an older toolchain." % (wheel_file , args .PLAT )
152
+ "the wheel on an older toolchain or pick a newer platform."
153
+ % (wheel_file , args .PLAT )
138
154
)
139
155
p .error (msg )
140
156
0 commit comments