59 # (empty for a global environment) |
59 # (empty for a global environment) |
60 # interpreter: the path of the Python interpreter |
60 # interpreter: the path of the Python interpreter |
61 # variant: Python variant (2 or 3) |
61 # variant: Python variant (2 or 3) |
62 # is_global: a flag indicating a global environment |
62 # is_global: a flag indicating a global environment |
63 # is_conda: a flag indicating an Anaconda environment |
63 # is_conda: a flag indicating an Anaconda environment |
|
64 # is_remote: a flag indicating a remotely accessed environment |
64 # exec_path: a string to be prefixed to the PATH environment |
65 # exec_path: a string to be prefixed to the PATH environment |
65 # setting |
66 # setting |
66 # |
67 # |
67 for venvName in environments: |
68 for venvName in environments: |
68 interpreter = environments[venvName]["interpreter"] |
69 environment = environments[venvName] |
69 if os.access(interpreter, os.X_OK): |
70 if ("is_remote" in environment and environment["is_remote"]) or \ |
70 environment = environments[venvName] |
71 os.access(environment["interpreter"], os.X_OK): |
71 if "is_global" not in environment: |
72 if "is_global" not in environment: |
72 environment["is_global"] = environment["path"] == "" |
73 environment["is_global"] = environment["path"] == "" |
73 if "is_conda" not in environment: |
74 if "is_conda" not in environment: |
74 environment["is_conda"] = False |
75 environment["is_conda"] = False |
|
76 if "is_remote" not in environment: |
|
77 environment["is_remote"] = False |
75 if "exec_path" not in environment: |
78 if "exec_path" not in environment: |
76 environment["exec_path"] = "" |
79 environment["exec_path"] = "" |
77 self.__virtualEnvironments[venvName] = environment |
80 self.__virtualEnvironments[venvName] = environment |
78 |
81 |
79 # check, if the interpreter used to run eric is in the environments |
82 # check, if the interpreter used to run eric is in the environments |
103 """ |
107 """ |
104 Preferences.Prefs.settings.setValue( |
108 Preferences.Prefs.settings.setValue( |
105 "PyVenv/VirtualEnvironments", |
109 "PyVenv/VirtualEnvironments", |
106 json.dumps(self.__virtualEnvironments) |
110 json.dumps(self.__virtualEnvironments) |
107 ) |
111 ) |
|
112 Preferences.syncPreferences() |
108 |
113 |
109 def getDefaultEnvironment(self): |
114 def getDefaultEnvironment(self): |
110 """ |
115 """ |
111 Public method to get the default virtual environment. |
116 Public method to get the default virtual environment. |
112 |
117 |
159 dia.start(args) |
164 dia.start(args) |
160 dia.exec_() |
165 dia.exec_() |
161 |
166 |
162 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="", |
167 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="", |
163 venvVariant=3, isGlobal=False, isConda=False, |
168 venvVariant=3, isGlobal=False, isConda=False, |
164 execPath=""): |
169 isRemote=False, execPath=""): |
165 """ |
170 """ |
166 Public method to add a virtual environment. |
171 Public method to add a virtual environment. |
167 |
172 |
168 @param venvName logical name for the virtual environment |
173 @param venvName logical name for the virtual environment |
169 @type str |
174 @type str |
174 @param venvVariant Python variant of the virtual environment |
179 @param venvVariant Python variant of the virtual environment |
175 @type int |
180 @type int |
176 @param isGlobal flag indicating a global environment |
181 @param isGlobal flag indicating a global environment |
177 @type bool |
182 @type bool |
178 @param isConda flag indicating an Anaconda virtual environment |
183 @param isConda flag indicating an Anaconda virtual environment |
|
184 @type bool |
|
185 @param isRemote flag indicating a remotely accessed environment |
179 @type bool |
186 @type bool |
180 @param execPath search path string to be prepended to the PATH |
187 @param execPath search path string to be prepended to the PATH |
181 environment variable |
188 environment variable |
182 @type str |
189 @type str |
183 """ |
190 """ |
207 "path": venvDirectory, |
214 "path": venvDirectory, |
208 "interpreter": venvInterpreter, |
215 "interpreter": venvInterpreter, |
209 "variant": venvVariant, |
216 "variant": venvVariant, |
210 "is_global": isGlobal, |
217 "is_global": isGlobal, |
211 "is_conda": isConda, |
218 "is_conda": isConda, |
|
219 "is_remote": isRemote, |
212 "exec_path": execPath, |
220 "exec_path": execPath, |
213 } |
221 } |
214 |
222 |
215 self.__saveSettings() |
223 self.__saveSettings() |
216 |
224 |
217 if self.__virtualenvManagerDialog: |
225 if self.__virtualenvManagerDialog: |
218 self.__virtualenvManagerDialog.refresh() |
226 self.__virtualenvManagerDialog.refresh() |
219 |
227 |
220 def setVirtualEnv(self, venvName, venvDirectory, venvInterpreter, |
228 def setVirtualEnv(self, venvName, venvDirectory, venvInterpreter, |
221 venvVariant, isGlobal, isConda, execPath): |
229 venvVariant, isGlobal, isConda, isRemote, |
|
230 execPath): |
222 """ |
231 """ |
223 Public method to change a virtual environment. |
232 Public method to change a virtual environment. |
224 |
233 |
225 @param venvName logical name of the virtual environment |
234 @param venvName logical name of the virtual environment |
226 @type str |
235 @type str |
231 @param venvVariant Python variant of the virtual environment |
240 @param venvVariant Python variant of the virtual environment |
232 @type int |
241 @type int |
233 @param isGlobal flag indicating a global environment |
242 @param isGlobal flag indicating a global environment |
234 @type bool |
243 @type bool |
235 @param isConda flag indicating an Anaconda virtual environment |
244 @param isConda flag indicating an Anaconda virtual environment |
|
245 @type bool |
|
246 @param isRemote flag indicating a remotely accessed environment |
236 @type bool |
247 @type bool |
237 @param execPath search path string to be prepended to the PATH |
248 @param execPath search path string to be prepended to the PATH |
238 environment variable |
249 environment variable |
239 @type str |
250 @type str |
240 """ |
251 """ |
252 "path": venvDirectory, |
263 "path": venvDirectory, |
253 "interpreter": venvInterpreter, |
264 "interpreter": venvInterpreter, |
254 "variant": venvVariant, |
265 "variant": venvVariant, |
255 "is_global": isGlobal, |
266 "is_global": isGlobal, |
256 "is_conda": isConda, |
267 "is_conda": isConda, |
|
268 "is_remote": isRemote, |
257 "exec_path": execPath, |
269 "exec_path": execPath, |
258 } |
270 } |
259 |
271 |
260 self.__saveSettings() |
272 self.__saveSettings() |
261 |
273 |
262 if self.__virtualenvManagerDialog: |
274 if self.__virtualenvManagerDialog: |
263 self.__virtualenvManagerDialog.refresh() |
275 self.__virtualenvManagerDialog.refresh() |
264 |
276 |
265 def renameVirtualEnv(self, oldVenvName, venvName, venvDirectory, |
277 def renameVirtualEnv(self, oldVenvName, venvName, venvDirectory, |
266 venvInterpreter, venvVariant, isGlobal, isConda, |
278 venvInterpreter, venvVariant, isGlobal, isConda, |
267 execPath): |
279 isRemote, execPath): |
268 """ |
280 """ |
269 Public method to substitute a virtual environment entry with a new |
281 Public method to substitute a virtual environment entry with a new |
270 name. |
282 name. |
271 |
283 |
272 @param oldVenvName old name of the virtual environment |
284 @param oldVenvName old name of the virtual environment |
280 @param venvVariant Python variant of the virtual environment |
292 @param venvVariant Python variant of the virtual environment |
281 @type int |
293 @type int |
282 @param isGlobal flag indicating a global environment |
294 @param isGlobal flag indicating a global environment |
283 @type bool |
295 @type bool |
284 @param isConda flag indicating an Anaconda virtual environment |
296 @param isConda flag indicating an Anaconda virtual environment |
|
297 @type bool |
|
298 @param isRemote flag indicating a remotely accessed environment |
285 @type bool |
299 @type bool |
286 @param execPath search path string to be prepended to the PATH |
300 @param execPath search path string to be prepended to the PATH |
287 environment variable |
301 environment variable |
288 @type str |
302 @type str |
289 """ |
303 """ |
297 icon=E5MessageBox.Warning) |
311 icon=E5MessageBox.Warning) |
298 return |
312 return |
299 |
313 |
300 del self.__virtualEnvironments[oldVenvName] |
314 del self.__virtualEnvironments[oldVenvName] |
301 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter, |
315 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter, |
302 venvVariant, isGlobal, isConda, execPath) |
316 venvVariant, isGlobal, isConda, isRemote, |
|
317 execPath) |
303 |
318 |
304 def deleteVirtualEnvs(self, venvNames): |
319 def deleteVirtualEnvs(self, venvNames): |
305 """ |
320 """ |
306 Public method to delete virtual environments from the list and disk. |
321 Public method to delete virtual environments from the list and disk. |
307 |
322 |
349 ok = False |
364 ok = False |
350 if venvName in self.__virtualEnvironments: |
365 if venvName in self.__virtualEnvironments: |
351 ok = True |
366 ok = True |
352 ok &= bool(self.__virtualEnvironments[venvName]["path"]) |
367 ok &= bool(self.__virtualEnvironments[venvName]["path"]) |
353 ok &= not self.__virtualEnvironments[venvName]["is_global"] |
368 ok &= not self.__virtualEnvironments[venvName]["is_global"] |
|
369 ok &= not self.__virtualEnvironments[venvName]["is_remote"] |
354 ok &= os.access(self.__virtualEnvironments[venvName]["path"], |
370 ok &= os.access(self.__virtualEnvironments[venvName]["path"], |
355 os.W_OK) |
371 os.W_OK) |
356 |
372 |
357 return ok |
373 return ok |
358 |
374 |
519 if venvName in self.__virtualEnvironments: |
535 if venvName in self.__virtualEnvironments: |
520 return self.__virtualEnvironments[venvName]["is_conda"] |
536 return self.__virtualEnvironments[venvName]["is_conda"] |
521 else: |
537 else: |
522 return False |
538 return False |
523 |
539 |
|
540 def isRemoteEnvironment(self, venvName): |
|
541 """ |
|
542 Public method to test, if a given environment is a remotely accessed |
|
543 environment. |
|
544 |
|
545 @param venvName logical name of the virtual environment |
|
546 @type str |
|
547 @return flag indicating a remotely accessed environment |
|
548 @rtype bool |
|
549 """ |
|
550 if venvName in self.__virtualEnvironments: |
|
551 return self.__virtualEnvironments[venvName]["is_remote"] |
|
552 else: |
|
553 return False |
|
554 |
524 def getVirtualenvExecPath(self, venvName): |
555 def getVirtualenvExecPath(self, venvName): |
525 """ |
556 """ |
526 Public method to get the search path prefix of a virtual environment. |
557 Public method to get the search path prefix of a virtual environment. |
527 |
558 |
528 @param venvName logical name for the virtual environment |
559 @param venvName logical name for the virtual environment |