CondaInterface/Conda.py

branch
conda
changeset 6728
ba077788a882
parent 6724
ca89c7d94c94
equal deleted inserted replaced
6727:e235150f016c 6728:ba077788a882
22 from E5Gui import E5MessageBox 22 from E5Gui import E5MessageBox
23 23
24 import Globals 24 import Globals
25 import Preferences 25 import Preferences
26 26
27 from . import rootPrefix 27 from . import rootPrefix, condaVersion
28 from .CondaExecDialog import CondaExecDialog 28 from .CondaExecDialog import CondaExecDialog
29 29
30 30
31 class Conda(QObject): 31 class Conda(QObject):
32 """ 32 """
454 raise RuntimeError("Only one of 'name' or 'prefix' must be given.") 454 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
455 455
456 if not name and not prefix: 456 if not name and not prefix:
457 raise RuntimeError("One of 'name' or 'prefix' must be given.") 457 raise RuntimeError("One of 'name' or 'prefix' must be given.")
458 458
459 # TODO: not implemented yet
460
461 if packages: 459 if packages:
462 args = [ 460 args = [
463 "install", 461 "install",
464 "--json", 462 "--json",
465 "--yes", 463 "--yes",
515 if dlg.exec_() == QDialog.Accepted: 513 if dlg.exec_() == QDialog.Accepted:
516 args = [ 514 args = [
517 "remove", 515 "remove",
518 "--json", 516 "--json",
519 "--yes", 517 "--yes",
520 "--prune",
521 ] 518 ]
519 if condaVersion() >= (4, 4, 0):
520 args.append("--prune",)
522 if name: 521 if name:
523 args.extend(["--name", name]) 522 args.extend(["--name", name])
524 elif prefix: 523 elif prefix:
525 args.extend(["--prefix", prefix]) 524 args.extend(["--prefix", prefix])
526 args.extend(packages) 525 args.extend(packages)
608 ####################################################################### 607 #######################################################################
609 608
610 def updateConda(self): 609 def updateConda(self):
611 """ 610 """
612 Public method to update conda itself. 611 Public method to update conda itself.
612
613 @return flag indicating success
614 @rtype bool
613 """ 615 """
614 args = [ 616 args = [
615 "update", 617 "update",
616 "--json", 618 "--json",
617 "--yes", 619 "--yes",
628 def writeDefaultConfiguration(self): 630 def writeDefaultConfiguration(self):
629 """ 631 """
630 Public method to create a conda configuration with default values. 632 Public method to create a conda configuration with default values.
631 """ 633 """
632 args = [ 634 args = [
633 "config", 635 "config",
634 "--write-default", 636 "--write-default",
635 "--quiet" 637 "--quiet"
636 ] 638 ]
637 639
638 exe = Preferences.getConda("CondaExecutable") 640 exe = Preferences.getConda("CondaExecutable")
658 infoDict = {} 660 infoDict = {}
659 661
660 proc = QProcess() 662 proc = QProcess()
661 proc.start(exe, ["info", "--json"]) 663 proc.start(exe, ["info", "--json"])
662 if proc.waitForStarted(15000): 664 if proc.waitForStarted(15000):
663 if proc.waitForFinished(15000): 665 if proc.waitForFinished(30000):
664 output = str(proc.readAllStandardOutput(), 666 output = str(proc.readAllStandardOutput(),
665 Preferences.getSystem("IOEncoding"), 667 Preferences.getSystem("IOEncoding"),
666 'replace').strip() 668 'replace').strip()
667 try: 669 try:
668 infoDict = json.loads(output) 670 infoDict = json.loads(output)
669 except Exception: 671 except Exception:
670 infoDict = {} 672 infoDict = {}
671 673
672 return infoDict 674 return infoDict
675
676 def runProcess(self, args):
677 """
678 Public method to execute the conda with the given arguments.
679
680 The conda executable is called with the given arguments and
681 waited for its end.
682
683 @param args list of command line arguments
684 @type list of str
685 @return tuple containing a flag indicating success and the output
686 of the process
687 @rtype tuple of (bool, str)
688 """
689 exe = Preferences.getConda("CondaExecutable")
690 if not exe:
691 exe = "conda"
692
693 process = QProcess()
694 process.start(exe, args)
695 procStarted = process.waitForStarted(15000)
696 if procStarted:
697 finished = process.waitForFinished(30000)
698 if finished:
699 if process.exitCode() == 0:
700 output = str(process.readAllStandardOutput(),
701 Preferences.getSystem("IOEncoding"),
702 'replace').strip()
703 return True, output
704 else:
705 return (False,
706 self.tr("conda exited with an error ({0}).")
707 .format(process.exitCode()))
708 else:
709 process.terminate()
710 process.waitForFinished(2000)
711 process.kill()
712 process.waitForFinished(3000)
713 return False, self.tr("conda did not finish within"
714 " 30 seconds.")
715
716 return False, self.tr("conda could not be started.")
717
718 def cleanConda(self, cleanAction):
719 """
720 Public method to update conda itself.
721
722 @param cleanAction cleaning action to be performed (must be one of
723 the command line parameters without '--')
724 @type str
725 """
726 args = [
727 "clean",
728 "--yes",
729 "--{0}".format(cleanAction),
730 ]
731
732 dlg = CondaExecDialog("clean", self.__ui)
733 dlg.start(args)
734 dlg.exec_()

eric ide

mercurial