From ff686f567900ac45860556253c397425edc05cfc Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 16 Mar 2022 09:28:01 +0100 Subject: [PATCH] Python: move python name cache to utils Change-Id: I7f6d13a465be6de90aea64e7f19c92bca3ee6c19 Reviewed-by: Christian Stenger --- src/plugins/python/pythonlanguageclient.cpp | 19 ------------------- src/plugins/python/pythonutils.cpp | 19 +++++++++++++++++++ src/plugins/python/pythonutils.h | 1 + 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp index fcf1d86b9e0..c4b01462ea9 100644 --- a/src/plugins/python/pythonlanguageclient.cpp +++ b/src/plugins/python/pythonlanguageclient.cpp @@ -77,25 +77,6 @@ struct PythonLanguageServerState FilePath pylsModulePath; }; -static QString pythonName(const FilePath &pythonPath) -{ - static QHash 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 diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index aff91c70986..5b37cdbf6b5 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 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 diff --git a/src/plugins/python/pythonutils.h b/src/plugins/python/pythonutils.h index c33bf456cac..c8844d964ea 100644 --- a/src/plugins/python/pythonutils.h +++ b/src/plugins/python/pythonutils.h @@ -33,6 +33,7 @@ namespace Internal { enum class ReplType { Unmodified, Import, ImportToplevel }; void openPythonRepl(QObject *parent, const Utils::FilePath &file, ReplType type); Utils::FilePath detectPython(const Utils::FilePath &documentPath); +QString pythonName(const Utils::FilePath &pythonPath); } // namespace Internal } // namespace Python