src/eric7/DebugClients/Python/SubprocessExtension.py

branch
eric7-maintenance
changeset 11118
967a88a16a21
parent 11090
f5f5f5803935
equal deleted inserted replaced
11064:c2cb561a39b0 11118:967a88a16a21
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 # Copyright (c) 2020 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2020 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing a function to patch subprocess.Popen to support debugging 7 Module implementing a function to patch subprocess.Popen to support debugging
8 of the process. 8 of the process.
9 """ 9 """
10 10
11 import os 11 import os
12 import shlex 12 import shlex
13 import shutil
13 14
14 from DebugUtilities import ( 15 from DebugUtilities import (
15 isPythonProgram, 16 isPythonProgram,
16 isWindowsPlatform, 17 isWindowsPlatform,
17 patchArguments, 18 patchArguments,
53 and _debugClient.multiprocessSupport 54 and _debugClient.multiprocessSupport
54 and isinstance(args, (str, list)) 55 and isinstance(args, (str, list))
55 ): 56 ):
56 if isinstance(args, str): 57 if isinstance(args, str):
57 # convert to arguments list 58 # convert to arguments list
58 args = ( 59 args_list = (
59 stringToArgumentsWindows(args) 60 stringToArgumentsWindows(args)
60 if isWindowsPlatform() 61 if isWindowsPlatform()
61 else shlex.split(args) 62 else shlex.split(args)
62 ) 63 )
63 else: 64 else:
64 # create a copy of the arguments 65 # create a copy of the arguments
65 args = args[:] 66 args_list = args[:]
66 ok = isPythonProgram(args[0]) 67 isPythonProg = isPythonProgram(
67 if ok: 68 args_list[0],
68 scriptName = os.path.basename(args[0]) 69 withPath="shell" in kwargs and kwargs["shell"] is True,
70 )
71 if isPythonProg:
72 scriptName = os.path.basename(args_list[0])
69 if not _debugClient.skipMultiProcessDebugging(scriptName): 73 if not _debugClient.skipMultiProcessDebugging(scriptName):
70 args = patchArguments(_debugClient, args, noRedirect=True) 74 if (
71 if "shell" in kwargs and kwargs["shell"] is True: 75 "shell" in kwargs
72 # shell=True interferes with eric debugger 76 and kwargs["shell"] is True
73 kwargs["shell"] = False 77 and not os.path.isabs(args_list[0])
78 ):
79 prog = shutil.which(args_list[0])
80 if prog:
81 args_list[0] = prog
82 args = patchArguments(
83 _debugClient,
84 args_list,
85 noRedirect=True,
86 isPythonProg=isPythonProg,
87 )
88 if "shell" in kwargs and kwargs["shell"] is True:
89 args = shlex.join(args)
74 90
75 super().__init__(args, *popenargs, **kwargs) 91 super().__init__(args, *popenargs, **kwargs)
76 92
77 _debugClient = debugClient 93 _debugClient = debugClient
78 module.Popen = PopenWrapper 94 module.Popen = PopenWrapper

eric ide

mercurial