14 from PyQt6.QtCore import QCoreApplication, QObject, QProcess, pyqtSignal |
14 from PyQt6.QtCore import QCoreApplication, QObject, QProcess, pyqtSignal |
15 from PyQt6.QtWidgets import QDialog |
15 from PyQt6.QtWidgets import QDialog |
16 |
16 |
17 from eric7 import Preferences |
17 from eric7 import Preferences |
18 from eric7.EricWidgets import EricMessageBox |
18 from eric7.EricWidgets import EricMessageBox |
|
19 from eric7.EricWidgets.EricApplication import ericApp |
19 from eric7.SystemUtilities import OSUtilities |
20 from eric7.SystemUtilities import OSUtilities |
20 |
21 from eric7.VirtualEnv.VirtualenvMeta import VirtualenvMetaData |
21 from . import condaVersion, rootPrefix |
22 from eric7.VirtualEnv.VirtualenvRegistry import VirtualenvType |
|
23 |
|
24 from . import condaVersion, isCondaAvailable, rootPrefix |
22 from .CondaExecDialog import CondaExecDialog |
25 from .CondaExecDialog import CondaExecDialog |
23 |
26 |
24 |
27 |
25 class Conda(QObject): |
28 class Conda(QObject): |
26 """ |
29 """ |
45 @type QObject |
49 @type QObject |
46 """ |
50 """ |
47 super().__init__(parent) |
51 super().__init__(parent) |
48 |
52 |
49 self.__ui = parent |
53 self.__ui = parent |
|
54 |
|
55 envManager = ericApp().getObject("VirtualEnvManager") |
|
56 envManager.registerType( |
|
57 VirtualenvType( |
|
58 name=Conda.EnvironmentType, |
|
59 visual_name=self.tr("Anaconda"), |
|
60 createFunc=self.createCondaVirtualEnvironment, |
|
61 deleteFunc=self.deleteCondaVirtualEnvironment, |
|
62 defaultExecPathFunc=self.condaDefaultExecPath, |
|
63 ) |
|
64 ) |
50 |
65 |
51 ####################################################################### |
66 ####################################################################### |
52 ## environment related methods below |
67 ## environment related methods below |
53 ####################################################################### |
68 ####################################################################### |
|
69 |
|
70 def condaDefaultExecPath(self, venvDirectory): |
|
71 """ |
|
72 Public method returning the default PATH prefix for a conda environment. |
|
73 |
|
74 @param venvDirectory path of the virtual environment to generate the |
|
75 default PATH prefix for |
|
76 @type str |
|
77 @return default PATH prefix string |
|
78 @rtype str |
|
79 """ |
|
80 if OSUtilities.isWindowsPlatform(): |
|
81 return os.pathsep.join( |
|
82 [ |
|
83 venvDirectory, |
|
84 os.path.join(venvDirectory, "Scripts"), |
|
85 os.path.join(venvDirectory, "Library", "bin"), |
|
86 ] |
|
87 ) |
|
88 else: |
|
89 return os.path.join(venvDirectory, "bin") |
|
90 |
|
91 def createCondaVirtualEnvironment(self, baseDir=""): |
|
92 """ |
|
93 Public method to create an anaconda/miniconda environment. |
|
94 |
|
95 Note: This method is used by the Virtual Environment Manager. |
|
96 |
|
97 @param baseDir base directory for the virtual environments (defaults to "") |
|
98 @type str (optional) |
|
99 """ |
|
100 from .CondaEnvironmentConfigurationDialog import ( |
|
101 CondaEnvironmentConfigurationDialog, |
|
102 ) |
|
103 |
|
104 if not isCondaAvailable(): |
|
105 EricMessageBox.critical( |
|
106 self.__ui, |
|
107 self.tr("Create Conda Environment"), |
|
108 self.tr( |
|
109 "Conda has not been installed or is not configured. Aborting..." |
|
110 ), |
|
111 ) |
|
112 return |
|
113 |
|
114 dlg = CondaEnvironmentConfigurationDialog(baseDir=baseDir, parent=self.__ui) |
|
115 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
116 resultDict = dlg.getData() |
|
117 # now create the conda environment |
|
118 ok, prefix, interpreter = self.createCondaEnvironment( |
|
119 resultDict["arguments"] |
|
120 ) |
|
121 if ok and "--dry-run" not in resultDict["arguments"]: |
|
122 ericApp().getObject("VirtualEnvManager").addVirtualEnv( |
|
123 VirtualenvMetaData( |
|
124 name=resultDict["logicalName"], |
|
125 path=prefix, |
|
126 interpreter=interpreter, |
|
127 environment_type=Conda.EnvironmentType, |
|
128 ) |
|
129 ) |
|
130 |
|
131 def deleteCondaVirtualEnvironment(self, venvMetaData): |
|
132 """ |
|
133 Public method to delete a given anaconda/miniconda environment from disk. |
|
134 |
|
135 Note: This method is used by the Virtual Environment Manager. |
|
136 |
|
137 @param venvMetaData virtual environment meta data structure |
|
138 @type VirtualenvMetaData |
|
139 @return flag indicating success |
|
140 @rtype bool |
|
141 """ |
|
142 return self.removeCondaEnvironment(prefix=venvMetaData.path) |
54 |
143 |
55 def createCondaEnvironment(self, arguments): |
144 def createCondaEnvironment(self, arguments): |
56 """ |
145 """ |
57 Public method to create a conda environment. |
146 Public method to create a conda environment. |
58 |
147 |