src/eric7/DebugClients/Python/DebugUtilities.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) 2015 - 2024 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2015 - 2025 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing utilities functions for the debug client. 7 Module implementing utilities functions for the debug client.
8 """ 8 """
9 9
10 import json 10 import json
11 import os 11 import os
12 import shutil
12 import sys 13 import sys
13 import traceback 14 import traceback
14 15
15 from collections import namedtuple 16 from collections import namedtuple
16 from inspect import iscode, isframe 17 from inspect import iscode, isframe
214 except Exception: 215 except Exception:
215 traceback.print_exc() 216 traceback.print_exc()
216 return False 217 return False
217 218
218 219
219 def isPythonProgram(program): 220 def isPythonProgram(program, withPath=False):
220 """ 221 """
221 Function to check, if the given program is a Python interpreter or 222 Function to check, if the given program is a Python interpreter or
222 program. 223 program.
223 224
224 @param program program to be checked 225 @param program program to be checked
225 @type str 226 @type str
227 @param withPath flag indicating to search the program in the executable
228 search path (defaults to False)
229 @type bool (optional)
226 @return flag indicating a Python interpreter or program 230 @return flag indicating a Python interpreter or program
227 @rtype bool 231 @rtype bool
228 """ 232 """
229 if not program: 233 if not program:
230 return False 234 return False
231 235
232 prog = os.path.basename(program).lower() 236 prog = os.path.basename(program).lower()
233 if any(pyname in prog for pyname in PYTHON_NAMES): 237 if any(pyname in prog for pyname in PYTHON_NAMES):
234 return True 238 return True
239
240 if withPath:
241 prog = shutil.which(program)
242 if prog:
243 program = prog
235 244
236 return ( 245 return (
237 not isWindowsPlatform() and isExecutable(program) and startsWithShebang(program) 246 not isWindowsPlatform() and isExecutable(program) and startsWithShebang(program)
238 ) 247 )
239 248
281 return quotedArgs 290 return quotedArgs
282 else: 291 else:
283 return args 292 return args
284 293
285 294
286 def patchArguments(debugClient, arguments, noRedirect=False): 295 def patchArguments(debugClient, arguments, noRedirect=False, isPythonProg=False):
287 """ 296 """
288 Function to patch the arguments given to start a program in order to 297 Function to patch the arguments given to start a program in order to
289 execute it in our debugger. 298 execute it in our debugger.
290 299
291 @param debugClient reference to the debug client object 300 @param debugClient reference to the debug client object
292 @type DebugClient 301 @type DebugClient
293 @param arguments list of program arguments 302 @param arguments list of program arguments
294 @type list of str 303 @type list of str
295 @param noRedirect flag indicating to not redirect stdin and stdout 304 @param noRedirect flag indicating to not redirect stdin and stdout
296 @type bool 305 (defaults to False)
306 @type bool (optional)
307 @param isPythonProg flag indicating a Python script (defaults to False)
308 @type bool (optional)
297 @return modified argument list 309 @return modified argument list
298 @rtype list of str 310 @rtype list of str
299 """ 311 """
300 if not isPythonProgram(arguments[0]): 312 if not (isPythonProg or isPythonProgram(arguments[0])):
301 # it is not a Python program 313 # it is not a Python program
302 return arguments 314 return arguments
303 315
304 debugClientScript = os.path.join(os.path.dirname(__file__), "DebugClient.py") 316 debugClientScript = os.path.join(os.path.dirname(__file__), "DebugClient.py")
305 if debugClientScript in arguments: 317 if debugClientScript in arguments:

eric ide

mercurial