src/eric7/VirtualEnv/VirtualenvManager.py

branch
server
changeset 10725
51fe971610d3
parent 10632
1109854f15f9
child 10746
b8fae72eb04d
diff -r 6299dec09231 -r 51fe971610d3 src/eric7/VirtualEnv/VirtualenvManager.py
--- a/src/eric7/VirtualEnv/VirtualenvManager.py	Tue May 21 19:31:50 2024 +0200
+++ b/src/eric7/VirtualEnv/VirtualenvManager.py	Tue May 21 19:35:41 2024 +0200
@@ -26,7 +26,6 @@
 from .VirtualenvMeta import VirtualenvMetaData
 
 
-# TODO: introduce 'eric-ide Server' environment definitions
 class VirtualenvManager(QObject):
     """
     Class implementing an object to manage Python virtual environments.
@@ -85,6 +84,7 @@
         #   is_global:      a flag indicating a global environment
         #   is_conda:       a flag indicating an Anaconda environment
         #   is_remote:      a flag indicating a remotely accessed environment
+        #   is_eric_server  a flag indicating an eric IDE server environment
         #   exec_path:      a string to be prefixed to the PATH environment
         #                   setting
         #   description     a description of the environment
@@ -154,18 +154,32 @@
 
     def __cleanEnvironments(self):
         """
-        Private method to delete all non-existent local environments.
+        Private method to delete all non-existent local or eric IDE server environments.
         """
         removed = False
 
         for venvName in list(self.__virtualEnvironments):
             venvItem = self.__virtualEnvironments[venvName]
             if not venvItem.is_remote:
-                # It is a local environment; check it is still valid.
                 venvPath = venvItem.path
-                if venvPath and not os.path.exists(venvPath):
-                    del self.__virtualEnvironments[venvName]
-                    removed = True
+                if venvPath:
+                    if venvItem.is_eric_server:
+                        # It is an eric IDE server environment; check it is still valid.
+                        ericServer = ericApp().getObject("EricServer")
+                        if (
+                            ericServer.isServerConnected()
+                            and ericServer.getHost() == venvItem.eric_server
+                            and not ericServer.getServiceInterface("FileSystem").exists(
+                                venvPath
+                            )
+                        ):
+                            del self.__virtualEnvironments[venvName]
+                            removed = True
+                    else:
+                        # It is a local environment; check it is still valid.
+                        if not os.path.exists(venvPath):
+                            del self.__virtualEnvironments[venvName]
+                            removed = True
         if removed:
             self.__saveSettings()
             self.virtualEnvironmentRemoved.emit()
@@ -442,6 +456,7 @@
             ok &= bool(self.__virtualEnvironments[venvName].path)
             ok &= not self.__virtualEnvironments[venvName].is_global
             ok &= not self.__virtualEnvironments[venvName].is_remote
+            ok &= not self.__virtualEnvironments[venvName].is_eric_server
             ok &= os.access(self.__virtualEnvironments[venvName].path, os.W_OK)
 
         return ok
@@ -627,9 +642,9 @@
         @return flag indicating a global environment
         @rtype bool
         """
-        if venvName in self.__virtualEnvironments:
+        try:
             return self.__virtualEnvironments[venvName].is_global
-        else:
+        except KeyError:
             return False
 
     def isCondaEnvironment(self, venvName):
@@ -642,9 +657,9 @@
         @return flag indicating an Anaconda environment
         @rtype bool
         """
-        if venvName in self.__virtualEnvironments:
+        try:
             return self.__virtualEnvironments[venvName].is_conda
-        else:
+        except KeyError:
             return False
 
     def isRemoteEnvironment(self, venvName):
@@ -657,9 +672,24 @@
         @return flag indicating a remotely accessed environment
         @rtype bool
         """
-        if venvName in self.__virtualEnvironments:
+        try:
             return self.__virtualEnvironments[venvName].is_remote
-        else:
+        except KeyError:
+            return False
+
+    def isEricServerEnvironment(self, venvName):
+        """
+        Public method to test, if a given environment is an environment accessed
+        through an eric IDE server.
+
+        @param venvName logical name of the virtual environment
+        @type str
+        @return flag indicating a remotely accessed environment
+        @rtype bool
+        """
+        try:
+            return self.__virtualEnvironments[venvName].is_eric_server
+        except KeyError:
             return False
 
     def getVirtualenvExecPath(self, venvName):
@@ -671,9 +701,9 @@
         @return search path prefix
         @rtype str
         """
-        if venvName in self.__virtualEnvironments:
+        try:
             return self.__virtualEnvironments[venvName].exec_path
-        else:
+        except KeyError:
             return ""
 
     def setVirtualEnvironmentsBaseDir(self, baseDir):

eric ide

mercurial