12 import shlex |
12 import shlex |
13 import contextlib |
13 import contextlib |
14 |
14 |
15 from PyQt6.QtCore import QObject, QProcess, QProcessEnvironment, QTimer |
15 from PyQt6.QtCore import QObject, QProcess, QProcessEnvironment, QTimer |
16 |
16 |
17 from EricWidgets.EricApplication import ericApp |
17 from eric7.EricWidgets.EricApplication import ericApp |
18 from EricWidgets import EricMessageBox |
18 from eric7.EricWidgets import EricMessageBox |
19 |
19 |
20 from . import DebugClientCapabilities |
20 from . import DebugClientCapabilities |
21 |
21 |
22 import Globals |
22 from eric7 import Globals, Preferences, Utilities |
23 import Preferences |
|
24 import Utilities |
|
25 |
23 |
26 from eric7config import getConfig |
24 from eric7config import getConfig |
27 |
25 |
28 |
26 |
29 ClientDefaultCapabilities = DebugClientCapabilities.HasAll |
27 ClientDefaultCapabilities = DebugClientCapabilities.HasAll |
181 """ |
179 """ |
182 global origPathEnv |
180 global origPathEnv |
183 |
181 |
184 if not venvName: |
182 if not venvName: |
185 venvName = Preferences.getDebugger("Python3VirtualEnv") |
183 venvName = Preferences.getDebugger("Python3VirtualEnv") |
186 venvManager = ericApp().getObject("VirtualEnvManager") |
184 if venvName == self.debugServer.getProjectEnvironmentString(): |
187 interpreter = venvManager.getVirtualenvInterpreter(venvName) |
185 project = ericApp().getObject("Project") |
188 execPath = venvManager.getVirtualenvExecPath(venvName) |
186 venvName = project.getProjectVenv() |
|
187 execPath = project.getProjectExecPath() |
|
188 interpreter = project.getProjectInterpreter() |
|
189 else: |
|
190 venvManager = ericApp().getObject("VirtualEnvManager") |
|
191 interpreter = venvManager.getVirtualenvInterpreter(venvName) |
|
192 execPath = venvManager.getVirtualenvExecPath(venvName) |
189 if interpreter == "": |
193 if interpreter == "": |
190 # use the interpreter used to run eric for identical variants |
194 # use the interpreter used to run eric for identical variants |
191 interpreter = Globals.getPythonExecutable() |
195 interpreter = Globals.getPythonExecutable() |
192 if interpreter == "": |
196 if interpreter == "": |
193 EricMessageBox.critical( |
197 EricMessageBox.critical( |
197 ) |
201 ) |
198 return None, False, "" |
202 return None, False, "" |
199 |
203 |
200 self.__inShutdown = False |
204 self.__inShutdown = False |
201 |
205 |
202 debugClientType = Preferences.getDebugger("DebugClientType3") |
206 debugClient = self.__determineDebugClient() |
203 if debugClientType == "standard": |
|
204 debugClient = os.path.join( |
|
205 getConfig("ericDir"), "DebugClients", "Python", "DebugClient.py" |
|
206 ) |
|
207 else: |
|
208 debugClient = Preferences.getDebugger("DebugClient3") |
|
209 if debugClient == "": |
|
210 # use the 'standard' debug client if no custom one was configured |
|
211 debugClient = os.path.join( |
|
212 getConfig("ericDir"), "DebugClients", "Python", "DebugClient.py" |
|
213 ) |
|
214 |
207 |
215 redirect = ( |
208 redirect = ( |
216 str(configOverride["redirect"]) |
209 str(configOverride["redirect"]) |
217 if configOverride and configOverride["enable"] |
210 if configOverride and configOverride["enable"] |
218 else str(Preferences.getDebugger("Python3Redirect")) |
211 else str(Preferences.getDebugger("Python3Redirect")) |
344 else: |
337 else: |
345 self.__startedVenv = venvName |
338 self.__startedVenv = venvName |
346 |
339 |
347 return process, self.__isNetworked, interpreter |
340 return process, self.__isNetworked, interpreter |
348 |
341 |
|
342 def __determineDebugClient(self): |
|
343 """ |
|
344 Private method to determine the debug client to be started. |
|
345 |
|
346 @return path of the debug client |
|
347 @rtype str |
|
348 """ |
|
349 debugClientType = Preferences.getDebugger("DebugClientType3") |
|
350 if debugClientType == "standard": |
|
351 debugClient = os.path.join( |
|
352 getConfig("ericDir"), "DebugClients", "Python", "DebugClient.py" |
|
353 ) |
|
354 else: |
|
355 debugClient = Preferences.getDebugger("DebugClient3") |
|
356 if debugClient == "": |
|
357 # use the 'standard' debug client if no custom one was configured |
|
358 debugClient = os.path.join( |
|
359 getConfig("ericDir"), "DebugClients", "Python", "DebugClient.py" |
|
360 ) |
|
361 |
|
362 return debugClient |
|
363 |
349 def startRemoteForProject( |
364 def startRemoteForProject( |
350 self, |
365 self, |
351 port, |
366 port, |
352 runInConsole, |
367 runInConsole, |
353 venvName, |
368 venvName, |
382 if not project.isDebugPropertiesLoaded(): |
397 if not project.isDebugPropertiesLoaded(): |
383 return None, self.__isNetworked, "" |
398 return None, self.__isNetworked, "" |
384 |
399 |
385 # start debugger with project specific settings |
400 # start debugger with project specific settings |
386 debugClient = project.getDebugProperty("DEBUGCLIENT") |
401 debugClient = project.getDebugProperty("DEBUGCLIENT") |
|
402 if not bool(debugClient) or not os.path.exists(debugClient): |
|
403 debugClient = self.__determineDebugClient() |
387 |
404 |
388 redirect = ( |
405 redirect = ( |
389 str(configOverride["redirect"]) |
406 str(configOverride["redirect"]) |
390 if configOverride and configOverride["enable"] |
407 if configOverride and configOverride["enable"] |
391 else str(project.getDebugProperty("REDIRECT")) |
408 else str(project.getDebugProperty("REDIRECT")) |
393 noencoding = "--no-encoding" if project.getDebugProperty("NOENCODING") else "" |
410 noencoding = "--no-encoding" if project.getDebugProperty("NOENCODING") else "" |
394 multiprocessEnabled = ( |
411 multiprocessEnabled = ( |
395 "--multiprocess" if Preferences.getDebugger("MultiProcessEnabled") else "" |
412 "--multiprocess" if Preferences.getDebugger("MultiProcessEnabled") else "" |
396 ) |
413 ) |
397 |
414 |
398 if venvName: |
415 if venvName and venvName != self.debugServer.getProjectEnvironmentString(): |
399 venvManager = ericApp().getObject("VirtualEnvManager") |
416 venvManager = ericApp().getObject("VirtualEnvManager") |
400 interpreter = venvManager.getVirtualenvInterpreter(venvName) |
417 interpreter = venvManager.getVirtualenvInterpreter(venvName) |
401 execPath = venvManager.getVirtualenvExecPath(venvName) |
418 execPath = venvManager.getVirtualenvExecPath(venvName) |
402 else: |
419 else: |
403 venvName = project.getProjectVenv() |
420 venvName = project.getProjectVenv() |
620 self.__pendingConnections.remove(sock) |
637 self.__pendingConnections.remove(sock) |
621 |
638 |
622 if not self.__connections: |
639 if not self.__connections: |
623 # no active connections anymore |
640 # no active connections anymore |
624 with contextlib.suppress(RuntimeError): |
641 with contextlib.suppress(RuntimeError): |
625 self.debugServer.signalLastClientExited() |
|
626 # debug server object might have been deleted already |
642 # debug server object might have been deleted already |
627 # ignore this |
643 # ignore this |
628 self.__autoContinued.clear() |
644 self.debugServer.signalLastClientExited() |
629 self.debugServer.startClient() |
645 self.__autoContinued.clear() |
|
646 if not self.__inShutdown: |
|
647 self.debugServer.startClient() |
630 |
648 |
631 def getDebuggerIds(self): |
649 def getDebuggerIds(self): |
632 """ |
650 """ |
633 Public method to return the IDs of the connected debugger backends. |
651 Public method to return the IDs of the connected debugger backends. |
634 |
652 |