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 |
167 dia.start(resultDict["arguments"]) |
172 dia.start(resultDict["arguments"]) |
168 dia.exec_() |
173 dia.exec_() |
169 |
174 |
170 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="", |
175 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="", |
171 venvVariant=3, isGlobal=False, isConda=False, |
176 venvVariant=3, isGlobal=False, isConda=False, |
172 execPath=""): |
177 isRemote=False, execPath=""): |
173 """ |
178 """ |
174 Public method to add a virtual environment. |
179 Public method to add a virtual environment. |
175 |
180 |
176 @param venvName logical name for the virtual environment |
181 @param venvName logical name for the virtual environment |
177 @type str |
182 @type str |
182 @param venvVariant Python variant of the virtual environment |
187 @param venvVariant Python variant of the virtual environment |
183 @type int |
188 @type int |
184 @param isGlobal flag indicating a global environment |
189 @param isGlobal flag indicating a global environment |
185 @type bool |
190 @type bool |
186 @param isConda flag indicating an Anaconda virtual environment |
191 @param isConda flag indicating an Anaconda virtual environment |
|
192 @type bool |
|
193 @param isRemote flag indicating a remotely accessed environment |
187 @type bool |
194 @type bool |
188 @param execPath search path string to be prepended to the PATH |
195 @param execPath search path string to be prepended to the PATH |
189 environment variable |
196 environment variable |
190 @type str |
197 @type str |
191 """ |
198 """ |
219 "path": venvDirectory, |
226 "path": venvDirectory, |
220 "interpreter": venvInterpreter, |
227 "interpreter": venvInterpreter, |
221 "variant": venvVariant, |
228 "variant": venvVariant, |
222 "is_global": isGlobal, |
229 "is_global": isGlobal, |
223 "is_conda": isConda, |
230 "is_conda": isConda, |
|
231 "is_remote": isRemote, |
224 "exec_path": execPath, |
232 "exec_path": execPath, |
225 } |
233 } |
226 |
234 |
227 self.__saveSettings() |
235 self.__saveSettings() |
228 |
236 |
229 if self.__virtualenvManagerDialog: |
237 if self.__virtualenvManagerDialog: |
230 self.__virtualenvManagerDialog.refresh() |
238 self.__virtualenvManagerDialog.refresh() |
231 |
239 |
232 def setVirtualEnv(self, venvName, venvDirectory, venvInterpreter, |
240 def setVirtualEnv(self, venvName, venvDirectory, venvInterpreter, |
233 venvVariant, isGlobal, isConda, execPath): |
241 venvVariant, isGlobal, isConda, isRemote, |
|
242 execPath): |
234 """ |
243 """ |
235 Public method to change a virtual environment. |
244 Public method to change a virtual environment. |
236 |
245 |
237 @param venvName logical name of the virtual environment |
246 @param venvName logical name of the virtual environment |
238 @type str |
247 @type str |
243 @param venvVariant Python variant of the virtual environment |
252 @param venvVariant Python variant of the virtual environment |
244 @type int |
253 @type int |
245 @param isGlobal flag indicating a global environment |
254 @param isGlobal flag indicating a global environment |
246 @type bool |
255 @type bool |
247 @param isConda flag indicating an Anaconda virtual environment |
256 @param isConda flag indicating an Anaconda virtual environment |
|
257 @type bool |
|
258 @param isRemote flag indicating a remotely accessed environment |
248 @type bool |
259 @type bool |
249 @param execPath search path string to be prepended to the PATH |
260 @param execPath search path string to be prepended to the PATH |
250 environment variable |
261 environment variable |
251 @type str |
262 @type str |
252 """ |
263 """ |
264 "path": venvDirectory, |
275 "path": venvDirectory, |
265 "interpreter": venvInterpreter, |
276 "interpreter": venvInterpreter, |
266 "variant": venvVariant, |
277 "variant": venvVariant, |
267 "is_global": isGlobal, |
278 "is_global": isGlobal, |
268 "is_conda": isConda, |
279 "is_conda": isConda, |
|
280 "is_remote": isRemote, |
269 "exec_path": execPath, |
281 "exec_path": execPath, |
270 } |
282 } |
271 |
283 |
272 self.__saveSettings() |
284 self.__saveSettings() |
273 |
285 |
274 if self.__virtualenvManagerDialog: |
286 if self.__virtualenvManagerDialog: |
275 self.__virtualenvManagerDialog.refresh() |
287 self.__virtualenvManagerDialog.refresh() |
276 |
288 |
277 def renameVirtualEnv(self, oldVenvName, venvName, venvDirectory, |
289 def renameVirtualEnv(self, oldVenvName, venvName, venvDirectory, |
278 venvInterpreter, venvVariant, isGlobal, isConda, |
290 venvInterpreter, venvVariant, isGlobal, isConda, |
279 execPath): |
291 isRemote, execPath): |
280 """ |
292 """ |
281 Public method to substitute a virtual environment entry with a new |
293 Public method to substitute a virtual environment entry with a new |
282 name. |
294 name. |
283 |
295 |
284 @param oldVenvName old name of the virtual environment |
296 @param oldVenvName old name of the virtual environment |
292 @param venvVariant Python variant of the virtual environment |
304 @param venvVariant Python variant of the virtual environment |
293 @type int |
305 @type int |
294 @param isGlobal flag indicating a global environment |
306 @param isGlobal flag indicating a global environment |
295 @type bool |
307 @type bool |
296 @param isConda flag indicating an Anaconda virtual environment |
308 @param isConda flag indicating an Anaconda virtual environment |
|
309 @type bool |
|
310 @param isRemote flag indicating a remotely accessed environment |
297 @type bool |
311 @type bool |
298 @param execPath search path string to be prepended to the PATH |
312 @param execPath search path string to be prepended to the PATH |
299 environment variable |
313 environment variable |
300 @type str |
314 @type str |
301 """ |
315 """ |
309 icon=E5MessageBox.Warning) |
323 icon=E5MessageBox.Warning) |
310 return |
324 return |
311 |
325 |
312 del self.__virtualEnvironments[oldVenvName] |
326 del self.__virtualEnvironments[oldVenvName] |
313 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter, |
327 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter, |
314 venvVariant, isGlobal, isConda, execPath) |
328 venvVariant, isGlobal, isConda, isRemote, |
|
329 execPath) |
315 |
330 |
316 def deleteVirtualEnvs(self, venvNames): |
331 def deleteVirtualEnvs(self, venvNames): |
317 """ |
332 """ |
318 Public method to delete virtual environments from the list and disk. |
333 Public method to delete virtual environments from the list and disk. |
319 |
334 |
369 ok = False |
384 ok = False |
370 if venvName in self.__virtualEnvironments: |
385 if venvName in self.__virtualEnvironments: |
371 ok = True |
386 ok = True |
372 ok &= bool(self.__virtualEnvironments[venvName]["path"]) |
387 ok &= bool(self.__virtualEnvironments[venvName]["path"]) |
373 ok &= not self.__virtualEnvironments[venvName]["is_global"] |
388 ok &= not self.__virtualEnvironments[venvName]["is_global"] |
|
389 ok &= not self.__virtualEnvironments[venvName]["is_remote"] |
374 ok &= os.access(self.__virtualEnvironments[venvName]["path"], |
390 ok &= os.access(self.__virtualEnvironments[venvName]["path"], |
375 os.W_OK) |
391 os.W_OK) |
376 |
392 |
377 return ok |
393 return ok |
378 |
394 |
539 if venvName in self.__virtualEnvironments: |
555 if venvName in self.__virtualEnvironments: |
540 return self.__virtualEnvironments[venvName]["is_conda"] |
556 return self.__virtualEnvironments[venvName]["is_conda"] |
541 else: |
557 else: |
542 return False |
558 return False |
543 |
559 |
|
560 def isRemoteEnvironment(self, venvName): |
|
561 """ |
|
562 Public method to test, if a given environment is a remotely accessed |
|
563 environment. |
|
564 |
|
565 @param venvName logical name of the virtual environment |
|
566 @type str |
|
567 @return flag indicating a remotely accessed environment |
|
568 @rtype bool |
|
569 """ |
|
570 if venvName in self.__virtualEnvironments: |
|
571 return self.__virtualEnvironments[venvName]["is_remote"] |
|
572 else: |
|
573 return False |
|
574 |
544 def getVirtualenvExecPath(self, venvName): |
575 def getVirtualenvExecPath(self, venvName): |
545 """ |
576 """ |
546 Public method to get the search path prefix of a virtual environment. |
577 Public method to get the search path prefix of a virtual environment. |
547 |
578 |
548 @param venvName logical name for the virtual environment |
579 @param venvName logical name for the virtual environment |