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 |
52 |
55 self.debugServer = debugServer |
53 self.debugServer = debugServer |
56 self.passive = passive |
54 self.passive = passive |
57 self.process = None |
55 self.process = None |
58 self.__variant = pythonVariant |
|
59 self.__startedVenv = "" |
56 self.__startedVenv = "" |
60 |
57 |
61 self.qsock = None |
58 self.qsock = None |
62 self.queue = [] |
59 self.queue = [] |
63 |
60 |
169 @rtype tuple of (QProcess, bool, str) |
166 @rtype tuple of (QProcess, bool, str) |
170 """ |
167 """ |
171 global origPathEnv |
168 global origPathEnv |
172 |
169 |
173 if not venvName: |
170 if not venvName: |
174 if self.__variant == "Python2": |
171 venvName = Preferences.getDebugger("Python3VirtualEnv") |
175 venvName = Preferences.getDebugger("Python2VirtualEnv") |
|
176 else: |
|
177 venvName = Preferences.getDebugger("Python3VirtualEnv") |
|
178 venvManager = e5App().getObject("VirtualEnvManager") |
172 venvManager = e5App().getObject("VirtualEnvManager") |
179 interpreter = venvManager.getVirtualenvInterpreter(venvName) |
173 interpreter = venvManager.getVirtualenvInterpreter(venvName) |
180 execPath = venvManager.getVirtualenvExecPath(venvName) |
174 execPath = venvManager.getVirtualenvExecPath(venvName) |
181 if (interpreter == "" and |
175 if interpreter == "": |
182 int(self.__variant[-1]) == sys.version_info[0]): |
|
183 # use the interpreter used to run eric for identical variants |
176 # use the interpreter used to run eric for identical variants |
184 interpreter = sys.executable.replace("w.exe", ".exe") |
177 interpreter = sys.executable.replace("w.exe", ".exe") |
185 if interpreter == "": |
178 if interpreter == "": |
186 E5MessageBox.critical( |
179 E5MessageBox.critical( |
187 None, |
180 None, |
188 self.tr("Start Debugger"), |
181 self.tr("Start Debugger"), |
189 self.tr( |
182 self.tr( |
190 """<p>No suitable {0} environment configured.</p>""") |
183 """<p>No suitable Python3 environment configured.</p>""") |
191 .format(self.__variant)) |
184 ) |
192 return None, False, "" |
185 return None, False, "" |
193 |
186 |
194 if self.__variant == "Python2": |
187 debugClientType = Preferences.getDebugger("DebugClientType3") |
195 debugClientType = Preferences.getDebugger("DebugClientType") |
|
196 else: |
|
197 debugClientType = Preferences.getDebugger("DebugClientType3") |
|
198 if debugClientType == "standard": |
188 if debugClientType == "standard": |
199 debugClient = os.path.join(getConfig('ericDir'), |
189 debugClient = os.path.join(getConfig('ericDir'), |
200 "DebugClients", "Python", |
190 "DebugClients", "Python", |
201 "DebugClient.py") |
191 "DebugClient.py") |
202 else: |
192 else: |
203 if self.__variant == "Python2": |
193 debugClient = Preferences.getDebugger("DebugClient3") |
204 debugClient = Preferences.getDebugger("DebugClient") |
|
205 else: |
|
206 debugClient = Preferences.getDebugger("DebugClient3") |
|
207 if debugClient == "": |
194 if debugClient == "": |
208 debugClient = os.path.join(sys.path[0], |
195 debugClient = os.path.join(sys.path[0], |
209 "DebugClients", "Python", |
196 "DebugClients", "Python", |
210 "DebugClient.py") |
197 "DebugClient.py") |
211 |
198 |
212 if self.__variant == "Python2": |
199 redirect = str(Preferences.getDebugger("Python3Redirect")) |
213 redirect = str(Preferences.getDebugger("PythonRedirect")) |
200 noencoding = (Preferences.getDebugger("Python3NoEncoding") and |
214 noencoding = (Preferences.getDebugger("PythonNoEncoding") and |
201 '--no-encoding' or '') |
215 '--no-encoding' or '') |
|
216 else: |
|
217 redirect = str(Preferences.getDebugger("Python3Redirect")) |
|
218 noencoding = (Preferences.getDebugger("Python3NoEncoding") and |
|
219 '--no-encoding' or '') |
|
220 |
202 |
221 if Preferences.getDebugger("RemoteDbgEnabled"): |
203 if Preferences.getDebugger("RemoteDbgEnabled"): |
222 ipaddr = self.debugServer.getHostAddress(False) |
204 ipaddr = self.debugServer.getHostAddress(False) |
223 rexec = Preferences.getDebugger("RemoteExecution") |
205 rexec = Preferences.getDebugger("RemoteExecution") |
224 rhost = Preferences.getDebugger("RemoteHost") |
206 rhost = Preferences.getDebugger("RemoteHost") |
352 # start debugger with project specific settings |
334 # start debugger with project specific settings |
353 debugClient = project.getDebugProperty("DEBUGCLIENT") |
335 debugClient = project.getDebugProperty("DEBUGCLIENT") |
354 if not venvName: |
336 if not venvName: |
355 venvName = project.getDebugProperty("VIRTUALENV") |
337 venvName = project.getDebugProperty("VIRTUALENV") |
356 if not venvName: |
338 if not venvName: |
357 if project.getProjectLanguage() == "Python2": |
339 if project.getProjectLanguage() == "Python3": |
358 venvName = Preferences.getDebugger("Python2VirtualEnv") |
|
359 elif project.getProjectLanguage() == "Python3": |
|
360 venvName = Preferences.getDebugger("Python3VirtualEnv") |
340 venvName = Preferences.getDebugger("Python3VirtualEnv") |
361 |
341 |
362 redirect = str(project.getDebugProperty("REDIRECT")) |
342 redirect = str(project.getDebugProperty("REDIRECT")) |
363 noencoding = ( |
343 noencoding = ( |
364 project.getDebugProperty("NOENCODING") and '--no-encoding' or '') |
344 project.getDebugProperty("NOENCODING") and '--no-encoding' or '') |
373 if interpreter == "": |
353 if interpreter == "": |
374 E5MessageBox.critical( |
354 E5MessageBox.critical( |
375 None, |
355 None, |
376 self.tr("Start Debugger"), |
356 self.tr("Start Debugger"), |
377 self.tr( |
357 self.tr( |
378 """<p>No suitable {0} environment configured.</p>""") |
358 """<p>No suitable Python3 environment configured.</p>""") |
379 .format(self.__variant)) |
359 ) |
380 return None, self.__isNetworked, "" |
360 return None, self.__isNetworked, "" |
381 |
361 |
382 if project.getDebugProperty("REMOTEDEBUGGER"): |
362 if project.getDebugProperty("REMOTEDEBUGGER"): |
383 ipaddr = self.debugServer.getHostAddress(False) |
363 ipaddr = self.debugServer.getHostAddress(False) |
384 rexec = project.getDebugProperty("REMOTECOMMAND") |
364 rexec = project.getDebugProperty("REMOTECOMMAND") |
1315 @param passive flag indicating passive connection mode |
1295 @param passive flag indicating passive connection mode |
1316 @type bool |
1296 @type bool |
1317 @return instantiated debugger interface |
1297 @return instantiated debugger interface |
1318 @rtype DebuggerInterfacePython |
1298 @rtype DebuggerInterfacePython |
1319 """ |
1299 """ |
1320 return DebuggerInterfacePython(debugServer, passive, "Python2") |
1300 return DebuggerInterfacePython(debugServer, passive) |
1321 |
|
1322 |
|
1323 def createDebuggerInterfacePython3(debugServer, passive): |
|
1324 """ |
|
1325 Module function to create a debugger interface instance. |
|
1326 |
|
1327 |
|
1328 @param debugServer reference to the debug server |
|
1329 @type DebugServer |
|
1330 @param passive flag indicating passive connection mode |
|
1331 @type bool |
|
1332 @return instantiated debugger interface |
|
1333 @rtype DebuggerInterfacePython |
|
1334 """ |
|
1335 return DebuggerInterfacePython(debugServer, passive, "Python3") |
|
1336 |
1301 |
1337 |
1302 |
1338 def getRegistryData(): |
1303 def getRegistryData(): |
1339 """ |
1304 """ |
1340 Module function to get characterizing data for the supported debugger |
1305 Module function to get characterizing data for the supported debugger |
1343 @return list of tuples containing the client type, the client capabilities, |
1308 @return list of tuples containing the client type, the client capabilities, |
1344 the client file type associations and a reference to the creation |
1309 the client file type associations and a reference to the creation |
1345 function |
1310 function |
1346 @rtype list of tuple of (str, int, list of str, function) |
1311 @rtype list of tuple of (str, int, list of str, function) |
1347 """ |
1312 """ |
1348 py2Exts = [] |
|
1349 for ext in Preferences.getDebugger("PythonExtensions").split(): |
|
1350 if ext.startswith("."): |
|
1351 py2Exts.append(ext) |
|
1352 else: |
|
1353 py2Exts.append(".{0}".format(ext)) |
|
1354 |
|
1355 py3Exts = [] |
1313 py3Exts = [] |
1356 for ext in Preferences.getDebugger("Python3Extensions").split(): |
1314 for ext in Preferences.getDebugger("Python3Extensions").split(): |
1357 if ext.startswith("."): |
1315 if ext.startswith("."): |
1358 py3Exts.append(ext) |
1316 py3Exts.append(ext) |
1359 else: |
1317 else: |
1360 py3Exts.append(".{0}".format(ext)) |
1318 py3Exts.append(".{0}".format(ext)) |
1361 |
1319 |
1362 registryData = [] |
1320 registryData = [] |
1363 if py2Exts and (Preferences.getDebugger("Python2VirtualEnv") or |
|
1364 sys.version_info[0] == 2): |
|
1365 registryData.append( |
|
1366 ("Python2", ClientDefaultCapabilities, py2Exts, |
|
1367 createDebuggerInterfacePython2) |
|
1368 ) |
|
1369 |
|
1370 if py3Exts and (Preferences.getDebugger("Python3VirtualEnv") or |
1321 if py3Exts and (Preferences.getDebugger("Python3VirtualEnv") or |
1371 sys.version_info[0] >= 3): |
1322 sys.version_info[0] >= 3): |
1372 registryData.append( |
1323 registryData.append( |
1373 ("Python3", ClientDefaultCapabilities, py3Exts, |
1324 ("Python3", ClientDefaultCapabilities, py3Exts, |
1374 createDebuggerInterfacePython3) |
1325 createDebuggerInterfacePython3) |