eric6/CondaInterface/Conda.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7360
9190402e4505
child 7628
f904d0eef264
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7250
diff changeset
3 # Copyright (c) 2019 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Package implementing the conda GUI logic.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import json
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
14 from PyQt5.QtCore import pyqtSignal, QObject, QProcess, QCoreApplication
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
15 from PyQt5.QtWidgets import QDialog
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 from E5Gui import E5MessageBox
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 import Globals
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import Preferences
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
22 from . import rootPrefix, condaVersion
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
23 from .CondaExecDialog import CondaExecDialog
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 class Conda(QObject):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Class implementing the conda GUI logic.
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
29
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
30 @signal condaEnvironmentCreated() emitted to indicate the creation of
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
31 a new environment
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
32 @signal condaEnvironmentRemoved() emitted to indicate the removal of
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
33 an environment
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
35 condaEnvironmentCreated = pyqtSignal()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
36 condaEnvironmentRemoved = pyqtSignal()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
37
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
38 RootName = QCoreApplication.translate("Conda", "<root>")
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
39
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 def __init__(self, parent=None):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Constructor
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @param parent parent
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @type QObject
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 super(Conda, self).__init__(parent)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.__ui = parent
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
51 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
52 ## environment related methods below
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
53 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
54
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 def createCondaEnvironment(self, arguments):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 Public method to create a conda environment.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 @param arguments list of command line arguments
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @type list of str
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 @return tuple containing a flag indicating success, the directory of
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 the created environment (aka. prefix) and the corresponding Python
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 interpreter
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 @rtype tuple of (bool, str, str)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 args = ["create", "--json", "--yes"] + arguments
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 dlg = CondaExecDialog("create", self.__ui)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 dlg.start(args)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 dlg.exec_()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 ok, resultDict = dlg.getResult()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 if ok:
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
74 if ("actions" in resultDict and
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
75 "PREFIX" in resultDict["actions"]):
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 prefix = resultDict["actions"]["PREFIX"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 elif "prefix" in resultDict:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 prefix = resultDict["prefix"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 elif "dst_prefix" in resultDict:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 prefix = resultDict["dst_prefix"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 prefix = ""
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 # determine Python executable
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 pathPrefixes = [
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 prefix,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 rootPrefix()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 ]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 pathPrefixes = [
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 rootPrefix()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 ]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 for pathPrefix in pathPrefixes:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 if Globals.isWindowsPlatform():
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 python = os.path.join(pathPrefix, "python.exe")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 python = os.path.join(pathPrefix, "bin", "python")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 if os.path.exists(python):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 break
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 python = ""
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
104 self.condaEnvironmentCreated.emit()
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 return True, prefix, python
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 return False, "", ""
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def removeCondaEnvironment(self, name="", prefix=""):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 Public method to remove a conda environment.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @param name name of the environment
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @type str
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 @param prefix prefix of the environment
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 @type str
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 @return flag indicating success
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @rtype bool
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 @exception RuntimeError raised to indicate an error in parameters
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 Note: only one of name or prefix must be given.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 if name and prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 if not name and not prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 raise RuntimeError("One of 'name' or 'prefix' must be given.")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 args = [
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 "remove",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 "--json",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 "--quiet",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 "--all",
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 ]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 if name:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 args.extend(["--name", name])
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 elif prefix:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 args.extend(["--prefix", prefix])
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 exe = Preferences.getConda("CondaExecutable")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 if not exe:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 exe = "conda"
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 proc = QProcess()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 proc.start(exe, args)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 if not proc.waitForStarted(15000):
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 E5MessageBox.critical(
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.__ui,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.tr("conda remove"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.tr("""The conda executable could not be started."""))
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 return False
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 else:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 proc.waitForFinished(15000)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 output = str(proc.readAllStandardOutput(),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 Preferences.getSystem("IOEncoding"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 'replace').strip()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 try:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 jsonDict = json.loads(output)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 except Exception:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 E5MessageBox.critical(
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.__ui,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.tr("conda remove"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 self.tr("""The conda executable returned invalid data."""))
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 return False
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 if "error" in jsonDict:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 E5MessageBox.critical(
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 self.__ui,
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 self.tr("conda remove"),
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 self.tr("<p>The conda executable returned an error.</p>"
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 "<p>{0}</p>").format(jsonDict["message"]))
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 return False
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
174 if jsonDict["success"]:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
175 self.condaEnvironmentRemoved.emit()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
176
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 return jsonDict["success"]
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
178
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
179 return False
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
180
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
181 def getCondaEnvironmentsList(self):
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
182 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
183 Public method to get a list of all Conda environments.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
184
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
185 @return list of tuples containing the environment name and prefix
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
186 @rtype list of tuples of (str, str)
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
187 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
188 exe = Preferences.getConda("CondaExecutable")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
189 if not exe:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
190 exe = "conda"
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
191
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
192 environmentsList = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
193
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
194 proc = QProcess()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
195 proc.start(exe, ["info", "--json"])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
196 if proc.waitForStarted(15000):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
197 if proc.waitForFinished(15000):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
198 output = str(proc.readAllStandardOutput(),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
199 Preferences.getSystem("IOEncoding"),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
200 'replace').strip()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
201 try:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
202 jsonDict = json.loads(output)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
203 except Exception:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
204 jsonDict = {}
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
205
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
206 if "envs" in jsonDict:
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
207 for prefix in jsonDict["envs"][:]:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
208 if prefix == jsonDict["root_prefix"]:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
209 if not jsonDict["root_writable"]:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
210 # root prefix is listed but not writable
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
211 continue
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
212 name = self.RootName
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
213 else:
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
214 name = os.path.basename(prefix)
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
215
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
216 environmentsList.append((name, prefix))
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
217
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
218 return environmentsList
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
219
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
220 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
221 ## package related methods below
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
222 #######################################################################
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
223
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
224 def getInstalledPackages(self, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
225 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
226 Public method to get a list of installed packages of a conda
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
227 environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
228
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
229 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
230 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
231 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
232 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
233 @return list of installed packages. Each entry is a tuple containing
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
234 the package name, version and build.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
235 @rtype list of tuples of (str, str, str)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
236 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
237
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
238 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
239 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
240 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
241 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
242
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
243 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
244 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
245
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
246 args = [
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
247 "list",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
248 "--json",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
249 ]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
250 if name:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
251 args.extend(["--name", name])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
252 elif prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
253 args.extend(["--prefix", prefix])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
254
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
255 exe = Preferences.getConda("CondaExecutable")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
256 if not exe:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
257 exe = "conda"
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
258
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
259 packages = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
260
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
261 proc = QProcess()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
262 proc.start(exe, args)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
263 if proc.waitForStarted(15000):
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
264 if proc.waitForFinished(30000):
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
265 output = str(proc.readAllStandardOutput(),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
266 Preferences.getSystem("IOEncoding"),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
267 'replace').strip()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
268 try:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
269 jsonList = json.loads(output)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
270 except Exception:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
271 jsonList = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
272
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
273 for package in jsonList:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
274 if isinstance(package, dict):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
275 packages.append((
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
276 package["name"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
277 package["version"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
278 package["build_string"]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
279 ))
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
280 else:
7033
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
281 parts = package.rsplit("-", 2)
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
282 while len(parts) < 3:
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
283 parts.append("")
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
284 packages.append(tuple(parts))
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
285
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
286 return packages
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
287
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
288 def getUpdateablePackages(self, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
289 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
290 Public method to get a list of updateable packages of a conda
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
291 environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
292
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
293 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
294 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
295 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
296 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
297 @return list of installed packages. Each entry is a tuple containing
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
298 the package name, version and build.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
299 @rtype list of tuples of (str, str, str)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
300 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
301
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
302 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
303 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
304 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
305 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
306
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
307 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
308 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
309
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
310 args = [
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
311 "update",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
312 "--json",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
313 "--quiet",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
314 "--all",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
315 "--dry-run",
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
316 ]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
317 if name:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
318 args.extend(["--name", name])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
319 elif prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
320 args.extend(["--prefix", prefix])
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
321
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
322 exe = Preferences.getConda("CondaExecutable")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
323 if not exe:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
324 exe = "conda"
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
325
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
326 packages = []
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
327
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
328 proc = QProcess()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
329 proc.start(exe, args)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
330 if proc.waitForStarted(15000):
6705
8cf1c3851b5c Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6701
diff changeset
331 if proc.waitForFinished(30000):
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
332 output = str(proc.readAllStandardOutput(),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
333 Preferences.getSystem("IOEncoding"),
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
334 'replace').strip()
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
335 try:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
336 jsonDict = json.loads(output)
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
337 except Exception:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
338 jsonDict = {}
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
339
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
340 if "actions" in jsonDict and "LINK" in jsonDict["actions"]:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
341 for linkEntry in jsonDict["actions"]["LINK"]:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
342 if isinstance(linkEntry, dict):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
343 packages.append((
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
344 linkEntry["name"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
345 linkEntry["version"],
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
346 linkEntry["build_string"]
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
347 ))
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
348 else:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
349 package = linkEntry.split()[0]
7033
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
350 parts = package.rsplit("-", 2)
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
351 while len(parts) < 3:
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
352 parts.append("")
39b9e66ddbd6 Conda: fixed an issue causing package list returned by getInstalledPackages() and getUpdateablePackages() not always contain three tuple elements.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
353 packages.append(tuple(parts))
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
354
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
355 return packages
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
356
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
357 def updatePackages(self, packages, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
358 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
359 Public method to update packages of a conda environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
360
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
361 @param packages list of package names to be updated
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
362 @type list of str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
363 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
364 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
365 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
366 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
367 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
368 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
369 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
370
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
371 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
372 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
373 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
374 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
375
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
376 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
377 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
378
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
379 if packages:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
380 args = [
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
381 "update",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
382 "--json",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
383 "--yes",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
384 ]
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
385 if name:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
386 args.extend(["--name", name])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
387 elif prefix:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
388 args.extend(["--prefix", prefix])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
389 args.extend(packages)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
390
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
391 dlg = CondaExecDialog("update", self.__ui)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
392 dlg.start(args)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
393 dlg.exec_()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
394 ok, _ = dlg.getResult()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
395 else:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
396 ok = False
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
397
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
398 return ok
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
399
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
400 def updateAllPackages(self, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
401 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
402 Public method to update all packages of a conda environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
403
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
404 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
405 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
406 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
407 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
408 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
409 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
410 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
411
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
412 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
413 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
414 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
415 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
416
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
417 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
418 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
419
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
420 args = [
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
421 "update",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
422 "--json",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
423 "--yes",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
424 "--all"
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
425 ]
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
426 if name:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
427 args.extend(["--name", name])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
428 elif prefix:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
429 args.extend(["--prefix", prefix])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
430
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
431 dlg = CondaExecDialog("update", self.__ui)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
432 dlg.start(args)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
433 dlg.exec_()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
434 ok, _ = dlg.getResult()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
435
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
436 return ok
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
437
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
438 def installPackages(self, packages, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
439 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
440 Public method to install packages into a conda environment.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
441
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
442 @param packages list of package names to be installed
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
443 @type list of str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
444 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
445 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
446 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
447 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
448 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
449 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
450 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
451
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
452 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
453 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
454 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
455 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
456
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
457 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
458 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
459
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
460 if packages:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
461 args = [
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
462 "install",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
463 "--json",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
464 "--yes",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
465 ]
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
466 if name:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
467 args.extend(["--name", name])
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
468 elif prefix:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
469 args.extend(["--prefix", prefix])
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
470 args.extend(packages)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
471
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
472 dlg = CondaExecDialog("install", self.__ui)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
473 dlg.start(args)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
474 dlg.exec_()
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
475 ok, _ = dlg.getResult()
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
476 else:
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
477 ok = False
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
478
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
479 return ok
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
480
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
481 def uninstallPackages(self, packages, name="", prefix=""):
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
482 """
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
483 Public method to uninstall packages of a conda environment (including
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
484 all no longer needed dependencies).
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
485
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
486 @param packages list of package names to be uninstalled
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
487 @type list of str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
488 @param name name of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
489 @type str
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
490 @param prefix prefix of the environment
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
491 @type str
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
492 @return flag indicating success
6701
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
493 @rtype bool
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
494 @exception RuntimeError raised to indicate an error in parameters
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
495
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
496 Note: only one of name or prefix must be given.
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
497 """
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
498 if name and prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
499 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
500
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
501 if not name and not prefix:
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
502 raise RuntimeError("One of 'name' or 'prefix' must be given.")
af29cf6ca309 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6697
diff changeset
503
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
504 if packages:
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
505 from UI.DeleteFilesConfirmationDialog import (
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
506 DeleteFilesConfirmationDialog)
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
507 dlg = DeleteFilesConfirmationDialog(
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
508 self.parent(),
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
509 self.tr("Uninstall Packages"),
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
510 self.tr(
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
511 "Do you really want to uninstall these packages and"
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
512 " their dependencies?"),
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
513 packages)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
514 if dlg.exec_() == QDialog.Accepted:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
515 args = [
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
516 "remove",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
517 "--json",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
518 "--yes",
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
519 ]
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
520 if condaVersion() >= (4, 4, 0):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
521 args.append("--prune",)
6706
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
522 if name:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
523 args.extend(["--name", name])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
524 elif prefix:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
525 args.extend(["--prefix", prefix])
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
526 args.extend(packages)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
527
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
528 dlg = CondaExecDialog("remove", self.__ui)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
529 dlg.start(args)
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
530 dlg.exec_()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
531 ok, _ = dlg.getResult()
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
532 else:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
533 ok = False
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
534 else:
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
535 ok = False
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
536
d792e054cde2 Conda, CondaPackagesWidget: continued implementing list functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6705
diff changeset
537 return ok
6712
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
538
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
539 def searchPackages(self, pattern, fullNameOnly=False, packageSpec=False,
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
540 platform="", name="", prefix=""):
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
541 """
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
542 Public method to search for a package pattern of a conda environment.
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
543
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
544 @param pattern package search pattern
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
545 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
546 @param fullNameOnly flag indicating to search for full names only
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
547 @type bool
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
548 @param packageSpec flag indicating to search a package specification
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
549 @type bool
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
550 @param platform type of platform to be searched for
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
551 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
552 @param name name of the environment
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
553 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
554 @param prefix prefix of the environment
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
555 @type str
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
556 @return flag indicating success and a dictionary with package name as
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
557 key and list of dictionaries containing detailed data for the found
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
558 packages as values
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
559 @rtype tuple of (bool, dict of list of dict)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
560 @exception RuntimeError raised to indicate an error in parameters
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
561
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
562 Note: only one of name or prefix must be given.
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
563 """
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
564 if name and prefix:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
565 raise RuntimeError("Only one of 'name' or 'prefix' must be given.")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
566
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
567 args = [
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
568 "search",
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
569 "--json",
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
570 ]
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
571 if fullNameOnly:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
572 args.append("--full-name")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
573 if packageSpec:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
574 args.append("--spec")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
575 if platform:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
576 args.extend(["--platform", platform])
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
577 if name:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
578 args.extend(["--name", name])
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
579 elif prefix:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
580 args.extend(["--prefix", prefix])
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
581 args.append(pattern)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
582
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
583 exe = Preferences.getConda("CondaExecutable")
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
584 if not exe:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
585 exe = "conda"
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
586
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
587 packages = {}
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
588 ok = False
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
589
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
590 proc = QProcess()
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
591 proc.start(exe, args)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
592 if proc.waitForStarted(15000):
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
593 if proc.waitForFinished(30000):
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
594 output = str(proc.readAllStandardOutput(),
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
595 Preferences.getSystem("IOEncoding"),
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
596 'replace').strip()
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
597 try:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
598 packages = json.loads(output)
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
599 ok = "error" not in packages
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
600 except Exception:
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
601 # return values for errors is already set
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
602 pass
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
603
91fa67e8ebbc Conda: implemented the package search and 'Show Details' functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6706
diff changeset
604 return ok, packages
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
605
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
606 #######################################################################
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
607 ## special methods below
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
608 #######################################################################
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
609
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
610 def updateConda(self):
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
611 """
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
612 Public method to update conda itself.
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
613
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
614 @return flag indicating success
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
615 @rtype bool
6715
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
616 """
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
617 args = [
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
618 "update",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
619 "--json",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
620 "--yes",
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
621 "conda"
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
622 ]
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
623
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
624 dlg = CondaExecDialog("update", self.__ui)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
625 dlg.start(args)
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
626 dlg.exec_()
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
627 ok, _ = dlg.getResult()
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
628
f1bf1985434e Conda, CondaPackagesWidget: implemented install functionality and strted with Conda menu.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6712
diff changeset
629 return ok
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
630
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
631 def writeDefaultConfiguration(self):
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
632 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
633 Public method to create a conda configuration with default values.
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
634 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
635 args = [
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
636 "config",
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
637 "--write-default",
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
638 "--quiet"
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
639 ]
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
640
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
641 exe = Preferences.getConda("CondaExecutable")
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
642 if not exe:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
643 exe = "conda"
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
644
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
645 proc = QProcess()
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
646 proc.start(exe, args)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
647 proc.waitForStarted(15000)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
648 proc.waitForFinished(30000)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
649
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
650 def getCondaInformation(self):
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
651 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
652 Public method to get a dictionary containing information about conda.
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
653
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
654 @return dictionary containing information about conda
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
655 @rtype dict
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
656 """
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
657 exe = Preferences.getConda("CondaExecutable")
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
658 if not exe:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
659 exe = "conda"
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
660
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
661 infoDict = {}
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
662
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
663 proc = QProcess()
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
664 proc.start(exe, ["info", "--json"])
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
665 if proc.waitForStarted(15000):
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
666 if proc.waitForFinished(30000):
6724
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
667 output = str(proc.readAllStandardOutput(),
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
668 Preferences.getSystem("IOEncoding"),
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
669 'replace').strip()
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
670 try:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
671 infoDict = json.loads(output)
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
672 except Exception:
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
673 infoDict = {}
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
674
ca89c7d94c94 Conda: started implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6715
diff changeset
675 return infoDict
6728
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
676
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
677 def runProcess(self, args):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
678 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
679 Public method to execute the conda with the given arguments.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
680
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
681 The conda executable is called with the given arguments and
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
682 waited for its end.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
683
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
684 @param args list of command line arguments
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
685 @type list of str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
686 @return tuple containing a flag indicating success and the output
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
687 of the process
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
688 @rtype tuple of (bool, str)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
689 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
690 exe = Preferences.getConda("CondaExecutable")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
691 if not exe:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
692 exe = "conda"
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
693
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
694 process = QProcess()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
695 process.start(exe, args)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
696 procStarted = process.waitForStarted(15000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
697 if procStarted:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
698 finished = process.waitForFinished(30000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
699 if finished:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
700 if process.exitCode() == 0:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
701 output = str(process.readAllStandardOutput(),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
702 Preferences.getSystem("IOEncoding"),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
703 'replace').strip()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
704 return True, output
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
705 else:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
706 return (False,
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
707 self.tr("conda exited with an error ({0}).")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
708 .format(process.exitCode()))
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
709 else:
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
710 process.terminate()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
711 process.waitForFinished(2000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
712 process.kill()
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
713 process.waitForFinished(3000)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
714 return False, self.tr("conda did not finish within"
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
715 " 30 seconds.")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
716
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
717 return False, self.tr("conda could not be started.")
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
718
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
719 def cleanConda(self, cleanAction):
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
720 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
721 Public method to update conda itself.
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
722
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
723 @param cleanAction cleaning action to be performed (must be one of
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
724 the command line parameters without '--')
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
725 @type str
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
726 """
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
727 args = [
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
728 "clean",
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
729 "--yes",
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
730 "--{0}".format(cleanAction),
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
731 ]
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
732
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
733 dlg = CondaExecDialog("clean", self.__ui)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
734 dlg.start(args)
ba077788a882 Conda: continued implementing the conda menu functionality
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6724
diff changeset
735 dlg.exec_()

eric ide

mercurial