25 |
25 |
26 class VirtualenvManager(QObject): |
26 class VirtualenvManager(QObject): |
27 """ |
27 """ |
28 Class implementing an object to manage Python virtual environments. |
28 Class implementing an object to manage Python virtual environments. |
29 """ |
29 """ |
|
30 DefaultKey = "<default>" |
|
31 |
30 def __init__(self, parent=None): |
32 def __init__(self, parent=None): |
31 """ |
33 """ |
32 Constructor |
34 Constructor |
33 |
35 |
34 @param parent reference to the parent object |
36 @param parent reference to the parent object |
74 self.__virtualEnvironments[venvName]["interpreter"]): |
76 self.__virtualEnvironments[venvName]["interpreter"]): |
75 found = True |
77 found = True |
76 break |
78 break |
77 if not found: |
79 if not found: |
78 # add an environment entry for the default interpreter |
80 # add an environment entry for the default interpreter |
79 self.__virtualEnvironments["<default>"] = { |
81 self.__virtualEnvironments[VirtualenvManager.DefaultKey] = { |
80 "path": "", |
82 "path": "", |
81 "interpreter": defaultPy, |
83 "interpreter": defaultPy, |
82 "variant": sys.version_info[0], |
84 "variant": sys.version_info[0], |
83 "is_global": True, |
85 "is_global": True, |
84 } |
86 } |
91 """ |
93 """ |
92 Preferences.Prefs.settings.setValue( |
94 Preferences.Prefs.settings.setValue( |
93 "PyVenv/VirtualEnvironments", |
95 "PyVenv/VirtualEnvironments", |
94 json.dumps(self.__virtualEnvironments) |
96 json.dumps(self.__virtualEnvironments) |
95 ) |
97 ) |
|
98 |
|
99 def getDefaultEnvironment(self): |
|
100 """ |
|
101 Public method to get the default virtual environment. |
|
102 |
|
103 Default is an environment with the key '<default>' or the first one |
|
104 having an interpreter matching sys.executable (i.e. the one used to |
|
105 execute eric6 with) |
|
106 |
|
107 @return tuple containing the environment name and a dictionary |
|
108 containing a copy of the default virtual environment |
|
109 @rtype tuple of (str, dict) |
|
110 """ |
|
111 if VirtualenvManager.DefaultKey in self.__virtualEnvironments: |
|
112 return ( |
|
113 VirtualenvManager.DefaultKey, |
|
114 copy.copy( |
|
115 self.__virtualEnvironments[VirtualenvManager.DefaultKey]) |
|
116 ) |
|
117 |
|
118 else: |
|
119 defaultPy = sys.executable.replace("w.exe", ".exe") |
|
120 for venvName in self.__virtualEnvironments: |
|
121 if (defaultPy == |
|
122 self.__virtualEnvironments[venvName]["interpreter"]): |
|
123 return ( |
|
124 venvName, |
|
125 copy.copy(self.__virtualEnvironments[venvName]) |
|
126 ) |
|
127 |
|
128 return ("", {}) |
96 |
129 |
97 @pyqtSlot() |
130 @pyqtSlot() |
98 def createVirtualEnv(self): |
131 def createVirtualEnv(self): |
99 """ |
132 """ |
100 Public slot to create a new virtual environment. |
133 Public slot to create a new virtual environment. |