--- a/eric6/DebugClients/Python/DebugUtilities.py Thu Feb 13 19:27:10 2020 +0100 +++ b/eric6/DebugClients/Python/DebugUtilities.py Fri Feb 14 19:52:37 2020 +0100 @@ -8,6 +8,7 @@ """ import json +import os # # Taken from inspect.py of Python 3.4 @@ -145,5 +146,72 @@ } return json.dumps(commandDict) + '\n' + +def isPythonProgram(program, arguments): + """ + Function to check, if program is a Python interpreter and + arguments don't include '-m'. + + @param program program to be executed + @type str + @param arguments list of command line arguments + @type list of str + @return flag indicating a python program and a tuple containing the + interpreter to be used and the arguments + @rtype tuple of (bool, tuple of (str, list of str)) + """ + prog = program.lower() + ok = ( + ("python" in prog and arguments[0] != '-m') or + "pypy" in prog + ) + return ok, (program, arguments[:]) + + +def patchArguments(debugClient, arguments, multiprocessSupport, + noRedirect=False): + """ + Function to patch the arguments given to start a program in order to + execute it in our debugger. + + @param debugClient reference to the debug client object + @type DebugClient + @param arguments list of program arguments + @type list of str + @param multiprocessSupport flag indicating multi process debug support + @type bool + @param noRedirect flag indicating to not redirect stdin and stdout + @type bool + @return modified argument list + @rtype list of str + """ + (wd, host, port, exceptions, tracePython, redirect, noencoding + ) = debugClient.startOptions[:7] + + modifiedArguments = [ + os.path.join(os.path.dirname(__file__), "DebugClient.py"), + "-h", host, + "-p", str(port), + "--no-passive", + ] + + if wd: + modifiedArguments.extend(["-w", wd]) + if not exceptions: + modifiedArguments.append("-e") + if tracePython: + modifiedArguments.append("-t") + if noRedirect or not redirect: + modifiedArguments.append("-n") + if noencoding: + modifiedArguments.append("--no-encoding") + if multiprocessSupport: + modifiedArguments.append("--multiprocess") + modifiedArguments.append("--") + # end the arguments for DebugClient + modifiedArguments.extend(arguments) + + return modifiedArguments + # # eflag: noqa = M702