Skip to content

Commit

Permalink
Fix compile error and ensure potential binaries return versions
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis committed Jan 12, 2025
1 parent d8c64c9 commit 7cdd095
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions avogadro/qtplugins/configurepython/configurepython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <QAction>
#include <QtCore/QDebug>
#include <QtCore/QFileInfo>
#include <QtCore/QProcess>
#include <QtCore/QSettings>
#include <QtCore/QSysInfo>
#include <QtCore/QUrl>
Expand Down Expand Up @@ -148,15 +150,39 @@ QStringList ConfigurePython::pythonPaths() const

QStringList paths = findExecutablePaths(names);

// Add the current interpreter to the list if it's not already there
// and it exists as an executable
// Add the current interpreter to the list
// it may be filtered out by the loop below
if (!paths.contains(pythonInterp)) {
QFileInfo info(pythonInterp);
if (info.exists() && info.isExecutable())
paths.prepend(pythonInterp);
paths.prepend(pythonInterp);
}

return paths;
// check to make sure each of the items are valid or remove them
// (i.e., the python should return a version flag)
QStringList validPaths;
QStringList arguments;
arguments << "-V";
foreach (const QString& path, paths) {
QFileInfo info(path);
if (info.exists() && info.isExecutable()) {
// try to run it to get the version
QProcess process;
process.start(path, arguments);
if (process.waitForFinished()) {
QString output = process.readAllStandardOutput();
// should be like Python 3.10.14
if (output.startsWith("Python")) {
QString version = output.split(" ").at(1).simplified();
// make sure it's at least Python 3
// in the future, we can ensure particular releases
if (version.startsWith("3"))
validPaths << path;
}
}
// if we didn't get results, it's not valid
}
}

return validPaths;
}

void ConfigurePython::showDialog()
Expand Down

0 comments on commit 7cdd095

Please sign in to comment.