237 @param noRedirect flag indicating to not redirect stdin and stdout |
237 @param noRedirect flag indicating to not redirect stdin and stdout |
238 @type bool |
238 @type bool |
239 @return modified argument list |
239 @return modified argument list |
240 @rtype list of str |
240 @rtype list of str |
241 """ |
241 """ |
242 # TODO: support #! line |
242 args = arguments[:] # create a copy of the arguments list |
|
243 |
|
244 # support for shebang line |
|
245 program = os.path.basename(args[0]).lower() |
|
246 for pyname in PYTHON_NAMES: |
|
247 if pyname in program: |
|
248 break |
|
249 else: |
|
250 if not isWindowsPlatform() and startsWithShebang(args[0]): |
|
251 # insert our interpreter as first argument |
|
252 args.insert(0, sys.executable) |
|
253 |
|
254 # check for -c or -m invocation => debugging not supported yet |
|
255 if "-c" in args: |
|
256 cm_position = args.index("-c") |
|
257 elif "-m" in args: |
|
258 cm_position = args.index("-m") |
|
259 else: |
|
260 cm_position = 0 |
|
261 if cm_position > 0: |
|
262 # check if it belongs to the interpreter or program |
|
263 for pos in range(1, len(args)): |
|
264 if not args[pos].startswith("-"): |
|
265 # first argument not starting with '-' is the program |
|
266 found = True |
|
267 break |
|
268 else: |
|
269 found = False |
|
270 if found and cm_position < pos: |
|
271 # it belongs to the interpreter |
|
272 return arguments |
|
273 |
|
274 # extract list of interpreter arguments, i.e. all arguments before the |
|
275 # first one not starting with '-'. |
|
276 interpreter = args.pop(0) |
|
277 interpreterArgs = [] |
|
278 while args: |
|
279 if args[0].startswith("-"): |
|
280 if args[0] in ("-W", "-X"): |
|
281 # take two elements off the list |
|
282 interpreterArgs.append(args.pop(0)) |
|
283 interpreterArgs.append(args.pop(0)) |
|
284 else: |
|
285 interpreterArgs.append(args.pop(0)) |
|
286 else: |
|
287 break |
|
288 print(interpreter, interpreterArgs, args) |
|
289 |
243 (wd, host, port, exceptions, tracePython, redirect, noencoding |
290 (wd, host, port, exceptions, tracePython, redirect, noencoding |
244 ) = debugClient.startOptions[:7] |
291 ) = debugClient.startOptions[:7] |
245 |
292 |
246 modifiedArguments = [ |
293 modifiedArguments = [interpreter] |
247 arguments[0], # interpreter (should be modified if #! line |
294 modifiedArguments.extend(interpreterArgs) |
|
295 modifiedArguments.extend([ |
248 os.path.join(os.path.dirname(__file__), "DebugClient.py"), |
296 os.path.join(os.path.dirname(__file__), "DebugClient.py"), |
249 "-h", host, |
297 "-h", host, |
250 "-p", str(port), |
298 "-p", str(port), |
251 "--no-passive", |
299 "--no-passive", |
252 ] |
300 ]) |
253 |
301 |
254 if wd: |
302 if wd: |
255 modifiedArguments.extend(["-w", wd]) |
303 modifiedArguments.extend(["-w", wd]) |
256 if not exceptions: |
304 if not exceptions: |
257 modifiedArguments.append("-e") |
305 modifiedArguments.append("-e") |
265 modifiedArguments.append("--multiprocess") |
313 modifiedArguments.append("--multiprocess") |
266 modifiedArguments.append("--") |
314 modifiedArguments.append("--") |
267 # end the arguments for DebugClient |
315 # end the arguments for DebugClient |
268 |
316 |
269 # append the arguments for the program to be debugged |
317 # append the arguments for the program to be debugged |
270 modifiedArguments.extend(arguments[1:]) |
318 modifiedArguments.extend(args) |
271 |
319 |
272 return modifiedArguments |
320 return modifiedArguments |
273 |
321 |
274 # |
322 # |
275 # eflag: noqa = M702 |
323 # eflag: noqa = M702 |