VirtualEnv/VirtualenvManager.py

changeset 6576
ea60ea85067a
parent 6503
e617c58807e8
child 6645
ad476851d7e0
equal deleted inserted replaced
6575:40a11619ee77 6576:ea60ea85067a
57 # path: the directory of the virtual environment 57 # path: the directory of the virtual environment
58 # (empty for a global environment) 58 # (empty for a global environment)
59 # interpreter: the path of the Python interpreter 59 # interpreter: the path of the Python interpreter
60 # variant: Python variant (2 or 3) 60 # variant: Python variant (2 or 3)
61 # is_global: a flag indicating a global environment 61 # is_global: a flag indicating a global environment
62 # is_conda: a flag indicating an Anaconda environment
63 # exec_path: a string to be prefixed to the PATH environment
64 # setting
62 # 65 #
63 for venvName in environments: 66 for venvName in environments:
64 interpreter = environments[venvName]["interpreter"] 67 interpreter = environments[venvName]["interpreter"]
65 if os.access(interpreter, os.X_OK): 68 if os.access(interpreter, os.X_OK):
66 environment = environments[venvName] 69 environment = environments[venvName]
67 if "is_global" not in environment: 70 if "is_global" not in environment:
68 environment["is_global"] = environment["path"] == "" 71 environment["is_global"] = environment["path"] == ""
72 if "is_conda" not in environment:
73 environment["is_conda"] = False
74 if "exec_path" not in environment:
75 environment["exec_path"] = ""
69 self.__virtualEnvironments[venvName] = environment 76 self.__virtualEnvironments[venvName] = environment
70 77
71 # check, if the interpreter used to run eric is in the environments 78 # check, if the interpreter used to run eric is in the environments
72 defaultPy = sys.executable.replace("w.exe", ".exe") 79 defaultPy = sys.executable.replace("w.exe", ".exe")
73 found = False 80 found = False
81 self.__virtualEnvironments[VirtualenvManager.DefaultKey] = { 88 self.__virtualEnvironments[VirtualenvManager.DefaultKey] = {
82 "path": "", 89 "path": "",
83 "interpreter": defaultPy, 90 "interpreter": defaultPy,
84 "variant": sys.version_info[0], 91 "variant": sys.version_info[0],
85 "is_global": True, 92 "is_global": True,
93 "is_conda": False,
94 "exec_path": "",
86 } 95 }
87 96
88 self.__saveSettings() 97 self.__saveSettings()
89 98
90 def __saveSettings(self): 99 def __saveSettings(self):
148 dia.show() 157 dia.show()
149 dia.start(args) 158 dia.start(args)
150 dia.exec_() 159 dia.exec_()
151 160
152 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="", 161 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="",
153 venvVariant=3, isGlobal=False): 162 venvVariant=3, isGlobal=False, isConda=False,
163 execPath=""):
154 """ 164 """
155 Public method to add a virtual environment. 165 Public method to add a virtual environment.
156 166
157 @param venvName logical name for the virtual environment 167 @param venvName logical name for the virtual environment
158 @type str 168 @type str
162 @type str 172 @type str
163 @param venvVariant Python variant of the virtual environment 173 @param venvVariant Python variant of the virtual environment
164 @type int 174 @type int
165 @param isGlobal flag indicating a global environment 175 @param isGlobal flag indicating a global environment
166 @type bool 176 @type bool
177 @param isConda flag indicating an Anaconda virtual environment
178 @type bool
179 @param execPath search path string to be prepended to the PATH
180 environment variable
181 @type str
167 """ 182 """
168 if venvName in self.__virtualEnvironments: 183 if venvName in self.__virtualEnvironments:
169 ok = E5MessageBox.yesNo( 184 ok = E5MessageBox.yesNo(
170 None, 185 None,
171 self.tr("Add Virtual Environment"), 186 self.tr("Add Virtual Environment"),
188 self.__virtualEnvironments[venvName] = { 203 self.__virtualEnvironments[venvName] = {
189 "path": venvDirectory, 204 "path": venvDirectory,
190 "interpreter": venvInterpreter, 205 "interpreter": venvInterpreter,
191 "variant": venvVariant, 206 "variant": venvVariant,
192 "is_global": isGlobal, 207 "is_global": isGlobal,
208 "is_conda": isConda,
209 "exec_path": execPath,
193 } 210 }
194 211
195 self.__saveSettings() 212 self.__saveSettings()
196 213
197 if self.__virtualenvManagerDialog: 214 if self.__virtualenvManagerDialog:
198 self.__virtualenvManagerDialog.refresh() 215 self.__virtualenvManagerDialog.refresh()
199 216
200 def setVirtualEnv(self, venvName, venvDirectory, venvInterpreter, 217 def setVirtualEnv(self, venvName, venvDirectory, venvInterpreter,
201 venvVariant, isGlobal): 218 venvVariant, isGlobal, isConda, execPath):
202 """ 219 """
203 Public method to change a virtual environment. 220 Public method to change a virtual environment.
204 221
205 @param venvName logical name of the virtual environment 222 @param venvName logical name of the virtual environment
206 @type str 223 @type str
210 @type str 227 @type str
211 @param venvVariant Python variant of the virtual environment 228 @param venvVariant Python variant of the virtual environment
212 @type int 229 @type int
213 @param isGlobal flag indicating a global environment 230 @param isGlobal flag indicating a global environment
214 @type bool 231 @type bool
232 @param isConda flag indicating an Anaconda virtual environment
233 @type bool
234 @param execPath search path string to be prepended to the PATH
235 environment variable
236 @type str
215 """ 237 """
216 if venvName not in self.__virtualEnvironments: 238 if venvName not in self.__virtualEnvironments:
217 E5MessageBox.yesNo( 239 E5MessageBox.yesNo(
218 None, 240 None,
219 self.tr("Change Virtual Environment"), 241 self.tr("Change Virtual Environment"),
226 self.__virtualEnvironments[venvName] = { 248 self.__virtualEnvironments[venvName] = {
227 "path": venvDirectory, 249 "path": venvDirectory,
228 "interpreter": venvInterpreter, 250 "interpreter": venvInterpreter,
229 "variant": venvVariant, 251 "variant": venvVariant,
230 "is_global": isGlobal, 252 "is_global": isGlobal,
253 "is_conda": isConda,
254 "exec_path": execPath,
231 } 255 }
232 256
233 self.__saveSettings() 257 self.__saveSettings()
234 258
235 if self.__virtualenvManagerDialog: 259 if self.__virtualenvManagerDialog:
236 self.__virtualenvManagerDialog.refresh() 260 self.__virtualenvManagerDialog.refresh()
237 261
238 def renameVirtualEnv(self, oldVenvName, venvName, venvDirectory, 262 def renameVirtualEnv(self, oldVenvName, venvName, venvDirectory,
239 venvInterpreter, venvVariant, isGlobal): 263 venvInterpreter, venvVariant, isGlobal, isConda,
264 execPath):
240 """ 265 """
241 Public method to substitute a virtual environment entry with a new 266 Public method to substitute a virtual environment entry with a new
242 name. 267 name.
243 268
244 @param oldVenvName old name of the virtual environment 269 @param oldVenvName old name of the virtual environment
251 @type str 276 @type str
252 @param venvVariant Python variant of the virtual environment 277 @param venvVariant Python variant of the virtual environment
253 @type int 278 @type int
254 @param isGlobal flag indicating a global environment 279 @param isGlobal flag indicating a global environment
255 @type bool 280 @type bool
281 @param isConda flag indicating an Anaconda virtual environment
282 @type bool
283 @param execPath search path string to be prepended to the PATH
284 environment variable
285 @type str
256 """ 286 """
257 if oldVenvName not in self.__virtualEnvironments: 287 if oldVenvName not in self.__virtualEnvironments:
258 E5MessageBox.yesNo( 288 E5MessageBox.yesNo(
259 None, 289 None,
260 self.tr("Rename Virtual Environment"), 290 self.tr("Rename Virtual Environment"),
264 icon=E5MessageBox.Warning) 294 icon=E5MessageBox.Warning)
265 return 295 return
266 296
267 del self.__virtualEnvironments[oldVenvName] 297 del self.__virtualEnvironments[oldVenvName]
268 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter, 298 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter,
269 venvVariant, isGlobal) 299 venvVariant, isGlobal, isConda, execPath)
270 300
271 def deleteVirtualEnvs(self, venvNames): 301 def deleteVirtualEnvs(self, venvNames):
272 """ 302 """
273 Public method to delete virtual environments from the list and disk. 303 Public method to delete virtual environments from the list and disk.
274 304
466 @param venvName logical name of the virtual environment 496 @param venvName logical name of the virtual environment
467 @type str 497 @type str
468 @return flag indicating a global environment 498 @return flag indicating a global environment
469 @rtype bool 499 @rtype bool
470 """ 500 """
471 return self.__virtualEnvironments[venvName]["is_global"] 501 if venvName in self.__virtualEnvironments:
502 return self.__virtualEnvironments[venvName]["is_global"]
503 else:
504 return False
505
506 def isCondaEnvironment(self, venvName):
507 """
508 Public method to test, if a given environment is an Anaconda
509 environment.
510
511 @param venvName logical name of the virtual environment
512 @type str
513 @return flag indicating an Anaconda environment
514 @rtype bool
515 """
516 if venvName in self.__virtualEnvironments:
517 return self.__virtualEnvironments[venvName]["is_conda"]
518 else:
519 return False
520
521 def getVirtualenvExecPath(self, venvName):
522 """
523 Public method to get the search path prefix of a virtual environment.
524
525 @param venvName logical name for the virtual environment
526 @type str
527 @return search path prefix
528 @rtype str
529 """
530 if venvName in self.__virtualEnvironments:
531 return self.__virtualEnvironments[venvName]["exec_path"]
532 else:
533 return ""

eric ide

mercurial