VirtualEnv/VirtualenvConfigurationDialog.py

branch
maintenance
changeset 6826
c6dda2cbe081
parent 6739
110ab101766a
equal deleted inserted replaced
6764:d14ddbfbbd36 6826:c6dda2cbe081
25 25
26 from .Ui_VirtualenvConfigurationDialog import Ui_VirtualenvConfigurationDialog 26 from .Ui_VirtualenvConfigurationDialog import Ui_VirtualenvConfigurationDialog
27 27
28 import Preferences 28 import Preferences
29 import Utilities 29 import Utilities
30
31 import CondaInterface
30 32
31 33
32 class VirtualenvConfigurationDialog(QDialog, Ui_VirtualenvConfigurationDialog): 34 class VirtualenvConfigurationDialog(QDialog, Ui_VirtualenvConfigurationDialog):
33 """ 35 """
34 Class implementing a dialog to enter the parameters for the 36 Class implementing a dialog to enter the parameters for the
58 self.pythonExecPicker.setWindowTitle( 60 self.pythonExecPicker.setWindowTitle(
59 self.tr("Python Interpreter")) 61 self.tr("Python Interpreter"))
60 self.pythonExecPicker.setDefaultDirectory( 62 self.pythonExecPicker.setDefaultDirectory(
61 sys.executable.replace("w.exe", ".exe")) 63 sys.executable.replace("w.exe", ".exe"))
62 64
65 self.condaTargetDirectoryPicker.setMode(
66 E5PathPickerModes.DirectoryMode)
67 self.condaTargetDirectoryPicker.setWindowTitle(
68 self.tr("Conda Environment Location"))
69 self.condaTargetDirectoryPicker.setDefaultDirectory(
70 Utilities.getHomeDir())
71
72 self.condaCloneDirectoryPicker.setMode(
73 E5PathPickerModes.DirectoryMode)
74 self.condaCloneDirectoryPicker.setWindowTitle(
75 self.tr("Conda Environment Location"))
76 self.condaCloneDirectoryPicker.setDefaultDirectory(
77 Utilities.getHomeDir())
78
79 self.condaRequirementsFilePicker.setMode(
80 E5PathPickerModes.OpenFileMode)
81 self.condaRequirementsFilePicker.setWindowTitle(
82 self.tr("Conda Requirements File"))
83 self.condaRequirementsFilePicker.setDefaultDirectory(
84 Utilities.getHomeDir())
85 self.condaRequirementsFilePicker.setFilters(
86 self.tr("Text Files (*.txt);;All Files (*)"))
87
63 self.__versionRe = re.compile(r""".*?(\d+\.\d+\.\d+).*""") 88 self.__versionRe = re.compile(r""".*?(\d+\.\d+\.\d+).*""")
64 89
65 self.__virtualenvFound = False 90 self.__virtualenvFound = False
66 self.__pyvenvFound = False 91 self.__pyvenvFound = False
92 self.__condaFound = False
67 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) 93 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
68 94
69 self.__mandatoryStyleSheet = "QLineEdit {border: 2px solid;}" 95 self.__mandatoryStyleSheet = "QLineEdit {border: 2px solid;}"
70 self.targetDirectoryPicker.setStyleSheet(self.__mandatoryStyleSheet) 96 self.targetDirectoryPicker.setStyleSheet(self.__mandatoryStyleSheet)
71 self.nameEdit.setStyleSheet(self.__mandatoryStyleSheet) 97 self.nameEdit.setStyleSheet(self.__mandatoryStyleSheet)
98 self.condaTargetDirectoryPicker.setStyleSheet(
99 self.__mandatoryStyleSheet)
100 self.condaNameEdit.setStyleSheet(self.__mandatoryStyleSheet)
72 101
73 self.__setVirtualenvVersion() 102 self.__setVirtualenvVersion()
74 self.__setPyvenvVersion() 103 self.__setPyvenvVersion()
75 if self.__virtualenvFound: 104 self.__setCondaVersion()
105 if self.__pyvenvFound:
106 self.pyvenvButton.setChecked(True)
107 elif self.__virtualenvFound:
76 self.virtualenvButton.setChecked(True) 108 self.virtualenvButton.setChecked(True)
77 elif self.__pyvenvFound: 109 elif self.__condaFound:
78 self.pyvenvButton.setChecked(True) 110 self.condaButton.setChecked(True)
111
112 self.condaInsecureCheckBox.setEnabled(
113 CondaInterface.condaVersion() >= (4, 3, 18))
79 114
80 msh = self.minimumSizeHint() 115 msh = self.minimumSizeHint()
81 self.resize(max(self.width(), msh.width()), msh.height()) 116 self.resize(max(self.width(), msh.width()), msh.height())
82 117
83 def __updateOK(self): 118 def __updateOK(self):
84 """ 119 """
85 Private method to update the enabled status of the OK button. 120 Private method to update the enabled status of the OK button.
86 """ 121 """
87 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( 122 if self.virtualenvButton.isChecked() or self.pyvenvButton.isChecked():
88 (self.__virtualenvFound or self.__pyvenvFound) and 123 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
89 bool(self.targetDirectoryPicker.text()) and 124 (self.__virtualenvFound or self.__pyvenvFound) and
90 bool(self.nameEdit.text()) 125 bool(self.targetDirectoryPicker.text()) and
91 ) 126 bool(self.nameEdit.text())
127 )
128 elif self.condaButton.isChecked():
129 enable = bool(self.condaNameEdit.text()) or \
130 bool(self.condaTargetDirectoryPicker.text())
131 if self.condaSpecialsGroup.isChecked():
132 if self.condaCloneButton.isChecked():
133 enable &= bool(self.condaCloneNameEdit.text()) or \
134 bool(self.condaCloneDirectoryPicker.text())
135 elif self.condaRequirementsButton.isChecked():
136 enable &= bool(self.condaRequirementsFilePicker.text())
137 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
138 else:
139 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
92 140
93 def __updateUi(self): 141 def __updateUi(self):
94 """ 142 """
95 Private method to update the UI depending on the selected 143 Private method to update the UI depending on the selected
96 virtual environment creator (virtualenv or pyvenv). 144 virtual environment creator (virtualenv or pyvenv).
97 """ 145 """
146 # venv page
98 enable = self.virtualenvButton.isChecked() 147 enable = self.virtualenvButton.isChecked()
99 self.extraSearchPathLabel.setEnabled(enable) 148 self.extraSearchPathLabel.setEnabled(enable)
100 self.extraSearchPathPicker.setEnabled(enable) 149 self.extraSearchPathPicker.setEnabled(enable)
101 self.promptPrefixLabel.setEnabled(enable) 150 self.promptPrefixLabel.setEnabled(enable)
102 self.promptPrefixEdit.setEnabled(enable) 151 self.promptPrefixEdit.setEnabled(enable)
106 self.versionComboBox.setEnabled(enable) 155 self.versionComboBox.setEnabled(enable)
107 self.unzipCheckBox.setEnabled(enable) 156 self.unzipCheckBox.setEnabled(enable)
108 self.noSetuptoolsCheckBox.setEnabled(enable) 157 self.noSetuptoolsCheckBox.setEnabled(enable)
109 self.symlinkCheckBox.setEnabled(not enable) 158 self.symlinkCheckBox.setEnabled(not enable)
110 self.upgradeCheckBox.setEnabled(not enable) 159 self.upgradeCheckBox.setEnabled(not enable)
160
161 # conda page
162 enable = not self.condaSpecialsGroup.isChecked()
163 self.condaPackagesEdit.setEnabled(enable)
164 self.condaPythonEdit.setEnabled(enable)
165 self.condaInsecureCheckBox.setEnabled(
166 enable and CondaInterface.condaVersion() >= (4, 3, 18))
167 self.condaDryrunCheckBox.setEnabled(enable)
168
169 # select page
170 if self.condaButton.isChecked():
171 self.venvStack.setCurrentWidget(self.condaPage)
172 else:
173 self.venvStack.setCurrentWidget(self.venvPage)
111 174
112 @pyqtSlot(str) 175 @pyqtSlot(str)
113 def on_targetDirectoryPicker_textChanged(self, txt): 176 def on_targetDirectoryPicker_textChanged(self, txt):
114 """ 177 """
115 Private slot handling a change of the target directory. 178 Private slot handling a change of the target directory.
148 211
149 @param checked state of the checkbox 212 @param checked state of the checkbox
150 @type bool 213 @type bool
151 """ 214 """
152 self.__updateUi() 215 self.__updateUi()
216
217 @pyqtSlot(bool)
218 def on_condaButton_toggled(self, checked):
219 """
220 Private slot to react to the selection of 'conda'.
221
222 @param checked state of the checkbox
223 @type bool
224 """
225 self.__updateUi()
226
227 @pyqtSlot(str)
228 def on_condaNameEdit_textChanged(self, txt):
229 """
230 Private slot handling a change of the conda environment name.
231
232 @param txt environment name
233 @type str
234 """
235 self.__updateOK()
236
237 @pyqtSlot(str)
238 def on_condaTargetDirectoryPicker_textChanged(self, txt):
239 """
240 Private slot handling a change of the conda target directory.
241
242 @param txt target directory
243 @type str
244 """
245 self.__updateOK()
246
247 @pyqtSlot()
248 def on_condaSpecialsGroup_clicked(self):
249 """
250 Private slot handling the selection of the specials group.
251 """
252 self.__updateOK()
253 self.__updateUi()
254
255 @pyqtSlot(str)
256 def on_condaCloneNameEdit_textChanged(self, txt):
257 """
258 Private slot handling a change of the conda source environment name.
259
260 @param txt name of the environment to be cloned
261 @type str
262 """
263 self.__updateOK()
264
265 @pyqtSlot(str)
266 def on_condaCloneDirectoryPicker_textChanged(self, txt):
267 """
268 Private slot handling a change of the cloned from directory.
269
270 @param txt target directory
271 @type str
272 """
273 self.__updateOK()
274
275 @pyqtSlot()
276 def on_condaCloneButton_clicked(self):
277 """
278 Private slot handling the selection of the clone button.
279 """
280 self.__updateOK()
281
282 @pyqtSlot()
283 def on_condaRequirementsButton_clicked(self):
284 """
285 Private slot handling the selection of the requirements button.
286 """
287 self.__updateOK()
288
289 @pyqtSlot(str)
290 def on_condaRequirementsFilePicker_textChanged(self, txt):
291 """
292 Private slot handling a change of the requirements file entry.
293
294 @param txt current text of the requirements file entry
295 @type str
296 """
297 self.__updateOK()
153 298
154 def __setVirtualenvVersion(self): 299 def __setVirtualenvVersion(self):
155 """ 300 """
156 Private method to determine the virtualenv version and set the 301 Private method to determine the virtualenv version and set the
157 respective label. 302 respective label.
257 "pyvenv Version: {0}".format(version))) 402 "pyvenv Version: {0}".format(version)))
258 self.pyvenvButton.setEnabled(self.__pyvenvFound) 403 self.pyvenvButton.setEnabled(self.__pyvenvFound)
259 if not self.__pyvenvFound: 404 if not self.__pyvenvFound:
260 self.pyvenvButton.setChecked(False) 405 self.pyvenvButton.setChecked(False)
261 406
407 def __setCondaVersion(self):
408 """
409 Private method to determine the conda version and set the respective
410 label.
411 """
412 self.__condaFound = bool(CondaInterface.condaVersion())
413 self.condaButton.setText(self.tr(
414 "conda Version: {0}".format(CondaInterface.condaVersionStr())))
415 self.condaButton.setEnabled(self.__condaFound)
416 if not self.__condaFound:
417 self.condaButton.setChecked(False)
418
262 def __generateTargetDir(self): 419 def __generateTargetDir(self):
263 """ 420 """
264 Private method to generate a valid target directory path. 421 Private method to generate a valid target directory path.
265 422
266 @return target directory path 423 @return target directory path
279 436
280 @return process arguments 437 @return process arguments
281 @rtype list of str 438 @rtype list of str
282 """ 439 """
283 args = [] 440 args = []
284 if self.virtualenvButton.isChecked(): 441 if self.condaButton.isChecked():
285 if self.extraSearchPathPicker.text(): 442 if bool(self.condaNameEdit.text()):
286 args.append("--extra-search-dir={0}".format( 443 args.extend(["--name", self.condaNameEdit.text()])
287 Utilities.toNativeSeparators( 444 if bool(self.condaTargetDirectoryPicker.text()):
288 self.extraSearchPathPicker.text()))) 445 args.extend(["--prefix",
289 if self.promptPrefixEdit.text(): 446 self.condaTargetDirectoryPicker.text()])
290 args.append("--prompt={0}".format( 447 if self.condaSpecialsGroup.isChecked():
291 self.promptPrefixEdit.text().replace(" ", "_"))) 448 if self.condaCloneButton.isChecked():
292 if self.pythonExecPicker.text(): 449 if bool(self.condaCloneNameEdit.text()):
293 args.append("--python={0}".format( 450 args.extend(
294 Utilities.toNativeSeparators( 451 ["--clone", self.condaCloneNameEdit.text()]
295 self.pythonExecPicker.text()))) 452 )
296 elif self.versionComboBox.currentText(): 453 elif bool(self.condaCloneDirectoryPicker.text()):
297 args.append("--python=python{0}".format( 454 args.extend(["--clone",
298 self.versionComboBox.currentText())) 455 self.condaCloneDirectoryPicker.text()])
299 if self.verbositySpinBox.value() == 1: 456 elif self.condaRequirementsButton.isChecked():
300 args.append("--verbose") 457 args.extend(
301 elif self.verbositySpinBox.value() == -1: 458 ["--file", self.condaRequirementsFilePicker.text()]
302 args.append("--quiet") 459 )
303 if self.clearCheckBox.isChecked(): 460 if self.condaInsecureCheckBox.isChecked():
304 args.append("--clear") 461 args.append("--insecure")
305 if self.systemCheckBox.isChecked(): 462 if self.condaDryrunCheckBox.isChecked():
306 args.append("--system-site-packages") 463 args.append("--dry-run")
307 if self.unzipCheckBox.isChecked(): 464 if not self.condaSpecialsGroup.isChecked():
308 args.append("--unzip-setuptools") 465 if bool(self.condaPythonEdit.text()):
309 if self.noSetuptoolsCheckBox.isChecked(): 466 args.append("python={0}".format(
310 args.append("--no-setuptools") 467 self.condaPythonEdit.text()))
311 if self.noPipCcheckBox.isChecked(): 468 if bool(self.condaPackagesEdit.text()):
312 args.append("--no-pip") 469 args.extend(self.condaPackagesEdit.text().split())
313 if self.copyCheckBox.isChecked(): 470 else:
314 args.append("--always-copy") 471 if self.virtualenvButton.isChecked():
315 elif self.pyvenvButton.isChecked(): 472 if self.extraSearchPathPicker.text():
316 if self.clearCheckBox.isChecked(): 473 args.append("--extra-search-dir={0}".format(
317 args.append("--clear") 474 Utilities.toNativeSeparators(
318 if self.systemCheckBox.isChecked(): 475 self.extraSearchPathPicker.text())))
319 args.append("--system-site-packages") 476 if self.promptPrefixEdit.text():
320 if self.noPipCcheckBox.isChecked(): 477 args.append("--prompt={0}".format(
321 args.append("--without-pip") 478 self.promptPrefixEdit.text().replace(" ", "_")))
322 if self.copyCheckBox.isChecked(): 479 if self.pythonExecPicker.text():
323 args.append("--copies") 480 args.append("--python={0}".format(
324 if self.symlinkCheckBox.isChecked(): 481 Utilities.toNativeSeparators(
325 args.append("--symlinks") 482 self.pythonExecPicker.text())))
326 if self.upgradeCheckBox.isChecked(): 483 elif self.versionComboBox.currentText():
327 args.append("--upgrade") 484 args.append("--python=python{0}".format(
328 targetDirectory = self.__generateTargetDir() 485 self.versionComboBox.currentText()))
329 args.append(targetDirectory) 486 if self.verbositySpinBox.value() == 1:
487 args.append("--verbose")
488 elif self.verbositySpinBox.value() == -1:
489 args.append("--quiet")
490 if self.clearCheckBox.isChecked():
491 args.append("--clear")
492 if self.systemCheckBox.isChecked():
493 args.append("--system-site-packages")
494 if self.unzipCheckBox.isChecked():
495 args.append("--unzip-setuptools")
496 if self.noSetuptoolsCheckBox.isChecked():
497 args.append("--no-setuptools")
498 if self.noPipCcheckBox.isChecked():
499 args.append("--no-pip")
500 if self.copyCheckBox.isChecked():
501 args.append("--always-copy")
502 elif self.pyvenvButton.isChecked():
503 if self.clearCheckBox.isChecked():
504 args.append("--clear")
505 if self.systemCheckBox.isChecked():
506 args.append("--system-site-packages")
507 if self.noPipCcheckBox.isChecked():
508 args.append("--without-pip")
509 if self.copyCheckBox.isChecked():
510 args.append("--copies")
511 if self.symlinkCheckBox.isChecked():
512 args.append("--symlinks")
513 if self.upgradeCheckBox.isChecked():
514 args.append("--upgrade")
515 targetDirectory = self.__generateTargetDir()
516 args.append(targetDirectory)
517
330 return args 518 return args
331 519
332 def getData(self): 520 def getData(self):
333 """ 521 """
334 Public method to retrieve the dialog data. 522 Public method to retrieve the dialog data.
335 523
336 @return tuple containing a flag indicating the pyvenv selection, the 524 @return dictionary containing the data for the two environment
337 process arguments, a name for the virtual environment, a flag 525 variants. The keys for both variants are 'arguments' containing the
338 indicating to open the target directory after creation, a flag 526 command line arguments, 'logicalName' containing the environment
339 indicating to write a log file, a flag indicating to write a 527 name to be used with the virtual env manager and 'envType'
340 script, the name of the target directory and the name of the 528 containing the environment type (virtualenv, pyvenv or conda). The
341 Python interpreter to use 529 virtualenv/pyvenv specific keys are 'openTarget' containg a flag to
342 @rtype tuple of (bool, list of str, str, bool, bool, bool, str, str) 530 open the target directory after creation, 'createLog' containing a
531 flag to write a log file, 'createScript' containing a flag to write
532 a script, 'targetDirectory' containing the target directory and
533 'pythonExe' containing the Python interpreter to be used. The
534 conda specific key is 'command' giving the conda command to be
535 executed (always 'create').
536 @rtype dict
343 """ 537 """
344 args = self.__generateArguments() 538 args = self.__generateArguments()
345 targetDirectory = self.__generateTargetDir() 539 resultDict = {
346 return ( 540 "arguments": args,
347 self.pyvenvButton.isChecked(), 541 "logicalName": self.nameEdit.text(),
348 args, 542 }
349 self.nameEdit.text(), 543 if self.condaButton.isChecked():
350 self.openCheckBox.isChecked(), 544 resultDict.update({
351 self.logCheckBox.isChecked(), 545 "envType": "conda",
352 self.scriptCheckBox.isChecked(), 546 "command": "create",
353 targetDirectory, 547 })
354 Utilities.toNativeSeparators(self.pythonExecPicker.text()), 548 else:
355 ) 549 resultDict.update({
550 "envType": ("pyvenv" if self.pyvenvButton.isChecked() else
551 "virtualenv"),
552 "openTarget": self.openCheckBox.isChecked(),
553 "createLog": self.logCheckBox.isChecked(),
554 "createScript": self.scriptCheckBox.isChecked(),
555 "targetDirectory": self.__generateTargetDir(),
556 "pythonExe": Utilities.toNativeSeparators(
557 self.pythonExecPicker.text()),
558 })
559
560 return resultDict

eric ide

mercurial