--- a/Plugins/UiExtensionPlugins/PipInterface/PipListDialog.py Tue Jun 12 18:59:45 2018 +0200 +++ b/Plugins/UiExtensionPlugins/PipInterface/PipListDialog.py Tue Jun 12 19:01:06 2018 +0200 @@ -41,16 +41,20 @@ ShowProcessEntryPointsMode = 2 ShowProcessFilesListMode = 3 - def __init__(self, pip, mode, plugin, title, parent=None): + def __init__(self, pip, mode, indexUrl, title, parent=None): """ Constructor - @param pip reference to the master object (Pip) - @param mode list command mode (string; one of 'list', - 'uptodate', 'outdated') - @param plugin reference to the plugin object (ToolPipPlugin) - @param title title of the dialog (string) - @param parent reference to the parent widget (QWidget) + @param pip reference to the master object + @type Pip + @param mode list command mode (one of 'list', 'uptodate', 'outdated') + @type str + @param indexUrl URL of the pypi index + @type str + @param title title of the dialog + @type str + @param parent reference to the parent widget + @type QWidget """ assert mode in PipListDialog.CommandArguments @@ -79,9 +83,8 @@ self.__pip = pip self.__mode = mode - self.__defaultCommand = plugin.getPreferences("CurrentPipExecutable") self.__ioEncoding = Preferences.getSystem("IOEncoding") - self.__indexUrl = plugin.getPreferences("PipSearchIndex") + self.__indexUrl = indexUrl self.__errors = "" self.__output = [] @@ -91,10 +94,8 @@ "outdated": self.tr("All packages up-to-date"), } - self.__default = self.tr("<Default>") - pipExecutables = sorted(plugin.getPreferences("PipExecutables")) - self.pipComboBox.addItem(self.__default) - self.pipComboBox.addItems(pipExecutables) + self.venvComboBox.addItem(self.__pip.getDefaultEnvironmentString()) + self.venvComboBox.addItems(self.__pip.getVirtualenvNames()) if mode == "list": self.infoLabel.setText(self.tr("Installed Packages:")) @@ -160,7 +161,8 @@ """ Protected slot implementing a close event handler. - @param e close event (QCloseEvent) + @param e close event + @type QCloseEvent """ self.__stopProcess() e.accept() @@ -188,7 +190,7 @@ E5MessageBox.critical( self, self.windowTitle(), - self.tr("""<p>The pip command failed.</p>""" + self.tr("""<p>The command failed.</p>""" """<p>Reason: {0}</p>""").format( self.__errors.replace("\r\n", "<br/>") .replace("\n", "<br/>").replace("\r", "<br/>") @@ -211,7 +213,8 @@ """ Private slot called by a button of the button box clicked. - @param button button that was clicked (QAbstractButton) + @param button button that was clicked + @type QAbstractButton """ if button == self.buttonBox.button(QDialogButtonBox.Close): self.close() @@ -230,8 +233,10 @@ """ Private slot connected to the finished signal. - @param exitCode exit code of the process (integer) - @param exitStatus exit status of the process (QProcess.ExitStatus) + @param exitCode exit code of the process + @type int + @param exitStatus exit status of the process + @type QProcess.ExitStatus """ self.__finish() @@ -261,11 +266,12 @@ QApplication.setOverrideCursor(Qt.WaitCursor) QApplication.processEvents() - command = self.pipComboBox.currentText() - if command == self.__default: - command = self.__defaultCommand + venvName = self.venvComboBox.currentText() + interpreter = self.__pip.getVirtualenvInterpreter(venvName) + if not interpreter: + return - args = PipListDialog.CommandArguments[self.__mode][:] + args = ["-m", "pip"] + PipListDialog.CommandArguments[self.__mode] if self.localCheckBox.isChecked(): args.append("--local") if self.notRequiredCheckBox.isChecked(): @@ -277,7 +283,7 @@ args.append("--index-url") args.append(self.__indexUrl + "/simple") - self.process.start(command, args) + self.process.start(interpreter, args) procStarted = self.process.waitForStarted(5000) if not procStarted: self.buttonBox.setFocus() @@ -287,7 +293,7 @@ self.tr('Process Generation Error'), self.tr( 'The process {0} could not be started.' - ).format(command)) + ).format(interpreter)) self.__finish() def __processOutput(self): @@ -338,11 +344,12 @@ self.__ioEncoding, 'replace') @pyqtSlot(str) - def on_pipComboBox_activated(self, txt): + def on_venvComboBox_activated(self, txt): """ - Private slot handling the selection of a pip executable. + Private slot handling the selection of a virtual environment. - @param txt path of the pip executable (string) + @param txt virtual environment + @type str """ self.__refresh() @@ -386,19 +393,20 @@ if len(self.packageList.selectedItems()) == 1: itm = self.packageList.selectedItems()[0] - command = self.pipComboBox.currentText() - if command == self.__default: - command = "" + environment = self.venvComboBox.currentText() + interpreter = self.__pip.getVirtualenvInterpreter(environment) + if not interpreter: + return QApplication.setOverrideCursor(Qt.WaitCursor) - args = ["show"] + args = ["-m", "pip", "show"] if self.verboseCheckBox.isChecked(): args.append("--verbose") if self.installedFilesCheckBox.isChecked(): args.append("--files") args.append(itm.text(0)) - success, output = self.__pip.runProcess(args, cmd=command) + success, output = self.__pip.runProcess(args, interpreter) if success and output: mode = PipListDialog.ShowProcessGeneralMode @@ -501,12 +509,9 @@ """ Private slot to upgrade pip itself. """ - pip = self.pipComboBox.currentText() - if pip == self.__default: - pip = "" - res = self.__pip.upgradePip( - pip=pip, userSite=self.userCheckBox.isChecked()) + venvName=self.venvComboBox.currentText(), + userSite=self.userCheckBox.isChecked()) if res: self.__refresh() @@ -517,12 +522,9 @@ @param packages list of package names to be upgraded @type list of str """ - command = self.pipComboBox.currentText() - if command == self.__default: - command = "" - res = self.__pip.upgradePackages( - packages, cmd=command, userSite=self.userCheckBox.isChecked()) + packages, venvName=self.venvComboBox.currentText(), + userSite=self.userCheckBox.isChecked()) if res: self.__refresh() @@ -535,10 +537,8 @@ packages.append(itm.text(0)) if packages: - command = self.pipComboBox.currentText() - if command == self.__default: - command = "" - - res = self.__pip.uninstallPackages(packages, cmd=command) + res = self.__pip.uninstallPackages( + packages, + venvName=self.venvComboBox.currentText()) if res: self.__refresh()