Started to change the file browser model such, that the sys.path entry is dependent on the running interpreter.

Tue, 11 Mar 2014 20:07:05 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 11 Mar 2014 20:07:05 +0100
changeset 3357
2390df6f42ba
parent 3356
22633c0739e2
child 3358
57af7e9fda48

Started to change the file browser model such, that the sys.path entry is dependent on the running interpreter.

Debugger/DebugServer.py file | annotate | diff | comparison | revisions
Debugger/DebuggerInterfaceNone.py file | annotate | diff | comparison | revisions
Debugger/DebuggerInterfacePython.py file | annotate | diff | comparison | revisions
Debugger/DebuggerInterfacePython3.py file | annotate | diff | comparison | revisions
Debugger/DebuggerInterfaceRuby.py file | annotate | diff | comparison | revisions
UI/Browser.py file | annotate | diff | comparison | revisions
UI/BrowserModel.py file | annotate | diff | comparison | revisions
UI/UserInterface.py file | annotate | diff | comparison | revisions
--- a/Debugger/DebugServer.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/Debugger/DebugServer.py	Tue Mar 11 20:07:05 2014 +0100
@@ -84,6 +84,8 @@
         connected in passive debug mode
     @signal clientGone(bool) emitted if the client went away (planned or
         unplanned)
+    @signal clientInterpreterChanged(str) emitted to signal a change of the
+        client interpreter
     @signal utPrepared(nrTests, exc_type, exc_value) emitted after the client
         has loaded a unittest suite
     @signal utFinished() emitted after the client signalled the end of the
@@ -128,6 +130,7 @@
     clientBanner = pyqtSignal(str, str, str)
     clientCapabilities = pyqtSignal(int, str)
     clientCompletionList = pyqtSignal(list, str)
+    clientInterpreterChanged = pyqtSignal(str)
     utPrepared = pyqtSignal(int, str, str)
     utStartTest = pyqtSignal(str, str)
     utStopTest = pyqtSignal()
@@ -179,6 +182,7 @@
         self.debugging = False
         self.running = False
         self.clientProcess = None
+        self.clientInterpreter = ""
         self.clientType = \
             Preferences.Prefs.settings.value('DebugClient/Type', 'Python3')
         self.lastClientType = ''
@@ -387,15 +391,15 @@
             if forProject:
                 project = e5App().getObject("Project")
                 if not project.isDebugPropertiesLoaded():
-                    self.clientProcess, isNetworked = \
+                    self.clientProcess, isNetworked, clientInterpreter = \
                         self.debuggerInterface.startRemote(self.serverPort(),
                                                            runInConsole)
                 else:
-                    self.clientProcess, isNetworked = \
+                    self.clientProcess, isNetworked, clientInterpreter = \
                         self.debuggerInterface.startRemoteForProject(
                             self.serverPort(), runInConsole)
             else:
-                self.clientProcess, isNetworked = \
+                self.clientProcess, isNetworked, clientInterpreter = \
                     self.debuggerInterface.startRemote(
                         self.serverPort(), runInConsole)
             
@@ -417,6 +421,11 @@
                     self.__setClientType(self.lastClientType)
         else:
             self.__createDebuggerInterface("None")
+            clientInterpreter = ""
+        
+        if clientInterpreter != self.clientInterpreter:
+            self.clientInterpreter = clientInterpreter
+            self.clientInterpreterChanged.emit(clientInterpreter)
 
     def __clientProcessOutput(self):
         """
@@ -623,6 +632,14 @@
         except KeyError:
             return 0    # no capabilities
         
+    def getClientInterpreter(self):
+        """
+        Public method to get the interpreter of the debug client.
+        
+        @return interpreter of the debug client (string)
+        """
+        return self.clientInterpreter
+        
     def __newConnection(self):
         """
         Private slot to handle a new connection.
--- a/Debugger/DebuggerInterfaceNone.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/Debugger/DebuggerInterfaceNone.py	Tue Mar 11 20:07:05 2014 +0100
@@ -53,10 +53,11 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return client process object (QProcess) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
-        return None, True
+        return None, True, ""
 
     def startRemoteForProject(self, port, runInConsole):
         """
@@ -65,10 +66,11 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return client process object (QProcess) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
-        return None, True
+        return None, True, ""
 
     def getClientCapabilities(self):
         """
--- a/Debugger/DebuggerInterfacePython.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/Debugger/DebuggerInterfacePython.py	Tue Mar 11 20:07:05 2014 +0100
@@ -150,8 +150,9 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return client process object (QProcess) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
         interpreter = Preferences.getDebugger("PythonInterpreter")
         if interpreter == "":
@@ -160,7 +161,7 @@
                 self.tr("Start Debugger"),
                 self.tr(
                     """<p>No Python2 interpreter configured.</p>"""))
-            return None, False
+            return None, False, ""
         
         debugClientType = Preferences.getDebugger("DebugClientType")
         if debugClientType == "standard":
@@ -211,7 +212,7 @@
                     self.translate = self.__remoteTranslation
                 else:
                     self.translate = self.__identityTranslation
-                return process, self.__isNetworked
+                return process, self.__isNetworked, ""
         
         # set translation function
         self.translate = self.__identityTranslation
@@ -248,7 +249,7 @@
                         self.tr(
                             """<p>The debugger backend could not be"""
                             """ started.</p>"""))
-                return process, self.__isNetworked
+                return process, self.__isNetworked, interpreter
         
         process = self.__startProcess(
             interpreter,
@@ -260,7 +261,7 @@
                 self.tr("Start Debugger"),
                 self.tr(
                     """<p>The debugger backend could not be started.</p>"""))
-        return process, self.__isNetworked
+        return process, self.__isNetworked, interpreter
 
     def startRemoteForProject(self, port, runInConsole):
         """
@@ -269,12 +270,13 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return client process object (QProcess) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
         project = e5App().getObject("Project")
         if not project.isDebugPropertiesLoaded():
-            return None, self.__isNetworked
+            return None, self.__isNetworked, ""
         
         # start debugger with project specific settings
         interpreter = project.getDebugProperty("INTERPRETER")
@@ -312,7 +314,7 @@
                     self.translate = self.__remoteTranslation
                 else:
                     self.translate = self.__identityTranslation
-                return process, self.__isNetworked
+                return process, self.__isNetworked, ""
         
         # set translation function
         self.translate = self.__identityTranslation
@@ -350,7 +352,7 @@
                         self.tr(
                             """<p>The debugger backend could not be"""
                             """ started.</p>"""))
-                return process, self.__isNetworked
+                return process, self.__isNetworked, interpreter
         
         process = self.__startProcess(
             interpreter,
@@ -362,7 +364,7 @@
                 self.tr("Start Debugger"),
                 self.tr(
                     """<p>The debugger backend could not be started.</p>"""))
-        return process, self.__isNetworked
+        return process, self.__isNetworked, interpreter
 
     def getClientCapabilities(self):
         """
--- a/Debugger/DebuggerInterfacePython3.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/Debugger/DebuggerInterfacePython3.py	Tue Mar 11 20:07:05 2014 +0100
@@ -147,8 +147,9 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return client process object (QProcess) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
         if Preferences.getDebugger("CustomPython3Interpreter"):
             interpreter = Preferences.getDebugger("Python3Interpreter")
@@ -206,7 +207,7 @@
                     self.translate = self.__remoteTranslation
                 else:
                     self.translate = self.__identityTranslation
-                return process, self.__isNetworked
+                return process, self.__isNetworked, ""
         
         # set translation function
         self.translate = self.__identityTranslation
@@ -243,7 +244,7 @@
                         self.tr(
                             """<p>The debugger backend could not be"""
                             """ started.</p>"""))
-                return process, self.__isNetworked
+                return process, self.__isNetworked, interpreter
         
         process = self.__startProcess(
             interpreter,
@@ -255,7 +256,7 @@
                 self.tr("Start Debugger"),
                 self.tr(
                     """<p>The debugger backend could not be started.</p>"""))
-        return process, self.__isNetworked
+        return process, self.__isNetworked, interpreter
 
     def startRemoteForProject(self, port, runInConsole):
         """
@@ -264,12 +265,13 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return client process object (QProcess) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
         project = e5App().getObject("Project")
         if not project.isDebugPropertiesLoaded():
-            return None, self.__isNetworked
+            return None, self.__isNetworked, ""
         
         # start debugger with project specific settings
         interpreter = project.getDebugProperty("INTERPRETER")
@@ -307,7 +309,7 @@
                     self.translate = self.__remoteTranslation
                 else:
                     self.translate = self.__identityTranslation
-                return process, self.__isNetworked
+                return process, self.__isNetworked, ""
         
         # set translation function
         self.translate = self.__identityTranslation
@@ -345,7 +347,7 @@
                         self.tr(
                             """<p>The debugger backend could not be"""
                             """ started.</p>"""))
-                return process, self.__isNetworked
+                return process, self.__isNetworked, interpreter
         
         process = self.__startProcess(
             interpreter,
@@ -357,7 +359,7 @@
                 self.tr("Start Debugger"),
                 self.tr(
                     """<p>The debugger backend could not be started.</p>"""))
-        return process, self.__isNetworked
+        return process, self.__isNetworked, interpreter
 
     def getClientCapabilities(self):
         """
--- a/Debugger/DebuggerInterfaceRuby.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/Debugger/DebuggerInterfaceRuby.py	Tue Mar 11 20:07:05 2014 +0100
@@ -141,8 +141,9 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return client process object (QProcess) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
         interpreter = Preferences.getDebugger("RubyInterpreter")
         if interpreter == "":
@@ -150,7 +151,7 @@
                 None,
                 self.tr("Start Debugger"),
                 self.tr("""<p>No Ruby interpreter configured.</p>"""))
-            return None, False
+            return None, False, ""
         
         debugClient = os.path.join(
             getConfig('ericDir'), "DebugClients", "Ruby", "DebugClient.rb")
@@ -186,7 +187,7 @@
                     self.translate = self.__remoteTranslation
                 else:
                     self.translate = self.__identityTranslation
-                return process, self.__isNetworked
+                return process, self.__isNetworked, ""
         
         # set translation function
         self.translate = self.__identityTranslation
@@ -223,7 +224,7 @@
                         self.tr(
                             """<p>The debugger backend could not be"""
                             """ started.</p>"""))
-                return process, self.__isNetworked
+                return process, self.__isNetworked, interpreter
         
         process = self.__startProcess(
             interpreter,
@@ -235,7 +236,7 @@
                 self.tr("Start Debugger"),
                 self.tr(
                     """<p>The debugger backend could not be started.</p>"""))
-        return process, self.__isNetworked
+        return process, self.__isNetworked, interpreter
 
     def startRemoteForProject(self, port, runInConsole):
         """
@@ -244,12 +245,13 @@
         @param port portnumber the debug server is listening on (integer)
         @param runInConsole flag indicating to start the debugger in a
             console window (boolean)
-        @return pid of the client process (integer) and a flag to indicate
-            a network connection (boolean)
+        @return client process object (QProcess), a flag to indicate
+            a network connection (boolean) and the name of the interpreter
+            in case of a local execution (string)
         """
         project = e5App().getObject("Project")
         if not project.isDebugPropertiesLoaded():
-            return None, self.__isNetworked
+            return None, self.__isNetworked, ""
         
         # start debugger with project specific settings
         interpreter = project.getDebugProperty("INTERPRETER")
@@ -285,7 +287,7 @@
                     self.translate = self.__remoteTranslation
                 else:
                     self.translate = self.__identityTranslation
-                return process, self.__isNetworked
+                return process, self.__isNetworked, ""
         
         # set translation function
         self.translate = self.__identityTranslation
@@ -323,7 +325,7 @@
                         self.tr(
                             """<p>The debugger backend could not be"""
                             """ started.</p>"""))
-                return process, self.__isNetworked
+                return process, self.__isNetworked, interpreter
         
         process = self.__startProcess(
             interpreter,
@@ -335,7 +337,7 @@
                 self.tr("Start Debugger"),
                 self.tr(
                     """<p>The debugger backend could not be started.</p>"""))
-        return process, self.__isNetworked
+        return process, self.__isNetworked, interpreter
 
     def getClientCapabilities(self):
         """
--- a/UI/Browser.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/UI/Browser.py	Tue Mar 11 20:07:05 2014 +0100
@@ -544,6 +544,14 @@
         """
         self.__model.programChange(os.path.dirname(fn))
         
+    def handleInterpreterChanged(self, interpreter):
+        """
+        Public slot to handle a change of the debug client's interpreter.
+        
+        @param interpreter interpreter of the debug client (string)
+        """
+        self.__model.interpreterChanged(interpreter)
+        
     def wantedItem(self, itm, filter=None):
         """
         Public method to check type of an item.
--- a/UI/BrowserModel.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/UI/BrowserModel.py	Tue Mar 11 20:07:05 2014 +0100
@@ -49,6 +49,9 @@
         self.watcher = QFileSystemWatcher(self)
         self.watcher.directoryChanged.connect(self.directoryChanged)
         
+        self.__sysPathInterpreter = ""
+        self.__sysPathItem = None
+        
         if not nopopulate:
             rootData = QApplication.translate("BrowserModel", "Name")
             self.rootItem = BrowserItem(None, rootData)
@@ -350,8 +353,6 @@
         """
         Private method to populate the browser model.
         """
-        self._addItem(BrowserSysPathItem(self.rootItem), self.rootItem)
-        
         self.toplevelDirs = []
         tdp = Preferences.Prefs.settings.value('BrowserModel/ToplevelDirs')
         if tdp:
@@ -367,6 +368,41 @@
             itm = BrowserDirectoryItem(self.rootItem, d)
             self._addItem(itm, self.rootItem)
     
+    def interpreterChanged(self, interpreter):
+        """
+        Public method to handle a change of the debug client's interpreter.
+        
+        @param interpreter interpreter of the debug client (string)
+        """
+        if interpreter and "python" in interpreter.lower():
+            if interpreter.endswith("w.exe"):
+                interpreter = interpreter.replace("w.exe", ".exe")
+            if self.__sysPathInterpreter != interpreter:
+                self.__sysPathInterpreter = interpreter
+                # step 1: remove sys.path entry
+                if self.__sysPathItem is not None:
+                    self.beginRemoveRows(
+                        QModelIndex(), self.__sysPathItem.row(),
+                        self.__sysPathItem.row())
+                    self.rootItem.removeChild(self.__sysPathItem)
+                    self.endRemoveRows()
+                    self.__sysPathItem = None
+                
+                if self.__sysPathInterpreter:
+                    # step 2: add a new one
+                    self.__sysPathItem = BrowserSysPathItem(self.rootItem)
+                    self.addItem(self.__sysPathItem)
+        else:
+            # remove sys.path entry
+            if self.__sysPathItem is not None:
+                self.beginRemoveRows(
+                    QModelIndex(), self.__sysPathItem.row(),
+                    self.__sysPathItem.row())
+                self.rootItem.removeChild(self.__sysPathItem)
+                self.endRemoveRows()
+                self.__sysPathItem = None
+            self.__sysPathInterpreter = ""
+    
     def programChange(self, dirname):
         """
         Public method to change the entry for the directory of file being
@@ -522,17 +558,16 @@
         @param parentItem reference to the sys.path item to be populated
         @param repopulate flag indicating a repopulation (boolean)
         """
+        # TODO: make this dynamic depending on interpreter
         if len(sys.path) > 0:
             if repopulate:
                 self.beginInsertRows(
                     self.createIndex(parentItem.row(), 0, parentItem),
                     0, len(sys.path) - 1)
             for p in sys.path:
-                if p == '':
-                    p = os.getcwd()
-                
-                node = BrowserDirectoryItem(parentItem, p)
-                self._addItem(node, parentItem)
+                if p:
+                    node = BrowserDirectoryItem(parentItem, p)
+                    self._addItem(node, parentItem)
             if repopulate:
                 self.endInsertRows()
 
--- a/UI/UserInterface.py	Tue Mar 11 18:56:38 2014 +0100
+++ b/UI/UserInterface.py	Tue Mar 11 20:07:05 2014 +0100
@@ -363,6 +363,8 @@
             self.debugViewer.breakpointViewer.highlightBreakpoint)
         debugServer.clientProcessStdout.connect(self.appendToStdout)
         debugServer.clientProcessStderr.connect(self.appendToStderr)
+        debugServer.clientInterpreterChanged.connect(
+            self.browser.handleInterpreterChanged)
         
         self.stdout.appendStdout.connect(self.appendToStdout)
         self.stderr.appendStderr.connect(self.appendToStderr)

eric ide

mercurial