| 44 | } |
| 45 | |
| 46 | QString Utils::pythonVersion(const QString &python) |
| 47 | { |
| 48 | auto getVersion = [](const QString &output) -> QString { |
| 49 | static QRegularExpression regex(R"((\d{1,3}(?:\.\d{1,3}){0,2}))"); |
| 50 | if (output.isEmpty()) |
| 51 | return ""; |
| 52 | |
| 53 | QRegularExpressionMatch match = regex.match(output); |
| 54 | if (match.hasMatch()) |
| 55 | return match.captured(1); |
| 56 | |
| 57 | return ""; |
| 58 | }; |
| 59 | |
| 60 | QProcess process; |
| 61 | process.start(python, { "--version" }); |
| 62 | process.waitForFinished(); |
| 63 | |
| 64 | QString output = process.readAllStandardOutput(); |
| 65 | QString version = getVersion(output); |
| 66 | if (version.isEmpty()) { |
| 67 | output = process.readAllStandardError(); |
| 68 | version = getVersion(output); |
| 69 | if (version.isEmpty()) { |
| 70 | int index = python.lastIndexOf('/') + 1; |
| 71 | output = python.mid(index, python.length() - index); |
| 72 | version = getVersion(output); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return version; |
| 77 | } |
| 78 | |
| 79 | QString Utils::packageInstallPath(const QString &python) |
| 80 | { |
nothing calls this directly
no test coverage detected