--- 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