58 self.pythonExecPicker.setWindowTitle( |
58 self.pythonExecPicker.setWindowTitle( |
59 self.tr("Python Interpreter")) |
59 self.tr("Python Interpreter")) |
60 self.pythonExecPicker.setDefaultDirectory( |
60 self.pythonExecPicker.setDefaultDirectory( |
61 sys.executable.replace("w.exe", ".exe")) |
61 sys.executable.replace("w.exe", ".exe")) |
62 |
62 |
|
63 self.condaTargetDirectoryPicker.setMode( |
|
64 E5PathPickerModes.DirectoryMode) |
|
65 self.condaTargetDirectoryPicker.setWindowTitle( |
|
66 self.tr("Conda Environment Location")) |
|
67 self.condaTargetDirectoryPicker.setDefaultDirectory( |
|
68 Utilities.getHomeDir()) |
|
69 |
|
70 self.condaCloneDirectoryPicker.setMode( |
|
71 E5PathPickerModes.DirectoryMode) |
|
72 self.condaCloneDirectoryPicker.setWindowTitle( |
|
73 self.tr("Conda Environment Location")) |
|
74 self.condaCloneDirectoryPicker.setDefaultDirectory( |
|
75 Utilities.getHomeDir()) |
|
76 |
63 self.__versionRe = re.compile(r""".*?(\d+\.\d+\.\d+).*""") |
77 self.__versionRe = re.compile(r""".*?(\d+\.\d+\.\d+).*""") |
64 |
78 |
65 self.__virtualenvFound = False |
79 self.__virtualenvFound = False |
66 self.__pyvenvFound = False |
80 self.__pyvenvFound = False |
|
81 self.__condaFound = False |
67 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
82 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
68 |
83 |
69 self.__mandatoryStyleSheet = "QLineEdit {border: 2px solid;}" |
84 self.__mandatoryStyleSheet = "QLineEdit {border: 2px solid;}" |
70 self.targetDirectoryPicker.setStyleSheet(self.__mandatoryStyleSheet) |
85 self.targetDirectoryPicker.setStyleSheet(self.__mandatoryStyleSheet) |
71 self.nameEdit.setStyleSheet(self.__mandatoryStyleSheet) |
86 self.nameEdit.setStyleSheet(self.__mandatoryStyleSheet) |
|
87 self.condaTargetDirectoryPicker.setStyleSheet( |
|
88 self.__mandatoryStyleSheet) |
|
89 self.condaNameEdit.setStyleSheet(self.__mandatoryStyleSheet) |
72 |
90 |
73 self.__setVirtualenvVersion() |
91 self.__setVirtualenvVersion() |
74 self.__setPyvenvVersion() |
92 self.__setPyvenvVersion() |
75 if self.__virtualenvFound: |
93 self.__setCondaVersion() |
|
94 if self.__pyvenvFound: |
|
95 self.pyvenvButton.setChecked(True) |
|
96 elif self.__virtualenvFound: |
76 self.virtualenvButton.setChecked(True) |
97 self.virtualenvButton.setChecked(True) |
77 elif self.__pyvenvFound: |
98 elif self.__condaFound: |
78 self.pyvenvButton.setChecked(True) |
99 self.condaButton.setChecked(True) |
79 |
100 |
80 msh = self.minimumSizeHint() |
101 msh = self.minimumSizeHint() |
81 self.resize(max(self.width(), msh.width()), msh.height()) |
102 self.resize(max(self.width(), msh.width()), msh.height()) |
82 |
103 |
83 def __updateOK(self): |
104 def __updateOK(self): |
84 """ |
105 """ |
85 Private method to update the enabled status of the OK button. |
106 Private method to update the enabled status of the OK button. |
86 """ |
107 """ |
87 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
108 if self.virtualenvButton.isChecked() or self.pyvenvButton.isChecked(): |
88 (self.__virtualenvFound or self.__pyvenvFound) and |
109 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
89 bool(self.targetDirectoryPicker.text()) and |
110 (self.__virtualenvFound or self.__pyvenvFound) and |
90 bool(self.nameEdit.text()) |
111 bool(self.targetDirectoryPicker.text()) and |
91 ) |
112 bool(self.nameEdit.text()) |
|
113 ) |
|
114 elif self.condaButton.isChecked(): |
|
115 enable = bool(self.condaNameEdit.text()) or \ |
|
116 bool(self.condaTargetDirectoryPicker.text()) |
|
117 if self.condaCloneGroup.isChecked(): |
|
118 enable &= bool(self.condaCloneNameEdit.text()) or \ |
|
119 bool(self.condaCloneDirectoryPicker.text()) |
|
120 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
121 else: |
|
122 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
92 |
123 |
93 def __updateUi(self): |
124 def __updateUi(self): |
94 """ |
125 """ |
95 Private method to update the UI depending on the selected |
126 Private method to update the UI depending on the selected |
96 virtual environment creator (virtualenv or pyvenv). |
127 virtual environment creator (virtualenv or pyvenv). |
97 """ |
128 """ |
|
129 # venv page |
98 enable = self.virtualenvButton.isChecked() |
130 enable = self.virtualenvButton.isChecked() |
99 self.extraSearchPathLabel.setEnabled(enable) |
131 self.extraSearchPathLabel.setEnabled(enable) |
100 self.extraSearchPathPicker.setEnabled(enable) |
132 self.extraSearchPathPicker.setEnabled(enable) |
101 self.promptPrefixLabel.setEnabled(enable) |
133 self.promptPrefixLabel.setEnabled(enable) |
102 self.promptPrefixEdit.setEnabled(enable) |
134 self.promptPrefixEdit.setEnabled(enable) |
257 "pyvenv Version: {0}".format(version))) |
360 "pyvenv Version: {0}".format(version))) |
258 self.pyvenvButton.setEnabled(self.__pyvenvFound) |
361 self.pyvenvButton.setEnabled(self.__pyvenvFound) |
259 if not self.__pyvenvFound: |
362 if not self.__pyvenvFound: |
260 self.pyvenvButton.setChecked(False) |
363 self.pyvenvButton.setChecked(False) |
261 |
364 |
|
365 def __setCondaVersion(self): |
|
366 """ |
|
367 Private method to determine the conda version and set the respective |
|
368 label. |
|
369 """ |
|
370 exe = Preferences.getConda("CondaExecutable") |
|
371 if not exe: |
|
372 exe = "conda" |
|
373 |
|
374 proc = QProcess() |
|
375 proc.start(exe, ["--version"]) |
|
376 if not proc.waitForStarted(5000): |
|
377 self.__condaFound = False |
|
378 version = self.tr('<conda not found or not configured.>') |
|
379 else: |
|
380 proc.waitForFinished(5000) |
|
381 output = str(proc.readAllStandardOutput(), |
|
382 Preferences.getSystem("IOEncoding"), |
|
383 'replace').strip() |
|
384 match = re.match(self.__versionRe, output) |
|
385 if match: |
|
386 self.__condaFound = True |
|
387 version = match.group(1) |
|
388 else: |
|
389 self.__condaFound = False |
|
390 version = self.tr('<conda returned strange version info.') |
|
391 self.condaButton.setText(self.tr( |
|
392 "conda Version: {0}".format(version))) |
|
393 self.condaButton.setEnabled(self.__condaFound) |
|
394 if not self.__condaFound: |
|
395 self.condaButton.setChecked(False) |
|
396 |
262 def __generateTargetDir(self): |
397 def __generateTargetDir(self): |
263 """ |
398 """ |
264 Private method to generate a valid target directory path. |
399 Private method to generate a valid target directory path. |
265 |
400 |
266 @return target directory path |
401 @return target directory path |
279 |
414 |
280 @return process arguments |
415 @return process arguments |
281 @rtype list of str |
416 @rtype list of str |
282 """ |
417 """ |
283 args = [] |
418 args = [] |
284 if self.virtualenvButton.isChecked(): |
419 if self.condaButton.isChecked(): |
285 if self.extraSearchPathPicker.text(): |
420 # TODO: assemble the conda arguments |
286 args.append("--extra-search-dir={0}".format( |
421 pass |
287 Utilities.toNativeSeparators( |
422 else: |
288 self.extraSearchPathPicker.text()))) |
423 if self.virtualenvButton.isChecked(): |
289 if self.promptPrefixEdit.text(): |
424 if self.extraSearchPathPicker.text(): |
290 args.append("--prompt={0}".format( |
425 args.append("--extra-search-dir={0}".format( |
291 self.promptPrefixEdit.text().replace(" ", "_"))) |
426 Utilities.toNativeSeparators( |
292 if self.pythonExecPicker.text(): |
427 self.extraSearchPathPicker.text()))) |
293 args.append("--python={0}".format( |
428 if self.promptPrefixEdit.text(): |
294 Utilities.toNativeSeparators( |
429 args.append("--prompt={0}".format( |
295 self.pythonExecPicker.text()))) |
430 self.promptPrefixEdit.text().replace(" ", "_"))) |
296 elif self.versionComboBox.currentText(): |
431 if self.pythonExecPicker.text(): |
297 args.append("--python=python{0}".format( |
432 args.append("--python={0}".format( |
298 self.versionComboBox.currentText())) |
433 Utilities.toNativeSeparators( |
299 if self.verbositySpinBox.value() == 1: |
434 self.pythonExecPicker.text()))) |
300 args.append("--verbose") |
435 elif self.versionComboBox.currentText(): |
301 elif self.verbositySpinBox.value() == -1: |
436 args.append("--python=python{0}".format( |
302 args.append("--quiet") |
437 self.versionComboBox.currentText())) |
303 if self.clearCheckBox.isChecked(): |
438 if self.verbositySpinBox.value() == 1: |
304 args.append("--clear") |
439 args.append("--verbose") |
305 if self.systemCheckBox.isChecked(): |
440 elif self.verbositySpinBox.value() == -1: |
306 args.append("--system-site-packages") |
441 args.append("--quiet") |
307 if self.unzipCheckBox.isChecked(): |
442 if self.clearCheckBox.isChecked(): |
308 args.append("--unzip-setuptools") |
443 args.append("--clear") |
309 if self.noSetuptoolsCheckBox.isChecked(): |
444 if self.systemCheckBox.isChecked(): |
310 args.append("--no-setuptools") |
445 args.append("--system-site-packages") |
311 if self.noPipCcheckBox.isChecked(): |
446 if self.unzipCheckBox.isChecked(): |
312 args.append("--no-pip") |
447 args.append("--unzip-setuptools") |
313 if self.copyCheckBox.isChecked(): |
448 if self.noSetuptoolsCheckBox.isChecked(): |
314 args.append("--always-copy") |
449 args.append("--no-setuptools") |
315 elif self.pyvenvButton.isChecked(): |
450 if self.noPipCcheckBox.isChecked(): |
316 if self.clearCheckBox.isChecked(): |
451 args.append("--no-pip") |
317 args.append("--clear") |
452 if self.copyCheckBox.isChecked(): |
318 if self.systemCheckBox.isChecked(): |
453 args.append("--always-copy") |
319 args.append("--system-site-packages") |
454 elif self.pyvenvButton.isChecked(): |
320 if self.noPipCcheckBox.isChecked(): |
455 if self.clearCheckBox.isChecked(): |
321 args.append("--without-pip") |
456 args.append("--clear") |
322 if self.copyCheckBox.isChecked(): |
457 if self.systemCheckBox.isChecked(): |
323 args.append("--copies") |
458 args.append("--system-site-packages") |
324 if self.symlinkCheckBox.isChecked(): |
459 if self.noPipCcheckBox.isChecked(): |
325 args.append("--symlinks") |
460 args.append("--without-pip") |
326 if self.upgradeCheckBox.isChecked(): |
461 if self.copyCheckBox.isChecked(): |
327 args.append("--upgrade") |
462 args.append("--copies") |
328 targetDirectory = self.__generateTargetDir() |
463 if self.symlinkCheckBox.isChecked(): |
329 args.append(targetDirectory) |
464 args.append("--symlinks") |
|
465 if self.upgradeCheckBox.isChecked(): |
|
466 args.append("--upgrade") |
|
467 targetDirectory = self.__generateTargetDir() |
|
468 args.append(targetDirectory) |
|
469 |
330 return args |
470 return args |
331 |
471 |
332 def getData(self): |
472 def getData(self): |
333 """ |
473 """ |
334 Public method to retrieve the dialog data. |
474 Public method to retrieve the dialog data. |
335 |
475 |
336 @return tuple containing a flag indicating the pyvenv selection, the |
476 @return dictionary containing the data for the two environment |
337 process arguments, a name for the virtual environment, a flag |
477 variants. The keys for both variants are 'arguments' containing the |
338 indicating to open the target directory after creation, a flag |
478 command line arguments, 'logicalName' containing the environment |
339 indicating to write a log file, a flag indicating to write a |
479 name to be used with the virtual env manager and 'envType' |
340 script, the name of the target directory and the name of the |
480 containing the environment type (virtualenv, pyvenv or conda). The |
341 Python interpreter to use |
481 virtualenv/pyvenv specific keys are 'openTarget' containg a flag to |
342 @rtype tuple of (bool, list of str, str, bool, bool, bool, str, str) |
482 open the target directory after creation, 'createLog' containing a |
343 """ |
483 flag to write a log file, 'createScript' containing a flag to write |
|
484 a script, 'targetDirectory' containing the target directory and |
|
485 'pythonExe' containing the Python interpreter to be used. The conda |
|
486 specific keys are |
|
487 @rtype dict |
|
488 """ |
|
489 # TODO: add the conda keys to the above description |
|
490 # TODO: change to returning a method specific dictionary |
344 args = self.__generateArguments() |
491 args = self.__generateArguments() |
345 targetDirectory = self.__generateTargetDir() |
492 resultDict = { |
346 return ( |
493 "arguments": args, |
347 self.pyvenvButton.isChecked(), |
494 "logicalName": self.nameEdit.text(), |
348 args, |
495 } |
349 self.nameEdit.text(), |
496 if self.condaButton.isChecked(): |
350 self.openCheckBox.isChecked(), |
497 resultDict.update({ |
351 self.logCheckBox.isChecked(), |
498 "envType": "conda", |
352 self.scriptCheckBox.isChecked(), |
499 }) |
353 targetDirectory, |
500 else: |
354 Utilities.toNativeSeparators(self.pythonExecPicker.text()), |
501 resultDict.update({ |
355 ) |
502 "envType": ("pyvenv" if self.pyvenvButton.isChecked() else |
|
503 "virtualenv"), |
|
504 "openTarget": self.openCheckBox.isChecked(), |
|
505 "createLog": self.logCheckBox.isChecked(), |
|
506 "createScript":self.scriptCheckBox.isChecked(), |
|
507 "targetDirectory": self.__generateTargetDir(), |
|
508 "pythonExe": Utilities.toNativeSeparators( |
|
509 self.pythonExecPicker.text()), |
|
510 }) |
|
511 |
|
512 return resultDict |