14 import copy |
14 import copy |
15 |
15 |
16 from PyQt6.QtCore import pyqtSlot, pyqtSignal, QObject |
16 from PyQt6.QtCore import pyqtSlot, pyqtSignal, QObject |
17 from PyQt6.QtWidgets import QDialog |
17 from PyQt6.QtWidgets import QDialog |
18 |
18 |
19 from E5Gui import E5MessageBox |
19 from E5Gui import EricMessageBox |
20 from E5Gui.E5Application import e5App |
20 from E5Gui.EricApplication import ericApp |
21 |
21 |
22 import Preferences |
22 import Preferences |
23 |
23 |
24 |
24 |
25 class VirtualenvManager(QObject): |
25 class VirtualenvManager(QObject): |
184 if dlg.exec() == QDialog.DialogCode.Accepted: |
184 if dlg.exec() == QDialog.DialogCode.Accepted: |
185 resultDict = dlg.getData() |
185 resultDict = dlg.getData() |
186 |
186 |
187 if resultDict["envType"] == "conda": |
187 if resultDict["envType"] == "conda": |
188 # create the conda environment |
188 # create the conda environment |
189 conda = e5App().getObject("Conda") |
189 conda = ericApp().getObject("Conda") |
190 ok, prefix, interpreter = conda.createCondaEnvironment( |
190 ok, prefix, interpreter = conda.createCondaEnvironment( |
191 resultDict["arguments"]) |
191 resultDict["arguments"]) |
192 if ok and "--dry-run" not in resultDict["arguments"]: |
192 if ok and "--dry-run" not in resultDict["arguments"]: |
193 self.addVirtualEnv(resultDict["logicalName"], |
193 self.addVirtualEnv(resultDict["logicalName"], |
194 prefix, |
194 prefix, |
223 @param execPath search path string to be prepended to the PATH |
223 @param execPath search path string to be prepended to the PATH |
224 environment variable |
224 environment variable |
225 @type str |
225 @type str |
226 """ |
226 """ |
227 if venvName in self.__virtualEnvironments: |
227 if venvName in self.__virtualEnvironments: |
228 ok = E5MessageBox.yesNo( |
228 ok = EricMessageBox.yesNo( |
229 None, |
229 None, |
230 self.tr("Add Virtual Environment"), |
230 self.tr("Add Virtual Environment"), |
231 self.tr("""A virtual environment named <b>{0}</b> exists""" |
231 self.tr("""A virtual environment named <b>{0}</b> exists""" |
232 """ already. Shall it be replaced?""") |
232 """ already. Shall it be replaced?""") |
233 .format(venvName), |
233 .format(venvName), |
234 icon=E5MessageBox.Warning) |
234 icon=EricMessageBox.Warning) |
235 if not ok: |
235 if not ok: |
236 from .VirtualenvNameDialog import VirtualenvNameDialog |
236 from .VirtualenvNameDialog import VirtualenvNameDialog |
237 dlg = VirtualenvNameDialog( |
237 dlg = VirtualenvNameDialog( |
238 list(self.__virtualEnvironments.keys()), |
238 list(self.__virtualEnvironments.keys()), |
239 venvName) |
239 venvName) |
287 @param execPath search path string to be prepended to the PATH |
287 @param execPath search path string to be prepended to the PATH |
288 environment variable |
288 environment variable |
289 @type str |
289 @type str |
290 """ |
290 """ |
291 if venvName not in self.__virtualEnvironments: |
291 if venvName not in self.__virtualEnvironments: |
292 E5MessageBox.yesNo( |
292 EricMessageBox.yesNo( |
293 None, |
293 None, |
294 self.tr("Change Virtual Environment"), |
294 self.tr("Change Virtual Environment"), |
295 self.tr("""A virtual environment named <b>{0}</b> does not""" |
295 self.tr("""A virtual environment named <b>{0}</b> does not""" |
296 """ exist. Aborting!""") |
296 """ exist. Aborting!""") |
297 .format(venvName), |
297 .format(venvName), |
298 icon=E5MessageBox.Warning) |
298 icon=EricMessageBox.Warning) |
299 return |
299 return |
300 |
300 |
301 self.__virtualEnvironments[venvName] = { |
301 self.__virtualEnvironments[venvName] = { |
302 "path": venvDirectory, |
302 "path": venvDirectory, |
303 "interpreter": venvInterpreter, |
303 "interpreter": venvInterpreter, |
338 @param execPath search path string to be prepended to the PATH |
338 @param execPath search path string to be prepended to the PATH |
339 environment variable |
339 environment variable |
340 @type str |
340 @type str |
341 """ |
341 """ |
342 if oldVenvName not in self.__virtualEnvironments: |
342 if oldVenvName not in self.__virtualEnvironments: |
343 E5MessageBox.yesNo( |
343 EricMessageBox.yesNo( |
344 None, |
344 None, |
345 self.tr("Rename Virtual Environment"), |
345 self.tr("Rename Virtual Environment"), |
346 self.tr("""A virtual environment named <b>{0}</b> does not""" |
346 self.tr("""A virtual environment named <b>{0}</b> does not""" |
347 """ exist. Aborting!""") |
347 """ exist. Aborting!""") |
348 .format(oldVenvName), |
348 .format(oldVenvName), |
349 icon=E5MessageBox.Warning) |
349 icon=EricMessageBox.Warning) |
350 return |
350 return |
351 |
351 |
352 del self.__virtualEnvironments[oldVenvName] |
352 del self.__virtualEnvironments[oldVenvName] |
353 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter, |
353 self.addVirtualEnv(venvName, venvDirectory, venvInterpreter, |
354 isGlobal, isConda, isRemote, execPath) |
354 isGlobal, isConda, isRemote, execPath) |
381 ) |
381 ) |
382 if dlg.exec() == QDialog.DialogCode.Accepted: |
382 if dlg.exec() == QDialog.DialogCode.Accepted: |
383 for venvName in venvNames: |
383 for venvName in venvNames: |
384 if self.__isEnvironmentDeleteable(venvName): |
384 if self.__isEnvironmentDeleteable(venvName): |
385 if self.isCondaEnvironment(venvName): |
385 if self.isCondaEnvironment(venvName): |
386 conda = e5App().getObject("Conda") |
386 conda = ericApp().getObject("Conda") |
387 path = self.__virtualEnvironments[venvName]["path"] |
387 path = self.__virtualEnvironments[venvName]["path"] |
388 res = conda.removeCondaEnvironment(prefix=path) |
388 res = conda.removeCondaEnvironment(prefix=path) |
389 if res: |
389 if res: |
390 del self.__virtualEnvironments[venvName] |
390 del self.__virtualEnvironments[venvName] |
391 else: |
391 else: |