17 from PyQt6.QtWidgets import QDialog |
17 from PyQt6.QtWidgets import QDialog |
18 |
18 |
19 from eric7 import Globals, Preferences |
19 from eric7 import Globals, Preferences |
20 from eric7.EricWidgets import EricMessageBox |
20 from eric7.EricWidgets import EricMessageBox |
21 from eric7.EricWidgets.EricApplication import ericApp |
21 from eric7.EricWidgets.EricApplication import ericApp |
|
22 from eric7.UI.DeleteFilesConfirmationDialog import DeleteFilesConfirmationDialog |
22 |
23 |
23 |
24 |
24 class VirtualenvManager(QObject): |
25 class VirtualenvManager(QObject): |
25 """ |
26 """ |
26 Class implementing an object to manage Python virtual environments. |
27 Class implementing an object to manage Python virtual environments. |
194 |
195 |
195 @param baseDir base directory for the virtual environments |
196 @param baseDir base directory for the virtual environments |
196 @type str |
197 @type str |
197 """ |
198 """ |
198 from .VirtualenvConfigurationDialog import VirtualenvConfigurationDialog |
199 from .VirtualenvConfigurationDialog import VirtualenvConfigurationDialog |
|
200 from .VirtualenvExecDialog import VirtualenvExecDialog |
199 |
201 |
200 if not baseDir: |
202 if not baseDir: |
201 baseDir = self.__virtualEnvironmentsBaseDir |
203 baseDir = self.__virtualEnvironmentsBaseDir |
202 |
204 |
203 dlg = VirtualenvConfigurationDialog(baseDir=baseDir) |
205 dlg = VirtualenvConfigurationDialog(baseDir=baseDir) |
235 @type str |
235 @type str |
236 """ |
236 """ |
237 from .VirtualenvUpgradeConfigurationDialog import ( |
237 from .VirtualenvUpgradeConfigurationDialog import ( |
238 VirtualenvUpgradeConfigurationDialog, |
238 VirtualenvUpgradeConfigurationDialog, |
239 ) |
239 ) |
|
240 from .VirtualenvUpgradeExecDialog import VirtualenvUpgradeExecDialog |
240 |
241 |
241 venvDirectory = self.getVirtualenvDirectory(venvName) |
242 venvDirectory = self.getVirtualenvDirectory(venvName) |
242 if not os.path.exists(os.path.join(venvDirectory, "pyvenv.cfg")): |
243 if not os.path.exists(os.path.join(venvDirectory, "pyvenv.cfg")): |
243 # The environment was not created by the 'venv' module. |
244 # The environment was not created by the 'venv' module. |
244 return |
245 return |
245 |
246 |
246 dlg = VirtualenvUpgradeConfigurationDialog(venvName, venvDirectory) |
247 dlg = VirtualenvUpgradeConfigurationDialog(venvName, venvDirectory) |
247 if dlg.exec() == QDialog.DialogCode.Accepted: |
248 if dlg.exec() == QDialog.DialogCode.Accepted: |
248 pythonExe, args, createLog = dlg.getData() |
249 pythonExe, args, createLog = dlg.getData() |
249 |
|
250 from .VirtualenvUpgradeExecDialog import VirtualenvUpgradeExecDialog |
|
251 |
250 |
252 dia = VirtualenvUpgradeExecDialog(venvName, pythonExe, createLog, self) |
251 dia = VirtualenvUpgradeExecDialog(venvName, pythonExe, createLog, self) |
253 dia.show() |
252 dia.show() |
254 dia.start(args) |
253 dia.start(args) |
255 dia.exec() |
254 dia.exec() |
284 environment variable |
283 environment variable |
285 @type str |
284 @type str |
286 @param description descriptive text for the environment |
285 @param description descriptive text for the environment |
287 @type str |
286 @type str |
288 """ |
287 """ |
|
288 from .VirtualenvInterpreterSelectionDialog import ( |
|
289 VirtualenvInterpreterSelectionDialog, |
|
290 ) |
|
291 from .VirtualenvNameDialog import VirtualenvNameDialog |
|
292 |
289 if venvName in self.__virtualEnvironments: |
293 if venvName in self.__virtualEnvironments: |
290 ok = EricMessageBox.yesNo( |
294 ok = EricMessageBox.yesNo( |
291 None, |
295 None, |
292 self.tr("Add Virtual Environment"), |
296 self.tr("Add Virtual Environment"), |
293 self.tr( |
297 self.tr( |
295 """ already. Shall it be replaced?""" |
299 """ already. Shall it be replaced?""" |
296 ).format(venvName), |
300 ).format(venvName), |
297 icon=EricMessageBox.Warning, |
301 icon=EricMessageBox.Warning, |
298 ) |
302 ) |
299 if not ok: |
303 if not ok: |
300 from .VirtualenvNameDialog import VirtualenvNameDialog |
|
301 |
|
302 dlg = VirtualenvNameDialog( |
304 dlg = VirtualenvNameDialog( |
303 list(self.__virtualEnvironments.keys()), venvName |
305 list(self.__virtualEnvironments.keys()), venvName |
304 ) |
306 ) |
305 if dlg.exec() != QDialog.DialogCode.Accepted: |
307 if dlg.exec() != QDialog.DialogCode.Accepted: |
306 return |
308 return |
307 |
309 |
308 venvName = dlg.getName() |
310 venvName = dlg.getName() |
309 |
311 |
310 if not venvInterpreter: |
312 if not venvInterpreter: |
311 from .VirtualenvInterpreterSelectionDialog import ( |
|
312 VirtualenvInterpreterSelectionDialog, |
|
313 ) |
|
314 |
|
315 dlg = VirtualenvInterpreterSelectionDialog(venvName, venvDirectory) |
313 dlg = VirtualenvInterpreterSelectionDialog(venvName, venvDirectory) |
316 if dlg.exec() == QDialog.DialogCode.Accepted: |
314 if dlg.exec() == QDialog.DialogCode.Accepted: |
317 venvInterpreter = dlg.getData() |
315 venvInterpreter = dlg.getData() |
318 |
316 |
319 if venvInterpreter: |
317 if venvInterpreter: |
469 self.tr("{0} - {1}").format( |
467 self.tr("{0} - {1}").format( |
470 venvName, self.__virtualEnvironments[venvName]["path"] |
468 venvName, self.__virtualEnvironments[venvName]["path"] |
471 ) |
469 ) |
472 ) |
470 ) |
473 if venvMessages: |
471 if venvMessages: |
474 from eric7.UI.DeleteFilesConfirmationDialog import ( |
|
475 DeleteFilesConfirmationDialog, |
|
476 ) |
|
477 |
|
478 dlg = DeleteFilesConfirmationDialog( |
472 dlg = DeleteFilesConfirmationDialog( |
479 None, |
473 None, |
480 self.tr("Delete Virtual Environments"), |
474 self.tr("Delete Virtual Environments"), |
481 self.tr( |
475 self.tr( |
482 """Do you really want to delete these virtual""" |
476 """Do you really want to delete these virtual""" |
538 self.tr("{0} - {1}").format( |
532 self.tr("{0} - {1}").format( |
539 venvName, self.__virtualEnvironments[venvName]["path"] |
533 venvName, self.__virtualEnvironments[venvName]["path"] |
540 ) |
534 ) |
541 ) |
535 ) |
542 if venvMessages: |
536 if venvMessages: |
543 from eric7.UI.DeleteFilesConfirmationDialog import ( |
|
544 DeleteFilesConfirmationDialog, |
|
545 ) |
|
546 |
|
547 dlg = DeleteFilesConfirmationDialog( |
537 dlg = DeleteFilesConfirmationDialog( |
548 None, |
538 None, |
549 self.tr("Remove Virtual Environments"), |
539 self.tr("Remove Virtual Environments"), |
550 self.tr( |
540 self.tr( |
551 """Do you really want to remove these virtual""" |
541 """Do you really want to remove these virtual""" |
580 Public slot to show the virtual environment manager dialog. |
570 Public slot to show the virtual environment manager dialog. |
581 |
571 |
582 @param modal flag indicating that the dialog should be shown in |
572 @param modal flag indicating that the dialog should be shown in |
583 a blocking mode |
573 a blocking mode |
584 """ |
574 """ |
|
575 from .VirtualenvManagerWidgets import VirtualenvManagerDialog |
|
576 |
585 if modal: |
577 if modal: |
586 from .VirtualenvManagerWidgets import VirtualenvManagerDialog |
|
587 |
|
588 virtualenvManagerDialog = VirtualenvManagerDialog(self, self.__ui) |
578 virtualenvManagerDialog = VirtualenvManagerDialog(self, self.__ui) |
589 virtualenvManagerDialog.exec() |
579 virtualenvManagerDialog.exec() |
590 self.virtualEnvironmentsListChanged.emit() |
580 self.virtualEnvironmentsListChanged.emit() |
591 else: |
581 else: |
592 self.__ui.activateVirtualenvManager() |
582 self.__ui.activateVirtualenvManager() |