17 |
17 |
18 from PyQt5.QtCore import pyqtSlot, QObject |
18 from PyQt5.QtCore import pyqtSlot, QObject |
19 from PyQt5.QtWidgets import QDialog |
19 from PyQt5.QtWidgets import QDialog |
20 |
20 |
21 from E5Gui import E5MessageBox |
21 from E5Gui import E5MessageBox |
|
22 from E5Gui.E5Application import e5App |
22 |
23 |
23 import Preferences |
24 import Preferences |
24 import Utilities |
|
25 |
25 |
26 |
26 |
27 class VirtualenvManager(QObject): |
27 class VirtualenvManager(QObject): |
28 """ |
28 """ |
29 Class implementing an object to manage Python virtual environments. |
29 Class implementing an object to manage Python virtual environments. |
146 VirtualenvConfigurationDialog |
146 VirtualenvConfigurationDialog |
147 |
147 |
148 dlg = VirtualenvConfigurationDialog() |
148 dlg = VirtualenvConfigurationDialog() |
149 if dlg.exec_() == QDialog.Accepted: |
149 if dlg.exec_() == QDialog.Accepted: |
150 resultDict = dlg.getData() |
150 resultDict = dlg.getData() |
151 ## (pyvenv, args, name, openTarget, createLog, createScript, |
|
152 ## targetDir, interpreter) = dlg.getData() |
|
153 |
151 |
154 if resultDict["envType"] == "conda": |
152 if resultDict["envType"] == "conda": |
155 from CondaInterface.CondaExecDialog import CondaExecDialog |
153 # create the conda environment |
156 dia = CondaExecDialog(resultDict, self) |
154 conda = e5App().getObject("Conda") |
|
155 ok, prefix, interpreter = conda.createCondaEnvironment( |
|
156 resultDict["arguments"]) |
|
157 if ok and "--dry-run" not in resultDict["arguments"]: |
|
158 self.addVirtualEnv(resultDict["logicalName"], |
|
159 prefix, |
|
160 venvInterpreter=interpreter, |
|
161 isConda=True) |
157 else: |
162 else: |
158 # now do the call |
163 # now do the call |
159 from .VirtualenvExecDialog import VirtualenvExecDialog |
164 from .VirtualenvExecDialog import VirtualenvExecDialog |
160 dia = VirtualenvExecDialog(resultDict, self) |
165 dia = VirtualenvExecDialog(resultDict, self) |
161 dia.show() |
166 dia.show() |
162 dia.start(resultDict["arguments"]) |
167 dia.start(resultDict["arguments"]) |
163 dia.exec_() |
168 dia.exec_() |
164 |
169 |
165 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="", |
170 def addVirtualEnv(self, venvName, venvDirectory, venvInterpreter="", |
166 venvVariant=3, isGlobal=False, isConda=False, |
171 venvVariant=3, isGlobal=False, isConda=False, |
167 execPath=""): |
172 execPath=""): |
168 """ |
173 """ |
206 from .VirtualenvInterpreterSelectionDialog import \ |
211 from .VirtualenvInterpreterSelectionDialog import \ |
207 VirtualenvInterpreterSelectionDialog |
212 VirtualenvInterpreterSelectionDialog |
208 dlg = VirtualenvInterpreterSelectionDialog(venvName, venvDirectory) |
213 dlg = VirtualenvInterpreterSelectionDialog(venvName, venvDirectory) |
209 if dlg.exec_() == QDialog.Accepted: |
214 if dlg.exec_() == QDialog.Accepted: |
210 venvInterpreter, venvVariant = dlg.getData() |
215 venvInterpreter, venvVariant = dlg.getData() |
211 if not Utilities.startswithPath(venvInterpreter, |
|
212 venvDirectory): |
|
213 isGlobal = True |
|
214 |
216 |
215 if venvInterpreter: |
217 if venvInterpreter: |
216 self.__virtualEnvironments[venvName] = { |
218 self.__virtualEnvironments[venvName] = { |
217 "path": venvDirectory, |
219 "path": venvDirectory, |
218 "interpreter": venvInterpreter, |
220 "interpreter": venvInterpreter, |
335 venvMessages |
337 venvMessages |
336 ) |
338 ) |
337 if dlg.exec_() == QDialog.Accepted: |
339 if dlg.exec_() == QDialog.Accepted: |
338 for venvName in venvNames: |
340 for venvName in venvNames: |
339 if self.__isEnvironmentDeleteable(venvName): |
341 if self.__isEnvironmentDeleteable(venvName): |
340 shutil.rmtree( |
342 if self.isCondaEnvironment(venvName): |
341 self.__virtualEnvironments[venvName]["path"], True) |
343 conda = e5App().getObject("Conda") |
342 del self.__virtualEnvironments[venvName] |
344 path = self.__virtualEnvironments[venvName]["path"] |
|
345 res = conda.removeCondaEnvironment(prefix=path) |
|
346 if res: |
|
347 del self.__virtualEnvironments[venvName] |
|
348 else: |
|
349 shutil.rmtree( |
|
350 self.__virtualEnvironments[venvName]["path"], |
|
351 True) |
|
352 del self.__virtualEnvironments[venvName] |
343 |
353 |
344 self.__saveSettings() |
354 self.__saveSettings() |
345 |
355 |
346 if self.__virtualenvManagerDialog: |
356 if self.__virtualenvManagerDialog: |
347 self.__virtualenvManagerDialog.refresh() |
357 self.__virtualenvManagerDialog.refresh() |