Fri, 06 Dec 2024 14:16:23 +0100
Improved subprocess debugging by support for the 'shell=True' parameter (see issue 575).
--- a/src/eric7/APIs/Python3/eric7.api Fri Dec 06 09:12:46 2024 +0100 +++ b/src/eric7/APIs/Python3/eric7.api Fri Dec 06 14:16:23 2024 +0100 @@ -435,11 +435,11 @@ eric7.DebugClients.Python.DebugUtilities.formatargvalues?4(args, varargs, varkw, localsDict, formatarg=str, formatvarargs=lambda name: "*" + name, formatvarkw=lambda name: "**" + name, formatvalue=lambda value: "=" + repr(value), ) eric7.DebugClients.Python.DebugUtilities.getargvalues?4(frame) eric7.DebugClients.Python.DebugUtilities.isExecutable?4(program) -eric7.DebugClients.Python.DebugUtilities.isPythonProgram?4(program) +eric7.DebugClients.Python.DebugUtilities.isPythonProgram?4(program, withPath=False) eric7.DebugClients.Python.DebugUtilities.isWindowsPlatform?4() eric7.DebugClients.Python.DebugUtilities.mod_dict?7 eric7.DebugClients.Python.DebugUtilities.patchArgumentStringWindows?4(debugClient, argStr) -eric7.DebugClients.Python.DebugUtilities.patchArguments?4(debugClient, arguments, noRedirect=False) +eric7.DebugClients.Python.DebugUtilities.patchArguments?4(debugClient, arguments, noRedirect=False, isPythonProg=False) eric7.DebugClients.Python.DebugUtilities.prepareJsonCommand?4(method, params) eric7.DebugClients.Python.DebugUtilities.quoteArgs?4(args) eric7.DebugClients.Python.DebugUtilities.removeQuotesFromArgs?4(args)
--- a/src/eric7/DebugClients/Python/DebugUtilities.py Fri Dec 06 09:12:46 2024 +0100 +++ b/src/eric7/DebugClients/Python/DebugUtilities.py Fri Dec 06 14:16:23 2024 +0100 @@ -9,6 +9,7 @@ import json import os +import shutil import sys import traceback @@ -216,13 +217,16 @@ return False -def isPythonProgram(program): +def isPythonProgram(program, withPath=False): """ Function to check, if the given program is a Python interpreter or program. @param program program to be checked @type str + @param withPath flag indicating to search the program in the executable + search path (defaults to False) + @type bool (optional) @return flag indicating a Python interpreter or program @rtype bool """ @@ -233,6 +237,11 @@ if any(pyname in prog for pyname in PYTHON_NAMES): return True + if withPath: + prog = shutil.which(program) + if prog: + program = prog + return ( not isWindowsPlatform() and isExecutable(program) and startsWithShebang(program) ) @@ -283,7 +292,7 @@ return args -def patchArguments(debugClient, arguments, noRedirect=False): +def patchArguments(debugClient, arguments, noRedirect=False, isPythonProg=False): """ Function to patch the arguments given to start a program in order to execute it in our debugger. @@ -293,11 +302,14 @@ @param arguments list of program arguments @type list of str @param noRedirect flag indicating to not redirect stdin and stdout - @type bool + (defaults to False) + @type bool (optional) + @param isPythonProg flag indicating a Python script (defaults to False) + @type bool (optional) @return modified argument list @rtype list of str """ - if not isPythonProgram(arguments[0]): + if not (isPythonProg or isPythonProgram(arguments[0])): # it is not a Python program return arguments
--- a/src/eric7/DebugClients/Python/SubprocessExtension.py Fri Dec 06 09:12:46 2024 +0100 +++ b/src/eric7/DebugClients/Python/SubprocessExtension.py Fri Dec 06 14:16:23 2024 +0100 @@ -10,6 +10,7 @@ import os import shlex +import shutil from DebugUtilities import ( isPythonProgram, @@ -55,22 +56,37 @@ ): if isinstance(args, str): # convert to arguments list - args = ( + args_list = ( stringToArgumentsWindows(args) if isWindowsPlatform() else shlex.split(args) ) else: # create a copy of the arguments - args = args[:] - ok = isPythonProgram(args[0]) - if ok: - scriptName = os.path.basename(args[0]) + args_list = args[:] + isPythonProg = isPythonProgram( + args_list[0], + withPath="shell" in kwargs and kwargs["shell"] is True, + ) + if isPythonProg: + scriptName = os.path.basename(args_list[0]) if not _debugClient.skipMultiProcessDebugging(scriptName): - args = patchArguments(_debugClient, args, noRedirect=True) - if "shell" in kwargs and kwargs["shell"] is True: - # shell=True interferes with eric debugger - kwargs["shell"] = False + if ( + "shell" in kwargs + and kwargs["shell"] is True + and not os.path.isabs(args_list[0]) + ): + prog = shutil.which(args_list[0]) + if prog: + args_list[0] = prog + args = patchArguments( + _debugClient, + args_list, + noRedirect=True, + isPythonProg=isPythonProg, + ) + if "shell" in kwargs and kwargs["shell"] is True: + args = shlex.join(args) super().__init__(args, *popenargs, **kwargs)
--- a/src/eric7/Documentation/Source/eric7.DebugClients.Python.DebugUtilities.html Fri Dec 06 09:12:46 2024 +0100 +++ b/src/eric7/Documentation/Source/eric7.DebugClients.Python.DebugUtilities.html Fri Dec 06 14:16:23 2024 +0100 @@ -248,7 +248,7 @@ <hr /> <a NAME="isPythonProgram" ID="isPythonProgram"></a> <h2>isPythonProgram</h2> -<b>isPythonProgram</b>(<i>program</i>) +<b>isPythonProgram</b>(<i>program, withPath=False</i>) <p> Function to check, if the given program is a Python interpreter or program. @@ -260,6 +260,11 @@ <dd> program to be checked </dd> +<dt><i>withPath</i> (bool (optional))</dt> +<dd> +flag indicating to search the program in the executable + search path (defaults to False) +</dd> </dl> <dl> <dt>Return:</dt> @@ -333,7 +338,7 @@ <hr /> <a NAME="patchArguments" ID="patchArguments"></a> <h2>patchArguments</h2> -<b>patchArguments</b>(<i>debugClient, arguments, noRedirect=False</i>) +<b>patchArguments</b>(<i>debugClient, arguments, noRedirect=False, isPythonProg=False</i>) <p> Function to patch the arguments given to start a program in order to execute it in our debugger. @@ -349,9 +354,14 @@ <dd> list of program arguments </dd> -<dt><i>noRedirect</i> (bool)</dt> +<dt><i>noRedirect</i> (bool (optional))</dt> <dd> flag indicating to not redirect stdin and stdout + (defaults to False) +</dd> +<dt><i>isPythonProg</i> (bool (optional))</dt> +<dd> +flag indicating a Python script (defaults to False) </dd> </dl> <dl>