diff options
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r-- | src/plugins/python/pythonutils.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index aff91c7098..5b37cdbf6b 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -127,5 +127,24 @@ void openPythonRepl(QObject *parent, const FilePath &file, ReplType type) process->start(); } +QString pythonName(const FilePath &pythonPath) +{ + static QHash<FilePath, QString> nameForPython; + if (!pythonPath.exists()) + return {}; + QString name = nameForPython.value(pythonPath); + if (name.isEmpty()) { + QtcProcess pythonProcess; + pythonProcess.setTimeoutS(2); + pythonProcess.setCommand({pythonPath, {"--version"}}); + pythonProcess.runBlocking(); + if (pythonProcess.result() != ProcessResult::FinishedWithSuccess) + return {}; + name = pythonProcess.allOutput().trimmed(); + nameForPython[pythonPath] = name; + } + return name; +} + } // namespace Internal } // namespace Python |