RefactoringRope/RefactoringServer.py

changeset 354
a967ff16629a
parent 347
b5048b5ff454
child 360
2b35968f3d02
equal deleted inserted replaced
353:d38295fd97c2 354:a967ff16629a
6 """ 6 """
7 Module implementing the refactoring interface to rope. 7 Module implementing the refactoring interface to rope.
8 """ 8 """
9 9
10 import os 10 import os
11 import sys 11 import contextlib
12 12
13 from PyQt5.QtCore import pyqtSlot 13 from PyQt5.QtCore import pyqtSlot
14 from PyQt5.QtWidgets import QMenu, QApplication, QAction 14 from PyQt5.QtWidgets import QMenu, QApplication, QAction
15 from PyQt5.Qsci import QsciScintilla 15 from PyQt5.Qsci import QsciScintilla
16 16
38 @param plugin reference to the plugin object 38 @param plugin reference to the plugin object
39 @type RefactoringRopePlugin 39 @type RefactoringRopePlugin
40 @param parent parent 40 @param parent parent
41 @type QObject 41 @type QObject
42 """ 42 """
43 super(RefactoringServer, self).__init__( 43 super().__init__(
44 "RefactoringServer", parent=parent) 44 "RefactoringServer", parent=parent)
45 45
46 self.__plugin = plugin 46 self.__plugin = plugin
47 self.__ui = parent 47 self.__ui = parent
48 self.__vm = e5App().getObject("ViewManager") 48 self.__vm = e5App().getObject("ViewManager")
84 @pyqtSlot() 84 @pyqtSlot()
85 def handleNewConnection(self): 85 def handleNewConnection(self):
86 """ 86 """
87 Public slot for new incoming connections from a client. 87 Public slot for new incoming connections from a client.
88 """ 88 """
89 super(RefactoringServer, self).handleNewConnection() 89 super().handleNewConnection()
90 90
91 self.sendJson("GetConfig", {}) 91 self.sendJson("GetConfig", {})
92 92
93 def activate(self): 93 def activate(self):
94 """ 94 """
859 @rtype bool 859 @rtype bool
860 """ 860 """
861 if "Error" not in result: 861 if "Error" not in result:
862 return True 862 return True
863 863
864 if "Title" in result: 864 title = result.get("Title", self.tr("Rope Error"))
865 title = result["Title"]
866 else:
867 title = self.tr("Rope Error")
868 865
869 if result["Error"] == 'ModuleSyntaxError': 866 if result["Error"] == 'ModuleSyntaxError':
870 res = E5MessageBox.warning( 867 res = E5MessageBox.warning(
871 self.__ui, title, 868 self.__ui, title,
872 self.tr("Rope error: {0}").format( 869 self.tr("Rope error: {0}").format(
924 @param result dictionary containing the changes data 921 @param result dictionary containing the changes data
925 @type dict 922 @type dict
926 """ 923 """
927 if self.handleRopeError(result): 924 if self.handleRopeError(result):
928 changeGroup = result["ChangeGroup"] 925 changeGroup = result["ChangeGroup"]
929 try: 926 with contextlib.suppress(KeyError):
930 self.__refactoringDialogs[changeGroup].processChangeData( 927 self.__refactoringDialogs[changeGroup].processChangeData(
931 result) 928 result)
932 except KeyError:
933 # ignore data for non-existing dialogs
934 pass
935 929
936 def __refactoringDialogClosed(self, changeGroup): 930 def __refactoringDialogClosed(self, changeGroup):
937 """ 931 """
938 Private slot handling the closing of a refactoring dialog. 932 Private slot handling the closing of a refactoring dialog.
939 933
940 @param changeGroup name of the refactoring change group the dialog 934 @param changeGroup name of the refactoring change group the dialog
941 belonged to 935 belonged to
942 @type str 936 @type str
943 """ 937 """
944 try: 938 with contextlib.suppress(KeyError):
945 del self.__refactoringDialogs[changeGroup] 939 del self.__refactoringDialogs[changeGroup]
946 except KeyError:
947 # it's gone already; ignore it
948 pass
949 940
950 ##################################################### 941 #####################################################
951 ## Rename refactorings 942 ## Rename refactorings
952 ##################################################### 943 #####################################################
953 944
1950 progressDialog.show() 1941 progressDialog.show()
1951 progressDialog.raise_() 1942 progressDialog.raise_()
1952 self.__progressDialog = progressDialog 1943 self.__progressDialog = progressDialog
1953 QApplication.processEvents() 1944 QApplication.processEvents()
1954 1945
1955 elif subcommand == "Progress": 1946 elif subcommand == "Progress" and self.__progressDialog is not None:
1956 if self.__progressDialog is not None: 1947 self.__progressDialog.updateProgress(params)
1957 self.__progressDialog.updateProgress(params) 1948 self.__progressDialog.raise_()
1958 self.__progressDialog.raise_()
1959 1949
1960 elif subcommand == "Reset": 1950 elif subcommand == "Reset" and self.__progressDialog is not None:
1961 if self.__progressDialog is not None: 1951 self.__progressDialog.reset()
1962 self.__progressDialog.reset()
1963 1952
1964 def __setConfig(self, params): 1953 def __setConfig(self, params):
1965 """ 1954 """
1966 Private method to set the rope client configuration data. 1955 Private method to set the rope client configuration data.
1967 1956
2035 2024
2036 if (self.__projectLanguage.startswith("Python") or 2025 if (self.__projectLanguage.startswith("Python") or
2037 self.__projectLanguage == "MicroPython"): 2026 self.__projectLanguage == "MicroPython"):
2038 clientEnv = os.environ.copy() 2027 clientEnv = os.environ.copy()
2039 if "PATH" in clientEnv: 2028 if "PATH" in clientEnv:
2029 clientEnv["PATH"] = self.__ui.getOriginalPathString()
2030
2031 venvManager = e5App().getObject("VirtualEnvManager")
2032
2033 # get virtual environment from project first
2034 venvName = self.__e5project.getDebugProperty("VIRTUALENV")
2035 if venvName:
2040 try: 2036 try:
2041 clientEnv["PATH"] = self.__ui.getOriginalPathString() 2037 isRemote = venvManager.isRemoteEnvironment(venvName)
2042 except AttributeError: 2038 except AttributeError:
2043 # ignore for eric6 < 18.12 2039 isRemote = False
2044 pass 2040 else:
2045 try: 2041 isRemote = False
2046 # new code using virtual environments 2042 if (not venvName) or isRemote:
2047 venvManager = e5App().getObject("VirtualEnvManager") 2043 # get it from debugger settings next
2044 if self.__projectLanguage in ("Python3", "MicroPython"):
2045 venvName = Preferences.getDebugger("Python3VirtualEnv")
2046 if not venvName:
2047 venvName, _ = venvManager.getDefaultEnvironment()
2048 else:
2049 venvName = ""
2050 if venvName:
2051 interpreter = venvManager.getVirtualenvInterpreter(
2052 venvName)
2053 execPath = venvManager.getVirtualenvExecPath(venvName)
2048 2054
2049 # get virtual environment from project first 2055 # build a suitable environment
2050 venvName = self.__e5project.getDebugProperty("VIRTUALENV") 2056 if execPath:
2051 if venvName: 2057 if "PATH" in clientEnv:
2052 try: 2058 clientEnv["PATH"] = os.pathsep.join(
2053 isRemote = venvManager.isRemoteEnvironment(venvName) 2059 [execPath, clientEnv["PATH"]])
2054 except AttributeError:
2055 isRemote = False
2056 else:
2057 isRemote = False
2058 if (not venvName) or isRemote:
2059 # get it from debugger settings next
2060 if self.__projectLanguage in ("Python3", "MicroPython"):
2061 # Python 3
2062 venvName = Preferences.getDebugger("Python3VirtualEnv")
2063 if not venvName and sys.version_info[0] >= 3:
2064 try:
2065 venvName, _ = (
2066 venvManager.getDefaultEnvironment()
2067 )
2068 except AttributeError:
2069 # ignore for eric6 < 18.10
2070 pass
2071 else: 2060 else:
2072 venvName = "" 2061 clientEnv["PATH"] = execPath
2073 if venvName: 2062 else:
2074 interpreter = venvManager.getVirtualenvInterpreter( 2063 interpreter = ""
2075 venvName)
2076
2077 try:
2078 execPath = venvManager.getVirtualenvExecPath(venvName)
2079 except AttributeError:
2080 # eric6 < 18.12
2081 execPath = ""
2082
2083 # build a suitable environment
2084 if execPath:
2085 if "PATH" in clientEnv:
2086 clientEnv["PATH"] = os.pathsep.join(
2087 [execPath, clientEnv["PATH"]])
2088 else:
2089 clientEnv["PATH"] = execPath
2090 else:
2091 interpreter = ""
2092 except KeyError:
2093 # backward compatibility (eric < 18.07)
2094 # get interpreter from project first
2095 interpreter = self.__e5project.getDebugProperty("INTERPRETER")
2096 if not interpreter or not Utilities.isinpath(interpreter):
2097 # get it from debugger settings second
2098 if self.__projectLanguage in ("Python3", "MicroPython"):
2099 interpreter = Preferences.getDebugger(
2100 "Python3Interpreter")
2101 else:
2102 interpreter = ""
2103 if interpreter: 2064 if interpreter:
2104 if isRemote: 2065 if isRemote:
2105 self.__ui.appendToStderr(self.tr( 2066 self.__ui.appendToStderr(self.tr(
2106 "The project is configured for remote access." 2067 "The project is configured for remote access."
2107 " Using local interpreter instead." 2068 " Using local interpreter instead."

eric ide

mercurial