@@ -43,13 +43,19 @@ 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+ )
54+ p .add_argument (
55+ "--best-plat" ,
56+ action = "store_true" ,
57+ dest = "BEST_PLAT" ,
58+ help = "Automatically determine the best target platform." ,
5359 )
5460 p .add_argument (
5561 "-L" ,
@@ -115,26 +121,36 @@ def execute(args, p):
115121 for wheel_file in args .WHEEL_FILE :
116122 if not isfile (wheel_file ):
117123 p .error ("cannot access %s. No such file" % wheel_file )
124+ wheel_policy .set_platform_from_wheel (wheel_file )
118125
119126 logger .info ("Repairing %s" , basename (wheel_file ))
120127
121- if not exists (args .WHEEL_DIR ):
122- os .makedirs (args .WHEEL_DIR )
123-
124128 try :
125129 wheel_abi = analyze_wheel_abi (wheel_policy , wheel_file , exclude )
126130 except NonPlatformWheel :
127131 logger .info (NonPlatformWheel .LOG_MESSAGE )
128132 return 1
129133
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
130145 policy = wheel_policy .get_policy_by_name (args .PLAT )
131146 reqd_tag = policy ["priority" ]
132147
133148 if reqd_tag > wheel_policy .get_priority_by_name (wheel_abi .sym_tag ):
134149 msg = (
135150 'cannot repair "%s" to "%s" ABI because of the presence '
136151 "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 )
138154 )
139155 p .error (msg )
140156
0 commit comments