eric6/Debugger/DebuggerInterfacePython.py

branch
multi_processing
changeset 7646
39e3db2b4936
parent 7564
787684e6f2f3
parent 7639
422fd05e9c91
child 7802
eefe954f01e8
equal deleted inserted replaced
7627:812ee8c0a91a 7646:39e3db2b4936
31 ClientDefaultCapabilities = DebugClientCapabilities.HasAll 31 ClientDefaultCapabilities = DebugClientCapabilities.HasAll
32 32
33 33
34 class DebuggerInterfacePython(QObject): 34 class DebuggerInterfacePython(QObject):
35 """ 35 """
36 Class implementing the debugger interface for the debug server for Python 2 36 Class implementing the debugger interface for the debug server for
37 and Python 3. 37 Python 3.
38 """ 38 """
39 def __init__(self, debugServer, passive, pythonVariant): 39 def __init__(self, debugServer, passive):
40 """ 40 """
41 Constructor 41 Constructor
42 42
43 @param debugServer reference to the debug server 43 @param debugServer reference to the debug server
44 @type DebugServer 44 @type DebugServer
45 @param passive flag indicating passive connection mode 45 @param passive flag indicating passive connection mode
46 @type bool 46 @type bool
47 @param pythonVariant Python variant to instantiate for
48 @type str (one of Python2 or Python3)
49 """ 47 """
50 super(DebuggerInterfacePython, self).__init__() 48 super(DebuggerInterfacePython, self).__init__()
51 49
52 self.__isNetworked = True 50 self.__isNetworked = True
53 self.__autoContinue = False 51 self.__autoContinue = False
54 self.__autoContinued = [] 52 self.__autoContinued = []
55 53
56 self.debugServer = debugServer 54 self.debugServer = debugServer
57 self.passive = passive 55 self.passive = passive
58 self.process = None 56 self.process = None
59 self.__variant = pythonVariant
60 self.__startedVenv = "" 57 self.__startedVenv = ""
61 58
62 self.queue = [] 59 self.queue = []
63 self.__master = None 60 self.__master = None
64 self.__connections = {} 61 self.__connections = {}
178 @rtype tuple of (QProcess, bool, str) 175 @rtype tuple of (QProcess, bool, str)
179 """ 176 """
180 global origPathEnv 177 global origPathEnv
181 178
182 if not venvName: 179 if not venvName:
183 if self.__variant == "Python2": 180 venvName = Preferences.getDebugger("Python3VirtualEnv")
184 venvName = Preferences.getDebugger("Python2VirtualEnv")
185 else:
186 venvName = Preferences.getDebugger("Python3VirtualEnv")
187 venvManager = e5App().getObject("VirtualEnvManager") 181 venvManager = e5App().getObject("VirtualEnvManager")
188 interpreter = venvManager.getVirtualenvInterpreter(venvName) 182 interpreter = venvManager.getVirtualenvInterpreter(venvName)
189 execPath = venvManager.getVirtualenvExecPath(venvName) 183 execPath = venvManager.getVirtualenvExecPath(venvName)
190 if (interpreter == "" and 184 if interpreter == "":
191 int(self.__variant[-1]) == sys.version_info[0]):
192 # use the interpreter used to run eric for identical variants 185 # use the interpreter used to run eric for identical variants
193 interpreter = sys.executable.replace("w.exe", ".exe") 186 interpreter = sys.executable.replace("w.exe", ".exe")
194 if interpreter == "": 187 if interpreter == "":
195 E5MessageBox.critical( 188 E5MessageBox.critical(
196 None, 189 None,
197 self.tr("Start Debugger"), 190 self.tr("Start Debugger"),
198 self.tr( 191 self.tr(
199 """<p>No suitable {0} environment configured.</p>""") 192 """<p>No suitable Python3 environment configured.</p>""")
200 .format(self.__variant)) 193 )
201 return None, False, "" 194 return None, False, ""
202 195
203 if self.__variant == "Python2": 196 debugClientType = Preferences.getDebugger("DebugClientType3")
204 debugClientType = Preferences.getDebugger("DebugClientType")
205 else:
206 debugClientType = Preferences.getDebugger("DebugClientType3")
207 if debugClientType == "standard": 197 if debugClientType == "standard":
208 debugClient = os.path.join(getConfig('ericDir'), 198 debugClient = os.path.join(getConfig('ericDir'),
209 "DebugClients", "Python", 199 "DebugClients", "Python",
210 "DebugClient.py") 200 "DebugClient.py")
211 else: 201 else:
212 if self.__variant == "Python2": 202 debugClient = Preferences.getDebugger("DebugClient3")
213 debugClient = Preferences.getDebugger("DebugClient")
214 else:
215 debugClient = Preferences.getDebugger("DebugClient3")
216 if debugClient == "": 203 if debugClient == "":
217 debugClient = os.path.join(sys.path[0], 204 debugClient = os.path.join(sys.path[0],
218 "DebugClients", "Python", 205 "DebugClients", "Python",
219 "DebugClient.py") 206 "DebugClient.py")
220 207
221 if self.__variant == "Python2": 208 redirect = str(Preferences.getDebugger("Python3Redirect"))
222 redirect = str(Preferences.getDebugger("PythonRedirect")) 209 noencoding = (Preferences.getDebugger("Python3NoEncoding") and
223 noencoding = (Preferences.getDebugger("PythonNoEncoding") and 210 '--no-encoding' or '')
224 '--no-encoding' or '')
225 else:
226 redirect = str(Preferences.getDebugger("Python3Redirect"))
227 noencoding = (Preferences.getDebugger("Python3NoEncoding") and
228 '--no-encoding' or '')
229 multiprocessEnabled = ( 211 multiprocessEnabled = (
230 '--multiprocess' if Preferences.getDebugger("MultiProcessEnabled") 212 '--multiprocess' if Preferences.getDebugger("MultiProcessEnabled")
231 else '' 213 else ''
232 ) 214 )
233 215
376 # start debugger with project specific settings 358 # start debugger with project specific settings
377 debugClient = project.getDebugProperty("DEBUGCLIENT") 359 debugClient = project.getDebugProperty("DEBUGCLIENT")
378 if not venvName: 360 if not venvName:
379 venvName = project.getDebugProperty("VIRTUALENV") 361 venvName = project.getDebugProperty("VIRTUALENV")
380 if not venvName: 362 if not venvName:
381 if project.getProjectLanguage() == "Python2": 363 if project.getProjectLanguage() == "Python3":
382 venvName = Preferences.getDebugger("Python2VirtualEnv")
383 elif project.getProjectLanguage() == "Python3":
384 venvName = Preferences.getDebugger("Python3VirtualEnv") 364 venvName = Preferences.getDebugger("Python3VirtualEnv")
385 365
386 redirect = str(project.getDebugProperty("REDIRECT")) 366 redirect = str(project.getDebugProperty("REDIRECT"))
387 noencoding = ( 367 noencoding = (
388 '--no-encoding' if project.getDebugProperty("NOENCODING") else '' 368 '--no-encoding' if project.getDebugProperty("NOENCODING") else ''
393 ) 373 )
394 374
395 venvManager = e5App().getObject("VirtualEnvManager") 375 venvManager = e5App().getObject("VirtualEnvManager")
396 interpreter = venvManager.getVirtualenvInterpreter(venvName) 376 interpreter = venvManager.getVirtualenvInterpreter(venvName)
397 execPath = venvManager.getVirtualenvExecPath(venvName) 377 execPath = venvManager.getVirtualenvExecPath(venvName)
398 if (interpreter == "" and 378 if (
399 project.getProjectLanguage().startswith("Python") and 379 interpreter == "" and
400 sys.version_info[0] == int(project.getProjectLanguage()[-1])): 380 project.getProjectLanguage().startswith("Python")
381 ):
401 interpreter = sys.executable.replace("w.exe", ".exe") 382 interpreter = sys.executable.replace("w.exe", ".exe")
402 if interpreter == "": 383 if interpreter == "":
403 E5MessageBox.critical( 384 E5MessageBox.critical(
404 None, 385 None,
405 self.tr("Start Debugger"), 386 self.tr("Start Debugger"),
406 self.tr( 387 self.tr(
407 """<p>No suitable {0} environment configured.</p>""") 388 """<p>No suitable Python3 environment configured.</p>""")
408 .format(self.__variant)) 389 )
409 return None, self.__isNetworked, "" 390 return None, self.__isNetworked, ""
410 391
411 if project.getDebugProperty("REMOTEDEBUGGER"): 392 if project.getDebugProperty("REMOTEDEBUGGER"):
412 ipaddr = self.debugServer.getHostAddress(False) 393 ipaddr = self.debugServer.getHostAddress(False)
413 rexec = project.getDebugProperty("REMOTECOMMAND") 394 rexec = project.getDebugProperty("REMOTECOMMAND")
1622 length = "{0:09d}".format(len(data)) 1603 length = "{0:09d}".format(len(data))
1623 sock.write(length.encode() + data) 1604 sock.write(length.encode() + data)
1624 sock.flush() 1605 sock.flush()
1625 1606
1626 1607
1627 def createDebuggerInterfacePython2(debugServer, passive): 1608 def createDebuggerInterfacePython3(debugServer, passive):
1628 """ 1609 """
1629 Module function to create a debugger interface instance. 1610 Module function to create a debugger interface instance.
1630 1611
1631 1612
1632 @param debugServer reference to the debug server 1613 @param debugServer reference to the debug server
1634 @param passive flag indicating passive connection mode 1615 @param passive flag indicating passive connection mode
1635 @type bool 1616 @type bool
1636 @return instantiated debugger interface 1617 @return instantiated debugger interface
1637 @rtype DebuggerInterfacePython 1618 @rtype DebuggerInterfacePython
1638 """ 1619 """
1639 return DebuggerInterfacePython(debugServer, passive, "Python2") 1620 return DebuggerInterfacePython(debugServer, passive)
1640
1641
1642 def createDebuggerInterfacePython3(debugServer, passive):
1643 """
1644 Module function to create a debugger interface instance.
1645
1646
1647 @param debugServer reference to the debug server
1648 @type DebugServer
1649 @param passive flag indicating passive connection mode
1650 @type bool
1651 @return instantiated debugger interface
1652 @rtype DebuggerInterfacePython
1653 """
1654 return DebuggerInterfacePython(debugServer, passive, "Python3")
1655 1621
1656 1622
1657 def getRegistryData(): 1623 def getRegistryData():
1658 """ 1624 """
1659 Module function to get characterizing data for the supported debugger 1625 Module function to get characterizing data for the supported debugger
1662 @return list of tuples containing the client type, the client capabilities, 1628 @return list of tuples containing the client type, the client capabilities,
1663 the client file type associations and a reference to the creation 1629 the client file type associations and a reference to the creation
1664 function 1630 function
1665 @rtype list of tuple of (str, int, list of str, function) 1631 @rtype list of tuple of (str, int, list of str, function)
1666 """ 1632 """
1667 py2Exts = []
1668 for ext in Preferences.getDebugger("PythonExtensions").split():
1669 if ext.startswith("."):
1670 py2Exts.append(ext)
1671 else:
1672 py2Exts.append(".{0}".format(ext))
1673
1674 py3Exts = [] 1633 py3Exts = []
1675 for ext in Preferences.getDebugger("Python3Extensions").split(): 1634 for ext in Preferences.getDebugger("Python3Extensions").split():
1676 if ext.startswith("."): 1635 if ext.startswith("."):
1677 py3Exts.append(ext) 1636 py3Exts.append(ext)
1678 else: 1637 else:
1679 py3Exts.append(".{0}".format(ext)) 1638 py3Exts.append(".{0}".format(ext))
1680 1639
1681 registryData = [] 1640 registryData = []
1682 if py2Exts and (Preferences.getDebugger("Python2VirtualEnv") or 1641 if py3Exts:
1683 sys.version_info[0] == 2):
1684 registryData.append(
1685 ("Python2", ClientDefaultCapabilities, py2Exts,
1686 createDebuggerInterfacePython2)
1687 )
1688
1689 if py3Exts and (Preferences.getDebugger("Python3VirtualEnv") or
1690 sys.version_info[0] >= 3):
1691 registryData.append( 1642 registryData.append(
1692 ("Python3", ClientDefaultCapabilities, py3Exts, 1643 ("Python3", ClientDefaultCapabilities, py3Exts,
1693 createDebuggerInterfacePython3) 1644 createDebuggerInterfacePython3)
1694 ) 1645 )
1695 1646

eric ide

mercurial