RefactoringRope/CodeAssistServer.py

changeset 354
a967ff16629a
parent 347
b5048b5ff454
child 360
2b35968f3d02
--- a/RefactoringRope/CodeAssistServer.py	Sat Mar 27 09:48:05 2021 +0100
+++ b/RefactoringRope/CodeAssistServer.py	Sat Apr 24 11:19:08 2021 +0200
@@ -9,6 +9,7 @@
 
 import os
 import sys
+import contextlib
 
 from PyQt5.QtCore import pyqtSlot, QCoreApplication, QTimer
 
@@ -21,7 +22,6 @@
 
 import Globals
 import Preferences
-import Utilities
 
 
 class CodeAssistServer(JsonServer):
@@ -55,7 +55,7 @@
         @param parent parent
         @type QObject
         """
-        super(CodeAssistServer, self).__init__(
+        super().__init__(
             "CodeAssistServer", multiplex=True, parent=parent)
         
         self.__plugin = plugin
@@ -541,13 +541,9 @@
             # ignore errors silently
             if "Location" in result:
                 location = result["Location"]
-                try:
-                    self.__vm.openSourceFile(
-                        location["ModulePath"], location["Line"], addNext=True)
-                except TypeError:
-                    # backward compatibility; <= 17.03
-                    self.__vm.openSourceFile(
-                        location["ModulePath"], location["Line"], next=True)
+                self.__vm.openSourceFile(location["ModulePath"],
+                                         location["Line"],
+                                         addNext=True)
             else:
                 e5App().getObject("UserInterface").statusBar().showMessage(
                     self.tr('Code Assist: No definition found'), 5000)
@@ -663,9 +659,8 @@
                     clientEnv["PATH"] = self.__ui.getOriginalPathString()
                 venvManager = e5App().getObject("VirtualEnvManager")
                 if idString == "Python3":
-                    # Python 3
                     venvName = Preferences.getDebugger("Python3VirtualEnv")
-                    if not venvName and sys.version_info[0] >= 3:
+                    if not venvName:
                         venvName, _ = venvManager.getDefaultEnvironment()
                 if venvName:
                     interpreter = venvManager.getVirtualenvInterpreter(
@@ -700,61 +695,34 @@
         interpreter = ""
         clientEnv = os.environ.copy()
         if "PATH" in clientEnv:
-            try:
-                clientEnv["PATH"] = self.__ui.getOriginalPathString()
-            except AttributeError:
-                # ignore for eric6 < 18.12
-                pass
+            clientEnv["PATH"] = self.__ui.getOriginalPathString()
         
         if projectLanguage.startswith("Python"):
-            try:
-                # new code using virtual environments
-                venvManager = e5App().getObject("VirtualEnvManager")
+            venvManager = e5App().getObject("VirtualEnvManager")
+            
+            # get virtual environment from project first
+            venvName = self.__e5project.getDebugProperty("VIRTUALENV")
+            if not venvName:
+                # get it from debugger settings next
+                if projectLanguage == "Python3":
+                    venvName = Preferences.getDebugger("Python3VirtualEnv")
+                    if not venvName:
+                        venvName, _ = venvManager.getDefaultEnvironment()
+                else:
+                    venvName = ""
+            if venvName:
+                interpreter = venvManager.getVirtualenvInterpreter(
+                    venvName
+                )
+                execPath = venvManager.getVirtualenvExecPath(venvName)
                 
-                # get virtual environment from project first
-                venvName = self.__e5project.getDebugProperty("VIRTUALENV")
-                if not venvName:
-                    # get it from debugger settings next
-                    if projectLanguage == "Python3":
-                        # Python 3
-                        venvName = Preferences.getDebugger("Python3VirtualEnv")
-                        if not venvName and sys.version_info[0] >= 3:
-                            try:
-                                venvName, _ = (
-                                    venvManager.getDefaultEnvironment()
-                                )
-                            except AttributeError:
-                                # ignore for eric6 < 18.10
-                                pass
+                # build a suitable environment
+                if execPath:
+                    if "PATH" in clientEnv:
+                        clientEnv["PATH"] = os.pathsep.join(
+                            [execPath, clientEnv["PATH"]])
                     else:
-                        venvName = ""
-                if venvName:
-                    interpreter = venvManager.getVirtualenvInterpreter(
-                        venvName
-                    )
-                    
-                    try:
-                        execPath = venvManager.getVirtualenvExecPath(venvName)
-                    except AttributeError:
-                        # eric6 < 18.12
-                        execPath = ""
-                    
-                    # build a suitable environment
-                    if execPath:
-                        if "PATH" in clientEnv:
-                            clientEnv["PATH"] = os.pathsep.join(
-                                [execPath, clientEnv["PATH"]])
-                        else:
-                            clientEnv["PATH"] = execPath
-            except KeyError:
-                # backward compatibility (eric < 18.07)
-                # get interpreter from project first
-                interpreter = self.__e5project.getDebugProperty("INTERPRETER")
-                if not interpreter or not Utilities.isinpath(interpreter):
-                    # get it from debugger settings second
-                    if projectLanguage == "Python3":
-                        interpreter = Preferences.getDebugger(
-                            "Python3Interpreter")
+                        clientEnv["PATH"] = execPath
         
         return interpreter, clientEnv
     
@@ -763,7 +731,7 @@
         """
         Public slot for new incoming connections from a client.
         """
-        super(CodeAssistServer, self).handleNewConnection()
+        super().handleNewConnection()
         
         self.__updateEditorLanguageMapping()
         
@@ -773,15 +741,11 @@
         """
         Public method to activate the code assist server.
         """
-        try:
-            self.__documentationViewer = self.__ui.documentationViewer()
-            if self.__documentationViewer is not None:
-                self.__documentationViewer.registerProvider(
-                    "rope", self.tr("Rope"), self.requestCodeDocumentation,
-                    self.isSupportedLanguage)
-        except AttributeError:
-            # eric6 before 17.11 doesn't have this
-            pass
+        self.__documentationViewer = self.__ui.documentationViewer()
+        if self.__documentationViewer is not None:
+            self.__documentationViewer.registerProvider(
+                "rope", self.tr("Rope"), self.requestCodeDocumentation,
+                self.isSupportedLanguage)
         
         self.__e5project.projectClosed.connect(self.__projectClosed)
     
@@ -798,11 +762,8 @@
         for idString in self.connectionNames():
             self.sendJson("closeProject", {}, flush=True, idString=idString)
         
-        try:
+        with contextlib.suppress(TypeError):
             self.__e5project.projectClosed.disconnect(self.__projectClosed)
-        except TypeError:
-            # ignore it, the signal may be disconnected already
-            pass
         
         self.stopAllClients()
     

eric ide

mercurial