eric6/DebugClients/Python/QProcessExtension.py

branch
multi_processing
changeset 7412
0a995393d2ba
parent 7411
6d8dcb3551b3
child 7419
9c1163735448
diff -r 6d8dcb3551b3 -r 0a995393d2ba eric6/DebugClients/Python/QProcessExtension.py
--- a/eric6/DebugClients/Python/QProcessExtension.py	Thu Feb 13 19:27:10 2020 +0100
+++ b/eric6/DebugClients/Python/QProcessExtension.py	Fri Feb 14 19:52:37 2020 +0100
@@ -10,28 +10,9 @@
 
 import os
 
-_debugClient = None
-
+from DebugUtilities import isPythonProgram, patchArguments
 
-def _isPythonProgram(program, arguments):
-    """
-    Protected 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[:])
+_debugClient = None
 
 
 def patchQProcess(module, debugClient):
@@ -45,6 +26,8 @@
     """     # __IGNORE_WARNING_D234__
     global _debugClient
     
+    # TODO: implement a process tracer
+    # i.e. report which processes are started
     class QProcessWrapper(module.QProcess):
         """
         Wrapper class for *.QProcess.
@@ -57,44 +40,6 @@
             """
             super(QProcessWrapper, self).__init__(parent)
         
-        @classmethod
-        def modifyArgs(cls, arguments, multiprocessSupport):
-            """
-            Private method to modify the arguments given to the start method.
-            
-            @param arguments list of program arguments
-            @type list of str
-            @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 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
-        
         ###################################################################
         ## Handling of 'start(...)' below
         ###################################################################
@@ -133,14 +78,14 @@
                         mode = args[0]
                     else:
                         mode = module.QIODevice.ReadWrite
-                ok, (program, arguments) = _isPythonProgram(program, arguments)
+                ok, (program, arguments) = isPythonProgram(program, arguments)
                 if (
                     ok and (
                         not os.path.basename(arguments[0])
                         in _debugClient.noDebugList
                     )
                 ):
-                    newArgs = self.modifyArgs(
+                    newArgs = patchArguments(
                         arguments, _debugClient.multiprocessSupport)
                     super(QProcessWrapper, self).start(program, newArgs, mode)
                 else:
@@ -197,7 +142,7 @@
                 arguments = self.arguments()
                 wd = self.workingDirectory()
                 
-                ok, (program, arguments) = _isPythonProgram(program, arguments)
+                ok, (program, arguments) = isPythonProgram(program, arguments)
                 if ok:
                     return QProcessWrapper.startDetachedStatic(
                         program, arguments, wd)
@@ -235,9 +180,9 @@
                     wd = args[2]
                 else:
                     wd = ""
-                ok, (program, arguments) = _isPythonProgram(program, arguments)
+                ok, (program, arguments) = isPythonProgram(program, arguments)
                 if ok:
-                    newArgs = QProcessWrapper.modifyArgs(
+                    newArgs = patchArguments(
                         arguments, _debugClient.multiprocessSupport)
                     return QProcessWrapper._origQProcessStartDetached(
                         program, newArgs, wd)

eric ide

mercurial