VirtualEnv/VirtualenvManager.py

changeset 6503
e617c58807e8
parent 6386
91dc4fa9bc9c
child 6576
ea60ea85067a
diff -r 07070e95be4d -r e617c58807e8 VirtualEnv/VirtualenvManager.py
--- a/VirtualEnv/VirtualenvManager.py	Sun Sep 16 13:32:57 2018 +0200
+++ b/VirtualEnv/VirtualenvManager.py	Sun Sep 16 13:36:01 2018 +0200
@@ -27,6 +27,8 @@
     """
     Class implementing an object to manage Python virtual environments.
     """
+    DefaultKey = "<default>"
+    
     def __init__(self, parent=None):
         """
         Constructor
@@ -76,7 +78,7 @@
                 break
         if not found:
             # add an environment entry for the default interpreter
-            self.__virtualEnvironments["<default>"] = {
+            self.__virtualEnvironments[VirtualenvManager.DefaultKey] = {
                 "path": "",
                 "interpreter": defaultPy,
                 "variant": sys.version_info[0],
@@ -94,6 +96,37 @@
             json.dumps(self.__virtualEnvironments)
         )
     
+    def getDefaultEnvironment(self):
+        """
+        Public method to get the default virtual environment.
+        
+        Default is an environment with the key '<default>' or the first one
+        having an interpreter matching sys.executable (i.e. the one used to
+        execute eric6 with)
+        
+        @return tuple containing the environment name and a dictionary
+            containing a copy of the default virtual environment
+        @rtype tuple of (str, dict)
+        """
+        if VirtualenvManager.DefaultKey in self.__virtualEnvironments:
+            return (
+                VirtualenvManager.DefaultKey,
+                copy.copy(
+                    self.__virtualEnvironments[VirtualenvManager.DefaultKey])
+            )
+        
+        else:
+            defaultPy = sys.executable.replace("w.exe", ".exe")
+            for venvName in self.__virtualEnvironments:
+                if (defaultPy ==
+                        self.__virtualEnvironments[venvName]["interpreter"]):
+                    return (
+                        venvName,
+                        copy.copy(self.__virtualEnvironments[venvName])
+                    )
+        
+        return ("", {})
+    
     @pyqtSlot()
     def createVirtualEnv(self):
         """

eric ide

mercurial