eric6/Debugger/DebuggerInterfacePython.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8257
28146736bbfc
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
9 9
10 import sys 10 import sys
11 import os 11 import os
12 import logging 12 import logging
13 import shlex 13 import shlex
14 import contextlib
14 15
15 from PyQt5.QtCore import ( 16 from PyQt5.QtCore import (
16 QObject, QProcess, QProcessEnvironment, QTimer 17 QObject, QProcess, QProcessEnvironment, QTimer
17 ) 18 )
18 19
42 @param debugServer reference to the debug server 43 @param debugServer reference to the debug server
43 @type DebugServer 44 @type DebugServer
44 @param passive flag indicating passive connection mode 45 @param passive flag indicating passive connection mode
45 @type bool 46 @type bool
46 """ 47 """
47 super(DebuggerInterfacePython, self).__init__() 48 super().__init__()
48 49
49 self.__isNetworked = True 50 self.__isNetworked = True
50 self.__autoContinue = False 51 self.__autoContinue = False
51 self.__autoContinued = [] 52 self.__autoContinued = []
52 self.__isStepCommand = False 53 self.__isStepCommand = False
206 if debugClient == "": 207 if debugClient == "":
207 debugClient = os.path.join(sys.path[0], 208 debugClient = os.path.join(sys.path[0],
208 "DebugClients", "Python", 209 "DebugClients", "Python",
209 "DebugClient.py") 210 "DebugClient.py")
210 211
211 if configOverride and configOverride["enable"]: 212 redirect = (
212 redirect = str(configOverride["redirect"]) 213 str(configOverride["redirect"])
213 else: 214 if configOverride and configOverride["enable"] else
214 redirect = str(Preferences.getDebugger("Python3Redirect")) 215 str(Preferences.getDebugger("Python3Redirect"))
216 )
215 noencoding = (Preferences.getDebugger("Python3NoEncoding") and 217 noencoding = (Preferences.getDebugger("Python3NoEncoding") and
216 '--no-encoding' or '') 218 '--no-encoding' or '')
217 multiprocessEnabled = ( 219 multiprocessEnabled = (
218 '--multiprocess' if Preferences.getDebugger("MultiProcessEnabled") 220 '--multiprocess' if Preferences.getDebugger("MultiProcessEnabled")
219 else '' 221 else ''
276 if originalPathString: 278 if originalPathString:
277 clientEnv["PATH"] = originalPathString 279 clientEnv["PATH"] = originalPathString
278 envlist = shlex.split( 280 envlist = shlex.split(
279 Preferences.getDebugger("DebugEnvironment")) 281 Preferences.getDebugger("DebugEnvironment"))
280 for el in envlist: 282 for el in envlist:
281 try: 283 with contextlib.suppress(ValueError):
282 key, value = el.split('=', 1) 284 key, value = el.split('=', 1)
283 clientEnv[str(key)] = str(value) 285 clientEnv[str(key)] = str(value)
284 except ValueError:
285 pass
286 if execPath: 286 if execPath:
287 if "PATH" in clientEnv: 287 if "PATH" in clientEnv:
288 clientEnv["PATH"] = os.pathsep.join( 288 clientEnv["PATH"] = os.pathsep.join(
289 [execPath, clientEnv["PATH"]]) 289 [execPath, clientEnv["PATH"]])
290 else: 290 else:
365 365
366 # start debugger with project specific settings 366 # start debugger with project specific settings
367 debugClient = project.getDebugProperty("DEBUGCLIENT") 367 debugClient = project.getDebugProperty("DEBUGCLIENT")
368 if not venvName: 368 if not venvName:
369 venvName = project.getDebugProperty("VIRTUALENV") 369 venvName = project.getDebugProperty("VIRTUALENV")
370 if not venvName: 370 if not venvName and project.getProjectLanguage() == "Python3":
371 if project.getProjectLanguage() == "Python3": 371 venvName = Preferences.getDebugger("Python3VirtualEnv")
372 venvName = Preferences.getDebugger("Python3VirtualEnv") 372
373 373 redirect = (
374 if configOverride and configOverride["enable"]: 374 str(configOverride["redirect"])
375 redirect = str(configOverride["redirect"]) 375 if configOverride and configOverride["enable"] else
376 else: 376 str(project.getDebugProperty("REDIRECT"))
377 redirect = str(project.getDebugProperty("REDIRECT")) 377 )
378 noencoding = ( 378 noencoding = (
379 '--no-encoding' if project.getDebugProperty("NOENCODING") else '' 379 '--no-encoding' if project.getDebugProperty("NOENCODING") else ''
380 ) 380 )
381 multiprocessEnabled = ( 381 multiprocessEnabled = (
382 '--multiprocess' if Preferences.getDebugger("MultiProcessEnabled") 382 '--multiprocess' if Preferences.getDebugger("MultiProcessEnabled")
460 if originalPathString: 460 if originalPathString:
461 clientEnv["PATH"] = originalPathString 461 clientEnv["PATH"] = originalPathString
462 envlist = shlex.split( 462 envlist = shlex.split(
463 project.getDebugProperty("ENVIRONMENTSTRING")) 463 project.getDebugProperty("ENVIRONMENTSTRING"))
464 for el in envlist: 464 for el in envlist:
465 try: 465 with contextlib.suppress(ValueError):
466 key, value = el.split('=', 1) 466 key, value = el.split('=', 1)
467 clientEnv[str(key)] = str(value) 467 clientEnv[str(key)] = str(value)
468 except ValueError:
469 pass
470 if execPath: 468 if execPath:
471 if "PATH" in clientEnv: 469 if "PATH" in clientEnv:
472 clientEnv["PATH"] = os.pathsep.join( 470 clientEnv["PATH"] = os.pathsep.join(
473 [execPath, clientEnv["PATH"]]) 471 [execPath, clientEnv["PATH"]])
474 else: 472 else:
600 if sock in self.__pendingConnections: 598 if sock in self.__pendingConnections:
601 self.__pendingConnections.remove(sock) 599 self.__pendingConnections.remove(sock)
602 600
603 if not self.__connections: 601 if not self.__connections:
604 # no active connections anymore 602 # no active connections anymore
605 try: 603 with contextlib.suppress(RuntimeError):
606 self.debugServer.signalLastClientExited() 604 self.debugServer.signalLastClientExited()
607 except RuntimeError:
608 # debug server object might have been deleted already 605 # debug server object might have been deleted already
609 # ignore this 606 # ignore this
610 pass
611 self.__autoContinued.clear() 607 self.__autoContinued.clear()
612 self.debugServer.startClient() 608 self.debugServer.startClient()
613 609
614 def getDebuggerIds(self): 610 def getDebuggerIds(self):
615 """ 611 """
913 @param cond condition of the breakpoint 909 @param cond condition of the breakpoint
914 @type str 910 @type str
915 @param temp flag indicating a temporary breakpoint 911 @param temp flag indicating a temporary breakpoint
916 @type bool 912 @type bool
917 """ 913 """
918 if debuggerId: 914 debuggerList = ([debuggerId] if debuggerId
919 debuggerList = [debuggerId] 915 else list(self.__connections.keys()))
920 else:
921 debuggerList = list(self.__connections.keys())
922 for debuggerId in debuggerList: 916 for debuggerId in debuggerList:
923 self.__sendJsonCommand("RequestBreakpoint", { 917 self.__sendJsonCommand("RequestBreakpoint", {
924 "filename": self.translate(fn, False), 918 "filename": self.translate(fn, False),
925 "line": line, 919 "line": line,
926 "temporary": temp, 920 "temporary": temp,
939 @param line linenumber of the breakpoint 933 @param line linenumber of the breakpoint
940 @type int 934 @type int
941 @param enable flag indicating enabling or disabling a breakpoint 935 @param enable flag indicating enabling or disabling a breakpoint
942 @type bool 936 @type bool
943 """ 937 """
944 if debuggerId: 938 debuggerList = ([debuggerId] if debuggerId
945 debuggerList = [debuggerId] 939 else list(self.__connections.keys()))
946 else:
947 debuggerList = list(self.__connections.keys())
948 for debuggerId in debuggerList: 940 for debuggerId in debuggerList:
949 self.__sendJsonCommand("RequestBreakpointEnable", { 941 self.__sendJsonCommand("RequestBreakpointEnable", {
950 "filename": self.translate(fn, False), 942 "filename": self.translate(fn, False),
951 "line": line, 943 "line": line,
952 "enable": enable, 944 "enable": enable,
963 @param line linenumber of the breakpoint 955 @param line linenumber of the breakpoint
964 @type int 956 @type int
965 @param count number of occurrences to ignore 957 @param count number of occurrences to ignore
966 @type int 958 @type int
967 """ 959 """
968 if debuggerId: 960 debuggerList = ([debuggerId] if debuggerId
969 debuggerList = [debuggerId] 961 else list(self.__connections.keys()))
970 else:
971 debuggerList = list(self.__connections.keys())
972 for debuggerId in debuggerList: 962 for debuggerId in debuggerList:
973 self.__sendJsonCommand("RequestBreakpointIgnore", { 963 self.__sendJsonCommand("RequestBreakpointIgnore", {
974 "filename": self.translate(fn, False), 964 "filename": self.translate(fn, False),
975 "line": line, 965 "line": line,
976 "count": count, 966 "count": count,
987 @param setWatch flag indicating setting or resetting a watch expression 977 @param setWatch flag indicating setting or resetting a watch expression
988 @type bool 978 @type bool
989 @param temp flag indicating a temporary watch expression 979 @param temp flag indicating a temporary watch expression
990 @type bool 980 @type bool
991 """ 981 """
992 if debuggerId: 982 debuggerList = ([debuggerId] if debuggerId
993 debuggerList = [debuggerId] 983 else list(self.__connections.keys()))
994 else:
995 debuggerList = list(self.__connections.keys())
996 for debuggerId in debuggerList: 984 for debuggerId in debuggerList:
997 # cond is combination of cond and special (s. watch expression 985 # cond is combination of cond and special (s. watch expression
998 # viewer) 986 # viewer)
999 self.__sendJsonCommand("RequestWatch", { 987 self.__sendJsonCommand("RequestWatch", {
1000 "temporary": temp, 988 "temporary": temp,
1011 @param cond expression of the watch expression 999 @param cond expression of the watch expression
1012 @type str 1000 @type str
1013 @param enable flag indicating enabling or disabling a watch expression 1001 @param enable flag indicating enabling or disabling a watch expression
1014 @type bool 1002 @type bool
1015 """ 1003 """
1016 if debuggerId: 1004 debuggerList = ([debuggerId] if debuggerId
1017 debuggerList = [debuggerId] 1005 else list(self.__connections.keys()))
1018 else:
1019 debuggerList = list(self.__connections.keys())
1020 for debuggerId in debuggerList: 1006 for debuggerId in debuggerList:
1021 # cond is combination of cond and special (s. watch expression 1007 # cond is combination of cond and special (s. watch expression
1022 # viewer) 1008 # viewer)
1023 self.__sendJsonCommand("RequestWatchEnable", { 1009 self.__sendJsonCommand("RequestWatchEnable", {
1024 "condition": cond, 1010 "condition": cond,
1035 @param cond expression of the watch expression 1021 @param cond expression of the watch expression
1036 @type str 1022 @type str
1037 @param count number of occurrences to ignore 1023 @param count number of occurrences to ignore
1038 @type int 1024 @type int
1039 """ 1025 """
1040 if debuggerId: 1026 debuggerList = ([debuggerId] if debuggerId
1041 debuggerList = [debuggerId] 1027 else list(self.__connections.keys()))
1042 else:
1043 debuggerList = list(self.__connections.keys())
1044 for debuggerId in debuggerList: 1028 for debuggerId in debuggerList:
1045 # cond is combination of cond and special (s. watch expression 1029 # cond is combination of cond and special (s. watch expression
1046 # viewer) 1030 # viewer)
1047 self.__sendJsonCommand("RequestWatchIgnore", { 1031 self.__sendJsonCommand("RequestWatchIgnore", {
1048 "condition": cond, 1032 "condition": cond,

eric ide

mercurial