8
8
9
9
#include " ui_configurepythondialog.h"
10
10
11
+ #include < avogadro/qtgui/utilities.h>
12
+
11
13
#include < QDebug>
12
14
#include < QFileInfo>
13
15
#include < QtCore/QProcess>
14
16
#include < QtCore/QSettings>
15
17
18
+ using Avogadro::QtGui::Utilities::findExecutablePaths;
19
+
16
20
namespace Avogadro ::QtPlugins {
17
21
18
22
ConfigurePythonDialog::ConfigurePythonDialog (QWidget* aParent)
@@ -33,8 +37,23 @@ ConfigurePythonDialog::ConfigurePythonDialog(QWidget* aParent)
33
37
QString condaPath =
34
38
settings.value (" interpreters/condaPath" , " conda" ).toString ();
35
39
// check if conda is executable
36
- if (!QFileInfo (condaPath).isExecutable ())
37
- return ;
40
+ if (!QFileInfo (condaPath).isExecutable ()) {
41
+ // see if we can find any related executables in the path
42
+ QStringList names;
43
+ names << " micromamba"
44
+ << " mamba"
45
+ << " conda" ;
46
+ #ifdef Q_OS_WIN
47
+ names << " micromamba.exe"
48
+ << " mamba.exe"
49
+ << " conda.exe" ;
50
+ #endif
51
+ QStringList paths = findExecutablePaths (names);
52
+ if (!paths.isEmpty ()) {
53
+ condaPath = paths.first ();
54
+ } else
55
+ return ; // nothing more to do
56
+ }
38
57
39
58
// set the path to conda
40
59
settings.setValue (" interpreters/condaPath" , condaPath);
@@ -85,8 +104,23 @@ void ConfigurePythonDialog::setupCondaEnvironment()
85
104
QString condaPath =
86
105
settings.value (" interpreters/condaPath" , " conda" ).toString ();
87
106
// check if conda is executable
88
- if (!QFileInfo (condaPath).isExecutable ())
89
- return ;
107
+ if (!QFileInfo (condaPath).isExecutable ()) {
108
+ // see if we can find any related executables in the path
109
+ QStringList names;
110
+ names << " micromamba"
111
+ << " mamba"
112
+ << " conda" ;
113
+ #ifdef Q_OS_WIN
114
+ names << " micromamba.exe"
115
+ << " mamba.exe"
116
+ << " conda.exe" ;
117
+ #endif
118
+ QStringList paths = findExecutablePaths (names);
119
+ if (!paths.isEmpty ()) {
120
+ condaPath = paths.first ();
121
+ } else
122
+ return ; // nothing more to do
123
+ }
90
124
91
125
QStringList arguments;
92
126
arguments << " create"
@@ -122,9 +156,22 @@ void ConfigurePythonDialog::setOptions(const QStringList& options)
122
156
{
123
157
m_ui->environmentCombo ->clear ();
124
158
159
+ // check the current choice from QSettings
160
+ QSettings settings;
161
+ QString currentInterpreter =
162
+ settings.value (" interpreters/python" , QString ()).toString ();
163
+ QString currentConda =
164
+ settings.value (" interpreters/condaEnvironment" , QString ()).toString ();
165
+ int index = -1 ;
166
+
125
167
// add all conda environments
126
168
foreach (const QString& environment, m_condaEnvironments) {
169
+ if (environment.isEmpty ())
170
+ continue ; // shouldn't happen, but just in case
171
+
127
172
m_ui->environmentCombo ->addItem (QString (" %1 (conda)" ).arg (environment));
173
+ if (environment == currentConda)
174
+ index = m_ui->environmentCombo ->count () - 1 ;
128
175
}
129
176
130
177
// get the Python version from each interpreter
@@ -136,7 +183,7 @@ void ConfigurePythonDialog::setOptions(const QStringList& options)
136
183
if (process.waitForFinished ()) {
137
184
QString output = process.readAllStandardOutput ();
138
185
if (output.startsWith (" Python" )) {
139
- versions << output.split (" " ).at (1 );
186
+ versions << output.split (" " ).at (1 ). simplified () ;
140
187
} else {
141
188
versions << tr (" Unknown" );
142
189
}
@@ -148,9 +195,16 @@ void ConfigurePythonDialog::setOptions(const QStringList& options)
148
195
for (int i = 0 ; i < options.size (); ++i) {
149
196
m_ui->environmentCombo ->addItem (
150
197
QString (" %1 (%2)" ).arg (options.at (i)).arg (versions.at (i)));
198
+ // if the conda environment isn't the current, check the python interpreter
199
+ if (options.at (i) == currentInterpreter && index == -1 )
200
+ index = m_ui->environmentCombo ->count () - 1 ;
151
201
}
152
202
153
203
m_ui->environmentCombo ->addItem (tr (" Other…" ));
204
+ // set the current choice
205
+ if (index >= 0 )
206
+ m_ui->environmentCombo ->setCurrentIndex (index );
207
+
154
208
m_ui->browseWidget ->hide ();
155
209
}
156
210
0 commit comments