From 54f2ebf91d76d05d0202de5263939fc4ba227fed Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 30 Oct 2019 14:33:04 +0100 Subject: Python: cache the module path for executable This reduces ui freezes when switching the interpreter for a python project. Change-Id: Iaa8ce8ed8d51666f8696eb96f504aaf8c4a11822 Reviewed-by: Christian Stenger --- src/plugins/python/pythonutils.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/plugins/python') diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index aa7051b396..dced51518b 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -94,6 +94,11 @@ static QString pythonName(const FilePath &pythonPath) FilePath getPylsModulePath(CommandLine pylsCommand) { + static QMap cache; + const FilePath &modulePath = cache.value(pylsCommand.executable()); + if (!modulePath.isEmpty()) + return modulePath; + pylsCommand.addArg("-h"); SynchronousProcess pythonProcess; pythonProcess.setEnvironment(pythonProcess.environment() + QStringList("PYTHONVERBOSE=x")); @@ -111,8 +116,11 @@ FilePath getPylsModulePath(CommandLine pylsCommand) const QString &output = response.allOutput(); for (auto regex : {regexCached, regexNotCached}) { QRegularExpressionMatch result = regex.match(output); - if (result.hasMatch()) - return FilePath::fromUserInput(result.captured(1)); + if (result.hasMatch()) { + const FilePath &modulePath = FilePath::fromUserInput(result.captured(1)); + cache[pylsCommand.executable()] = modulePath; + return modulePath; + } } return {}; } @@ -146,7 +154,7 @@ static PythonLanguageServerState checkPythonLanguageServer(const FilePath &pytho } } - return {PythonLanguageServerState::AlreadyInstalled, getPylsModulePath(pythonLShelpCommand)}; + return {PythonLanguageServerState::AlreadyInstalled, modulePath}; } const CommandLine pythonPipVersionCommand(python, {"-m", "pip", "-V"}); -- cgit v1.2.1 From 3df6a29d4fab106435c408cea92ba89f17b5d2fb Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 4 Nov 2019 08:51:26 +0100 Subject: Python: remove reference to out of scope variable Change-Id: Idd4dbab5ee01fda331452fefd27de71625afa5af Reviewed-by: Nikolai Kosjar --- src/plugins/python/pythonsettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/python') diff --git a/src/plugins/python/pythonsettings.cpp b/src/plugins/python/pythonsettings.cpp index acb7a50ddd..ab5f024765 100644 --- a/src/plugins/python/pythonsettings.cpp +++ b/src/plugins/python/pythonsettings.cpp @@ -530,7 +530,7 @@ QList PythonSettings::detectPythonVenvs(const FilePath &path) void PythonSettings::saveSettings() { const QList &interpreters = interpreterOptionsPage().interpreters(); - const QString &defaultId = interpreterOptionsPage().defaultInterpreter().id; + const QString defaultId = interpreterOptionsPage().defaultInterpreter().id; toSettings(Core::ICore::settings(), {interpreters, defaultId}); if (QTC_GUARD(settingsInstance)) emit settingsInstance->interpretersChanged(interpreters, defaultId); -- cgit v1.2.1