@@ -43,13 +43,20 @@ def configure_parser(sub_parsers):
4343 p .add_argument (
4444 "--plat" ,
4545 action = EnvironmentDefault ,
46+ required = False ,
4647 metavar = "PLATFORM" ,
4748 env = "AUDITWHEEL_PLAT" ,
4849 dest = "PLAT" ,
4950 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 } ")' ,
5152 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." ,
5360 )
5461 p .add_argument (
5562 "-L" ,
@@ -115,26 +122,36 @@ def execute(args, p):
115122 for wheel_file in args .WHEEL_FILE :
116123 if not isfile (wheel_file ):
117124 p .error ("cannot access %s. No such file" % wheel_file )
125+ wheel_policy .set_platform_from_wheel (wheel_file )
118126
119127 logger .info ("Repairing %s" , basename (wheel_file ))
120128
121- if not exists (args .WHEEL_DIR ):
122- os .makedirs (args .WHEEL_DIR )
123-
124129 try :
125130 wheel_abi = analyze_wheel_abi (wheel_policy , wheel_file , exclude )
126131 except NonPlatformWheel :
127132 logger .info (NonPlatformWheel .LOG_MESSAGE )
128133 return 1
129134
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
130146 policy = wheel_policy .get_policy_by_name (args .PLAT )
131147 reqd_tag = policy ["priority" ]
132148
133149 if reqd_tag > wheel_policy .get_priority_by_name (wheel_abi .sym_tag ):
134150 msg = (
135151 'cannot repair "%s" to "%s" ABI because of the presence '
136152 "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 )
138155 )
139156 p .error (msg )
140157
@@ -184,3 +201,6 @@ def execute(args, p):
184201
185202 if out_wheel is not None :
186203 logger .info ("\n Fixed-up wheel written to %s" , out_wheel )
204+
205+ if args .BEST_PLAT :
206+ args .PLAT = None
0 commit comments