Sat, 09 Feb 2019 18:28:33 +0100
Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
CondaInterface/Conda.py | file | annotate | diff | comparison | revisions | |
CondaInterface/CondaPackagesWidget.py | file | annotate | diff | comparison | revisions |
--- a/CondaInterface/Conda.py Sat Feb 09 18:27:23 2019 +0100 +++ b/CondaInterface/Conda.py Sat Feb 09 18:28:33 2019 +0100 @@ -16,7 +16,7 @@ import json import os -from PyQt5.QtCore import pyqtSignal, QObject, QProcess +from PyQt5.QtCore import pyqtSignal, QObject, QProcess, QCoreApplication from PyQt5.QtWidgets import QDialog from E5Gui import E5MessageBox @@ -25,6 +25,7 @@ import Preferences from . import rootPrefix +from .CondaExecDialog import CondaExecDialog class Conda(QObject): @@ -39,6 +40,8 @@ condaEnvironmentCreated = pyqtSignal() condaEnvironmentRemoved = pyqtSignal() + RootName = QCoreApplication.translate("Conda", "<root>") + def __init__(self, parent=None): """ Constructor @@ -65,8 +68,6 @@ interpreter @rtype tuple of (bool, str, str) """ - from .CondaExecDialog import CondaExecDialog - args = ["create", "--json", "--yes"] + arguments dlg = CondaExecDialog("create", self.__ui) @@ -213,7 +214,7 @@ if not jsonDict["root_writable"]: # root prefix is listed but not writable continue - name = self.tr("<root>") + name = self.RootName else: name = os.path.basename(prefix) @@ -375,8 +376,6 @@ raise RuntimeError("One of 'name' or 'prefix' must be given.") if packages: - from .CondaExecDialog import CondaExecDialog - args = [ "update", "--json", @@ -417,8 +416,6 @@ if not name and not prefix: raise RuntimeError("One of 'name' or 'prefix' must be given.") - from .CondaExecDialog import CondaExecDialog - args = [ "update", "--json", @@ -460,10 +457,32 @@ raise RuntimeError("One of 'name' or 'prefix' must be given.") # TODO: not implemented yet + + if packages: + args = [ + "install", + "--json", + "--yes", + ] + if name: + args.extend(["--name", name]) + elif prefix: + args.extend(["--prefix", prefix]) + args.extend(packages) + + dlg = CondaExecDialog("install", self.__ui) + dlg.start(args) + dlg.exec_() + ok, _ = dlg.getResult() + else: + ok = False + + return ok def uninstallPackages(self, packages, name="", prefix=""): """ - Public method to uninstall packages of a conda environment. + Public method to uninstall packages of a conda environment (including + all no longer needed dependencies). @param packages list of package names to be uninstalled @type list of str @@ -490,15 +509,15 @@ self.parent(), self.tr("Uninstall Packages"), self.tr( - "Do you really want to uninstall these packages?"), + "Do you really want to uninstall these packages and" + " their dependencies?"), packages) if dlg.exec_() == QDialog.Accepted: - from .CondaExecDialog import CondaExecDialog - args = [ "remove", "--json", "--yes", + "--prune", ] if name: args.extend(["--name", name]) @@ -583,3 +602,25 @@ pass return ok, packages + + ####################################################################### + ## special methods below + ####################################################################### + + def updateConda(self): + """ + Private method to update conda itself. + """ + args = [ + "update", + "--json", + "--yes", + "conda" + ] + + dlg = CondaExecDialog("update", self.__ui) + dlg.start(args) + dlg.exec_() + ok, _ = dlg.getResult() + + return ok
--- a/CondaInterface/CondaPackagesWidget.py Sat Feb 09 18:27:23 2019 +0100 +++ b/CondaInterface/CondaPackagesWidget.py Sat Feb 09 18:28:33 2019 +0100 @@ -94,10 +94,13 @@ """ self.__condaMenu = QMenu(self) # TODO: implement Conda menu - self.__condaMenu.addAction(self.tr("Test Entry"), - self.on_refreshButton_clicked) + self.__condaMenu.addAction( + self.tr("Update Conda"), self.__conda.updateConda) + self.__condaMenu.addSeparator() self.condaMenuButton.setMenu(self.__condaMenu) + + self.__condaMenu.aboutToShow.connect(self.__aboutToShowCondaMenu) def __selectedUpdateableItems(self): """ @@ -280,8 +283,11 @@ QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() - prefix = self.environmentsComboBox.itemData( - self.environmentsComboBox.currentIndex()) + if CondaInterface.condaVersion() >= (4, 4, 0): + prefix = "" + else: + prefix = self.environmentsComboBox.itemData( + self.environmentsComboBox.currentIndex()) ok, result = self.__conda.searchPackages( pattern, fullNameOnly=self.fullNameButton.isChecked(), @@ -336,7 +342,7 @@ if details: from .CondaPackageDetailsWidget import CondaPackageDetailsDialog dlg = CondaPackageDetailsDialog(details, self) - dlg.show() + dlg.exec_() @pyqtSlot(str) def on_searchEdit_textChanged(self, txt): @@ -366,10 +372,26 @@ @pyqtSlot() def on_installButton_clicked(self): """ - Slot documentation goes here. + Private slot to install a selected package. """ - # TODO: not implemented yet - raise NotImplementedError + if len(self.searchResultList.selectedItems()) == 1: + item = self.searchResultList.selectedItems()[0] + if item.parent() is None: + # it is just the package item + package = item.text(0) + else: + # item with version and build + package = "{0}={1}={2}".format( + item.parent().text(0), + item.text(1), + item.text(2), + ) + + prefix = self.environmentsComboBox.itemData( + self.environmentsComboBox.currentIndex()) + ok = self.__conda.installPackages([package], prefix=prefix) + if ok: + self.on_refreshButton_clicked() @pyqtSlot() def on_showDetailsButton_clicked(self): @@ -425,3 +447,10 @@ self.searchEdit.selectAll() self.__updateSearchActionButtons() + + @pyqtSlot() + def __aboutToShowCondaMenu(self): + """ + Private slot to handle the conda menu about to be shown. + """ + selectedEnvironment = self.environmentsComboBox.currentText()