eric6/DebugClients/Python/DebugUtilities.py

branch
multi_processing
changeset 7420
0d596bb4a60d
parent 7419
9c1163735448
child 7421
4a9900aef04e
--- a/eric6/DebugClients/Python/DebugUtilities.py	Sat Feb 15 20:00:22 2020 +0100
+++ b/eric6/DebugClients/Python/DebugUtilities.py	Sun Feb 16 12:42:12 2020 +0100
@@ -239,17 +239,65 @@
     @return modified argument list
     @rtype list of str
     """
-    # TODO: support #! line
+    args = arguments[:]    # create a copy of the arguments list
+    
+    # support for shebang line
+    program = os.path.basename(args[0]).lower()
+    for pyname in PYTHON_NAMES:
+        if pyname in program:
+            break
+    else:
+        if not isWindowsPlatform() and startsWithShebang(args[0]):
+            # insert our interpreter as first argument
+            args.insert(0, sys.executable)
+    
+    # check for -c or -m invocation => debugging not supported yet
+    if "-c" in args:
+        cm_position = args.index("-c")
+    elif "-m" in args:
+        cm_position = args.index("-m")
+    else:
+        cm_position = 0
+    if cm_position > 0:
+        # check if it belongs to the interpreter or program
+        for pos in range(1, len(args)):
+            if not args[pos].startswith("-"):
+                # first argument not starting with '-' is the program
+                found = True
+                break
+        else:
+            found = False
+        if found and cm_position < pos:
+            # it belongs to the interpreter
+            return arguments
+    
+    # extract list of interpreter arguments, i.e. all arguments before the
+    # first one not starting with '-'.
+    interpreter = args.pop(0)
+    interpreterArgs = []
+    while args:
+        if args[0].startswith("-"):
+            if args[0] in ("-W", "-X"):
+                # take two elements off the list
+                interpreterArgs.append(args.pop(0))
+                interpreterArgs.append(args.pop(0))
+            else:
+                interpreterArgs.append(args.pop(0))
+        else:
+            break
+    print(interpreter, interpreterArgs, args)
+    
     (wd, host, port, exceptions, tracePython, redirect, noencoding
      ) = debugClient.startOptions[:7]
     
-    modifiedArguments = [
-        arguments[0],           # interpreter (should be modified if #! line
+    modifiedArguments = [interpreter]
+    modifiedArguments.extend(interpreterArgs)
+    modifiedArguments.extend([
         os.path.join(os.path.dirname(__file__), "DebugClient.py"),
         "-h", host,
         "-p", str(port),
         "--no-passive",
-    ]
+    ])
     
     if wd:
         modifiedArguments.extend(["-w", wd])
@@ -267,7 +315,7 @@
     # end the arguments for DebugClient
     
     # append the arguments for the program to be debugged
-    modifiedArguments.extend(arguments[1:])
+    modifiedArguments.extend(args)
     
     return modifiedArguments
 

eric ide

mercurial