VirtualEnv/VirtualenvManager.py

changeset 6716
1c9d3b369ea8
parent 6673
c3d3c8abcdec
child 6740
46bb5e2df095
--- a/VirtualEnv/VirtualenvManager.py	Sat Feb 09 14:40:32 2019 +0100
+++ b/VirtualEnv/VirtualenvManager.py	Sun Feb 10 12:13:10 2019 +0100
@@ -61,17 +61,20 @@
         #   variant:        Python variant (2 or 3)
         #   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
         #   exec_path:      a string to be prefixed to the PATH environment
         #                   setting
         #
         for venvName in environments:
-            interpreter = environments[venvName]["interpreter"]
-            if os.access(interpreter, os.X_OK):
-                environment = environments[venvName]
+            environment = environments[venvName]
+            if ("is_remote" in environment and environment["is_remote"]) or \
+               os.access(environment["interpreter"], os.X_OK):
                 if "is_global" not in environment:
                     environment["is_global"] = environment["path"] == ""
                 if "is_conda" not in environment:
                     environment["is_conda"] = False
+                if "is_remote" not in environment:
+                    environment["is_remote"] = False
                 if "exec_path" not in environment:
                     environment["exec_path"] = ""
                 self.__virtualEnvironments[venvName] = environment
@@ -92,6 +95,7 @@
                 "variant": sys.version_info[0],
                 "is_global": True,
                 "is_conda": False,
+                "is_remote": False,
                 "exec_path": "",
             }
         
@@ -105,6 +109,7 @@
             "PyVenv/VirtualEnvironments",
             json.dumps(self.__virtualEnvironments)
         )
+        Preferences.syncPreferences()
     
     def getDefaultEnvironment(self):
         """
@@ -161,7 +166,7 @@
     
     def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="",
                       venvVariant=3, isGlobal=False, isConda=False,
-                      execPath=""):
+                      isRemote=False, execPath=""):
         """
         Public method to add a virtual environment.
         
@@ -177,6 +182,8 @@
         @type bool
         @param isConda flag indicating an Anaconda virtual environment
         @type bool
+        @param isRemote flag indicating a remotely accessed environment
+        @type bool
         @param execPath search path string to be prepended to the PATH
             environment variable
         @type str
@@ -209,6 +216,7 @@
                 "variant": venvVariant,
                 "is_global": isGlobal,
                 "is_conda": isConda,
+                "is_remote": isRemote,
                 "exec_path": execPath,
             }
             
@@ -218,7 +226,8 @@
                 self.__virtualenvManagerDialog.refresh()
     
     def setVirtualEnv(self, venvName, venvDirectory, venvInterpreter,
-                      venvVariant, isGlobal, isConda, execPath):
+                      venvVariant, isGlobal, isConda, isRemote,
+                      execPath):
         """
         Public method to change a virtual environment.
         
@@ -234,6 +243,8 @@
         @type bool
         @param isConda flag indicating an Anaconda virtual environment
         @type bool
+        @param isRemote flag indicating a remotely accessed environment
+        @type bool
         @param execPath search path string to be prepended to the PATH
             environment variable
         @type str
@@ -254,6 +265,7 @@
             "variant": venvVariant,
             "is_global": isGlobal,
             "is_conda": isConda,
+            "is_remote": isRemote,
             "exec_path": execPath,
         }
         
@@ -264,7 +276,7 @@
     
     def renameVirtualEnv(self, oldVenvName, venvName, venvDirectory,
                          venvInterpreter, venvVariant, isGlobal, isConda,
-                         execPath):
+                         isRemote, execPath):
         """
         Public method to substitute a virtual environment entry with a new
         name.
@@ -283,6 +295,8 @@
         @type bool
         @param isConda flag indicating an Anaconda virtual environment
         @type bool
+        @param isRemote flag indicating a remotely accessed environment
+        @type bool
         @param execPath search path string to be prepended to the PATH
             environment variable
         @type str
@@ -299,7 +313,8 @@
         
         del self.__virtualEnvironments[oldVenvName]
         self.addVirtualEnv(venvName, venvDirectory, venvInterpreter,
-                           venvVariant, isGlobal, isConda, execPath)
+                           venvVariant, isGlobal, isConda, isRemote,
+                           execPath)
     
     def deleteVirtualEnvs(self, venvNames):
         """
@@ -351,6 +366,7 @@
             ok = True
             ok &= bool(self.__virtualEnvironments[venvName]["path"])
             ok &= not self.__virtualEnvironments[venvName]["is_global"]
+            ok &= not self.__virtualEnvironments[venvName]["is_remote"]
             ok &= os.access(self.__virtualEnvironments[venvName]["path"],
                             os.W_OK)
         
@@ -521,6 +537,21 @@
         else:
             return False
     
+    def isRemoteEnvironment(self, venvName):
+        """
+        Public method to test, if a given environment is a remotely accessed
+        environment.
+        
+        @param venvName logical name of the virtual environment
+        @type str
+        @return flag indicating a remotely accessed environment
+        @rtype bool
+        """
+        if venvName in self.__virtualEnvironments:
+            return self.__virtualEnvironments[venvName]["is_remote"]
+        else:
+            return False
+    
     def getVirtualenvExecPath(self, venvName):
         """
         Public method to get the search path prefix of a virtual environment.

eric ide

mercurial