File tree Expand file tree Collapse file tree 1 file changed +32
-9
lines changed
Expand file tree Collapse file tree 1 file changed +32
-9
lines changed Original file line number Diff line number Diff line change 11#! /usr/bin/env python3
22import argparse
33import os
4+ import subprocess
45import sys
56from pathlib import Path
67
@@ -157,21 +158,43 @@ def main() -> None:
157158 return
158159
159160 # Run file
160- python_command = "python2" if cmd_args .python2 else "python3"
161+ if cmd_args .python2 :
162+ python_commands = ["python2" , "py -2" , sys .executable ]
163+ else :
164+ python_commands = ["python3" , "python" , "py" , sys .executable ]
165+ if os .name == "nt" :
166+ python_commands .pop (0 )
161167
162168 filename = Path (cmd_args .input [0 ]).name
169+ py_file = path_prefix + parser ._change_file_name (filename , None )
170+ args_str = " " .join (arg for arg in cmd_args .args )
163171
164172 try :
165173 logger .log_info ("Running" )
166174 logger .program_header ()
167- os .system (
168- "%s %s %s"
169- % (
170- python_command ,
171- path_prefix + parser ._change_file_name (filename , None ),
172- " " .join (arg for arg in cmd_args .args ),
173- ),
174- )
175+
176+ # Try different Python commands until one works
177+ success = False
178+ for cmd in python_commands :
179+ try :
180+ if os .name == "nt" :
181+ result = subprocess .run (
182+ f"{ cmd } { py_file } { args_str } " ,
183+ shell = True ,
184+ check = False ,
185+ )
186+ else :
187+ result = subprocess .run ([cmd , py_file , * cmd_args .args ], check = False )
188+
189+ if result .returncode == 0 :
190+ success = True
191+ break
192+ except :
193+ continue
194+
195+ if not success :
196+ logger .log_error ("Could not find a working Python interpreter" )
197+
175198 logger .program_footer ()
176199
177200 except Exception as e :
You can’t perform that action at this time.
0 commit comments