|
13 | 13 |
|
14 | 14 | #include <QAction>
|
15 | 15 | #include <QtCore/QDebug>
|
| 16 | +#include <QtCore/QFileInfo> |
| 17 | +#include <QtCore/QProcess> |
16 | 18 | #include <QtCore/QSettings>
|
17 | 19 | #include <QtCore/QSysInfo>
|
18 | 20 | #include <QtCore/QUrl>
|
@@ -148,11 +150,39 @@ QStringList ConfigurePython::pythonPaths() const
|
148 | 150 |
|
149 | 151 | QStringList paths = findExecutablePaths(names);
|
150 | 152 |
|
151 |
| - // Add the current interpreter to the list if it's not already there. |
152 |
| - if (!paths.contains(pythonInterp)) |
| 153 | + // Add the current interpreter to the list |
| 154 | + // it may be filtered out by the loop below |
| 155 | + if (!paths.contains(pythonInterp)) { |
153 | 156 | paths.prepend(pythonInterp);
|
| 157 | + } |
| 158 | + |
| 159 | + // check to make sure each of the items are valid or remove them |
| 160 | + // (i.e., the python should return a version flag) |
| 161 | + QStringList validPaths; |
| 162 | + QStringList arguments; |
| 163 | + arguments << "-V"; |
| 164 | + foreach (const QString& path, paths) { |
| 165 | + QFileInfo info(path); |
| 166 | + if (info.exists() && info.isExecutable()) { |
| 167 | + // try to run it to get the version |
| 168 | + QProcess process; |
| 169 | + process.start(path, arguments); |
| 170 | + if (process.waitForFinished()) { |
| 171 | + QString output = process.readAllStandardOutput(); |
| 172 | + // should be like Python 3.10.14 |
| 173 | + if (output.startsWith("Python")) { |
| 174 | + QString version = output.split(" ").at(1).simplified(); |
| 175 | + // make sure it's at least Python 3 |
| 176 | + // in the future, we can ensure particular releases |
| 177 | + if (version.startsWith("3")) |
| 178 | + validPaths << path; |
| 179 | + } |
| 180 | + } |
| 181 | + // if we didn't get results, it's not valid |
| 182 | + } |
| 183 | + } |
154 | 184 |
|
155 |
| - return paths; |
| 185 | + return validPaths; |
156 | 186 | }
|
157 | 187 |
|
158 | 188 | void ConfigurePython::showDialog()
|
|
0 commit comments