Python: move python name cache to utils

Change-Id: I7f6d13a465be6de90aea64e7f19c92bca3ee6c19
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-03-16 09:28:01 +01:00
parent b8c8e0ccae
commit ff686f5679
3 changed files with 20 additions and 19 deletions

View File

@@ -77,25 +77,6 @@ struct PythonLanguageServerState
FilePath pylsModulePath;
};
static 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;
}
FilePath getPylsModulePath(CommandLine pylsCommand)
{
static QMutex mutex; // protect the access to the cache