Plugins/UiExtensionPlugins/PipInterface/PipListDialog.py

changeset 6342
c79ecba9cde7
parent 6327
a1716d9210f4
child 6396
f6d4ab496cfe
equal deleted inserted replaced
6341:a00e63f6d766 6342:c79ecba9cde7
39 ShowProcessGeneralMode = 0 39 ShowProcessGeneralMode = 0
40 ShowProcessClassifiersMode = 1 40 ShowProcessClassifiersMode = 1
41 ShowProcessEntryPointsMode = 2 41 ShowProcessEntryPointsMode = 2
42 ShowProcessFilesListMode = 3 42 ShowProcessFilesListMode = 3
43 43
44 def __init__(self, pip, mode, plugin, title, parent=None): 44 def __init__(self, pip, mode, indexUrl, title, parent=None):
45 """ 45 """
46 Constructor 46 Constructor
47 47
48 @param pip reference to the master object (Pip) 48 @param pip reference to the master object
49 @param mode list command mode (string; one of 'list', 49 @type Pip
50 'uptodate', 'outdated') 50 @param mode list command mode (one of 'list', 'uptodate', 'outdated')
51 @param plugin reference to the plugin object (ToolPipPlugin) 51 @type str
52 @param title title of the dialog (string) 52 @param indexUrl URL of the pypi index
53 @param parent reference to the parent widget (QWidget) 53 @type str
54 @param title title of the dialog
55 @type str
56 @param parent reference to the parent widget
57 @type QWidget
54 """ 58 """
55 assert mode in PipListDialog.CommandArguments 59 assert mode in PipListDialog.CommandArguments
56 60
57 super(PipListDialog, self).__init__(parent) 61 super(PipListDialog, self).__init__(parent)
58 self.setupUi(self) 62 self.setupUi(self)
77 self.tr("&Uninstall"), QDialogButtonBox.ActionRole) 81 self.tr("&Uninstall"), QDialogButtonBox.ActionRole)
78 self.__uninstallButton.setEnabled(False) 82 self.__uninstallButton.setEnabled(False)
79 83
80 self.__pip = pip 84 self.__pip = pip
81 self.__mode = mode 85 self.__mode = mode
82 self.__defaultCommand = plugin.getPreferences("CurrentPipExecutable")
83 self.__ioEncoding = Preferences.getSystem("IOEncoding") 86 self.__ioEncoding = Preferences.getSystem("IOEncoding")
84 self.__indexUrl = plugin.getPreferences("PipSearchIndex") 87 self.__indexUrl = indexUrl
85 self.__errors = "" 88 self.__errors = ""
86 self.__output = [] 89 self.__output = []
87 90
88 self.__nothingStrings = { 91 self.__nothingStrings = {
89 "list": self.tr("Nothing to show"), 92 "list": self.tr("Nothing to show"),
90 "uptodate": self.tr("All packages outdated"), 93 "uptodate": self.tr("All packages outdated"),
91 "outdated": self.tr("All packages up-to-date"), 94 "outdated": self.tr("All packages up-to-date"),
92 } 95 }
93 96
94 self.__default = self.tr("<Default>") 97 self.venvComboBox.addItem(self.__pip.getDefaultEnvironmentString())
95 pipExecutables = sorted(plugin.getPreferences("PipExecutables")) 98 self.venvComboBox.addItems(self.__pip.getVirtualenvNames())
96 self.pipComboBox.addItem(self.__default)
97 self.pipComboBox.addItems(pipExecutables)
98 99
99 if mode == "list": 100 if mode == "list":
100 self.infoLabel.setText(self.tr("Installed Packages:")) 101 self.infoLabel.setText(self.tr("Installed Packages:"))
101 self.packageList.setHeaderLabels([ 102 self.packageList.setHeaderLabels([
102 self.tr("Package"), 103 self.tr("Package"),
158 159
159 def closeEvent(self, e): 160 def closeEvent(self, e):
160 """ 161 """
161 Protected slot implementing a close event handler. 162 Protected slot implementing a close event handler.
162 163
163 @param e close event (QCloseEvent) 164 @param e close event
165 @type QCloseEvent
164 """ 166 """
165 self.__stopProcess() 167 self.__stopProcess()
166 e.accept() 168 e.accept()
167 169
168 def __finish(self): 170 def __finish(self):
186 [self.__nothingStrings[self.__mode]]) 188 [self.__nothingStrings[self.__mode]])
187 if self.__errors and not self.__errors.startswith("DEPRECATION"): 189 if self.__errors and not self.__errors.startswith("DEPRECATION"):
188 E5MessageBox.critical( 190 E5MessageBox.critical(
189 self, 191 self,
190 self.windowTitle(), 192 self.windowTitle(),
191 self.tr("""<p>The pip command failed.</p>""" 193 self.tr("""<p>The command failed.</p>"""
192 """<p>Reason: {0}</p>""").format( 194 """<p>Reason: {0}</p>""").format(
193 self.__errors.replace("\r\n", "<br/>") 195 self.__errors.replace("\r\n", "<br/>")
194 .replace("\n", "<br/>").replace("\r", "<br/>") 196 .replace("\n", "<br/>").replace("\r", "<br/>")
195 .replace(" ", "&nbsp;"))) 197 .replace(" ", "&nbsp;")))
196 if self.__upgradeAllButton is not None: 198 if self.__upgradeAllButton is not None:
209 @pyqtSlot(QAbstractButton) 211 @pyqtSlot(QAbstractButton)
210 def on_buttonBox_clicked(self, button): 212 def on_buttonBox_clicked(self, button):
211 """ 213 """
212 Private slot called by a button of the button box clicked. 214 Private slot called by a button of the button box clicked.
213 215
214 @param button button that was clicked (QAbstractButton) 216 @param button button that was clicked
217 @type QAbstractButton
215 """ 218 """
216 if button == self.buttonBox.button(QDialogButtonBox.Close): 219 if button == self.buttonBox.button(QDialogButtonBox.Close):
217 self.close() 220 self.close()
218 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 221 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
219 self.__finish() 222 self.__finish()
228 231
229 def __procFinished(self, exitCode, exitStatus): 232 def __procFinished(self, exitCode, exitStatus):
230 """ 233 """
231 Private slot connected to the finished signal. 234 Private slot connected to the finished signal.
232 235
233 @param exitCode exit code of the process (integer) 236 @param exitCode exit code of the process
234 @param exitStatus exit status of the process (QProcess.ExitStatus) 237 @type int
238 @param exitStatus exit status of the process
239 @type QProcess.ExitStatus
235 """ 240 """
236 self.__finish() 241 self.__finish()
237 242
238 def __refresh(self): 243 def __refresh(self):
239 """ 244 """
259 QApplication.processEvents() 264 QApplication.processEvents()
260 265
261 QApplication.setOverrideCursor(Qt.WaitCursor) 266 QApplication.setOverrideCursor(Qt.WaitCursor)
262 QApplication.processEvents() 267 QApplication.processEvents()
263 268
264 command = self.pipComboBox.currentText() 269 venvName = self.venvComboBox.currentText()
265 if command == self.__default: 270 interpreter = self.__pip.getVirtualenvInterpreter(venvName)
266 command = self.__defaultCommand 271 if not interpreter:
267 272 return
268 args = PipListDialog.CommandArguments[self.__mode][:] 273
274 args = ["-m", "pip"] + PipListDialog.CommandArguments[self.__mode]
269 if self.localCheckBox.isChecked(): 275 if self.localCheckBox.isChecked():
270 args.append("--local") 276 args.append("--local")
271 if self.notRequiredCheckBox.isChecked(): 277 if self.notRequiredCheckBox.isChecked():
272 args.append("--not-required") 278 args.append("--not-required")
273 if self.userCheckBox.isChecked(): 279 if self.userCheckBox.isChecked():
275 281
276 if self.__indexUrl: 282 if self.__indexUrl:
277 args.append("--index-url") 283 args.append("--index-url")
278 args.append(self.__indexUrl + "/simple") 284 args.append(self.__indexUrl + "/simple")
279 285
280 self.process.start(command, args) 286 self.process.start(interpreter, args)
281 procStarted = self.process.waitForStarted(5000) 287 procStarted = self.process.waitForStarted(5000)
282 if not procStarted: 288 if not procStarted:
283 self.buttonBox.setFocus() 289 self.buttonBox.setFocus()
284 self.__stopProcess() 290 self.__stopProcess()
285 E5MessageBox.critical( 291 E5MessageBox.critical(
286 self, 292 self,
287 self.tr('Process Generation Error'), 293 self.tr('Process Generation Error'),
288 self.tr( 294 self.tr(
289 'The process {0} could not be started.' 295 'The process {0} could not be started.'
290 ).format(command)) 296 ).format(interpreter))
291 self.__finish() 297 self.__finish()
292 298
293 def __processOutput(self): 299 def __processOutput(self):
294 """ 300 """
295 Private method to process the captured output. 301 Private method to process the captured output.
336 """ 342 """
337 self.__errors += str(self.process.readAllStandardError(), 343 self.__errors += str(self.process.readAllStandardError(),
338 self.__ioEncoding, 'replace') 344 self.__ioEncoding, 'replace')
339 345
340 @pyqtSlot(str) 346 @pyqtSlot(str)
341 def on_pipComboBox_activated(self, txt): 347 def on_venvComboBox_activated(self, txt):
342 """ 348 """
343 Private slot handling the selection of a pip executable. 349 Private slot handling the selection of a virtual environment.
344 350
345 @param txt path of the pip executable (string) 351 @param txt virtual environment
352 @type str
346 """ 353 """
347 self.__refresh() 354 self.__refresh()
348 355
349 @pyqtSlot(bool) 356 @pyqtSlot(bool)
350 def on_localCheckBox_clicked(self, checked): 357 def on_localCheckBox_clicked(self, checked):
384 self.infoWidget.clear() 391 self.infoWidget.clear()
385 392
386 if len(self.packageList.selectedItems()) == 1: 393 if len(self.packageList.selectedItems()) == 1:
387 itm = self.packageList.selectedItems()[0] 394 itm = self.packageList.selectedItems()[0]
388 395
389 command = self.pipComboBox.currentText() 396 environment = self.venvComboBox.currentText()
390 if command == self.__default: 397 interpreter = self.__pip.getVirtualenvInterpreter(environment)
391 command = "" 398 if not interpreter:
399 return
392 400
393 QApplication.setOverrideCursor(Qt.WaitCursor) 401 QApplication.setOverrideCursor(Qt.WaitCursor)
394 402
395 args = ["show"] 403 args = ["-m", "pip", "show"]
396 if self.verboseCheckBox.isChecked(): 404 if self.verboseCheckBox.isChecked():
397 args.append("--verbose") 405 args.append("--verbose")
398 if self.installedFilesCheckBox.isChecked(): 406 if self.installedFilesCheckBox.isChecked():
399 args.append("--files") 407 args.append("--files")
400 args.append(itm.text(0)) 408 args.append(itm.text(0))
401 success, output = self.__pip.runProcess(args, cmd=command) 409 success, output = self.__pip.runProcess(args, interpreter)
402 410
403 if success and output: 411 if success and output:
404 mode = PipListDialog.ShowProcessGeneralMode 412 mode = PipListDialog.ShowProcessGeneralMode
405 for line in output.splitlines(): 413 for line in output.splitlines():
406 line = line.rstrip() 414 line = line.rstrip()
499 507
500 def __upgradePip(self): 508 def __upgradePip(self):
501 """ 509 """
502 Private slot to upgrade pip itself. 510 Private slot to upgrade pip itself.
503 """ 511 """
504 pip = self.pipComboBox.currentText()
505 if pip == self.__default:
506 pip = ""
507
508 res = self.__pip.upgradePip( 512 res = self.__pip.upgradePip(
509 pip=pip, userSite=self.userCheckBox.isChecked()) 513 venvName=self.venvComboBox.currentText(),
514 userSite=self.userCheckBox.isChecked())
510 if res: 515 if res:
511 self.__refresh() 516 self.__refresh()
512 517
513 def __executeUpgradePackages(self, packages): 518 def __executeUpgradePackages(self, packages):
514 """ 519 """
515 Private method to execute the pip upgrade command. 520 Private method to execute the pip upgrade command.
516 521
517 @param packages list of package names to be upgraded 522 @param packages list of package names to be upgraded
518 @type list of str 523 @type list of str
519 """ 524 """
520 command = self.pipComboBox.currentText()
521 if command == self.__default:
522 command = ""
523
524 res = self.__pip.upgradePackages( 525 res = self.__pip.upgradePackages(
525 packages, cmd=command, userSite=self.userCheckBox.isChecked()) 526 packages, venvName=self.venvComboBox.currentText(),
527 userSite=self.userCheckBox.isChecked())
526 if res: 528 if res:
527 self.__refresh() 529 self.__refresh()
528 530
529 def __uninstallPackages(self): 531 def __uninstallPackages(self):
530 """ 532 """
533 packages = [] 535 packages = []
534 for itm in self.packageList.selectedItems(): 536 for itm in self.packageList.selectedItems():
535 packages.append(itm.text(0)) 537 packages.append(itm.text(0))
536 538
537 if packages: 539 if packages:
538 command = self.pipComboBox.currentText() 540 res = self.__pip.uninstallPackages(
539 if command == self.__default: 541 packages,
540 command = "" 542 venvName=self.venvComboBox.currentText())
541
542 res = self.__pip.uninstallPackages(packages, cmd=command)
543 if res: 543 if res:
544 self.__refresh() 544 self.__refresh()

eric ide

mercurial