aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/python/pythonsettings.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2024-12-12 11:50:31 +0100
committerDavid Schulz <david.schulz@qt.io>2025-01-07 13:15:59 +0000
commit94c43600852a0d018cb82f46c6549960f182dca8 (patch)
tree2bc2b8d9a6bb60ffdc829c2f72630d0ccad8f81b /src/plugins/python/pythonsettings.cpp
parent5fa27341fec78c98966b5b5cae97f93824309278 (diff)
Python: optimize the pip and venv checks
Those checks can take an considerable amount of time. So instead of running them the first time we want to check this info run them in the background as soon as we have loaded the python settings. Change-Id: I287acd2a5fd7b053873257238f7dfbaa9cf00170 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/python/pythonsettings.cpp')
-rw-r--r--src/plugins/python/pythonsettings.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/plugins/python/pythonsettings.cpp b/src/plugins/python/pythonsettings.cpp
index e9fbff36b10..bc6eebc7885 100644
--- a/src/plugins/python/pythonsettings.cpp
+++ b/src/plugins/python/pythonsettings.cpp
@@ -855,11 +855,18 @@ QString PythonSettings::pylsConfiguration()
return settingsInstance->m_pylsConfiguration;
}
+static void cacheVenvAndPipUsability(const Interpreter &interpreter)
+{
+ Utils::asyncRun(&venvIsUsable, interpreter.command);
+ Utils::asyncRun(&pipIsUsable, interpreter.command);
+}
+
void PythonSettings::addInterpreter(const Interpreter &interpreter, bool isDefault)
{
if (Utils::anyOf(settingsInstance->m_interpreters, Utils::equal(&Interpreter::id, interpreter.id)))
return;
settingsInstance->m_interpreters.append(interpreter);
+ cacheVenvAndPipUsability(interpreter);
if (isDefault)
settingsInstance->m_defaultInterpreterId = interpreter.id;
saveSettings();
@@ -1026,8 +1033,12 @@ void PythonSettings::initFromSettings(QtcSettings *settings)
const auto [valid, outdatedInterpreters] = Utils::partition(m_interpreters, keepInterpreter);
m_interpreters = valid;
- if (!settings->value(kitsGeneratedKey, false).toBool()) {
- for (const Interpreter &interpreter : m_interpreters) {
+ const bool kitsGenerated = settings->value(kitsGeneratedKey, false).toBool();
+ if (kitsGenerated)
+ fixupPythonKits();
+ for (const Interpreter &interpreter : std::as_const(m_interpreters)) {
+ cacheVenvAndPipUsability(interpreter);
+ if (!kitsGenerated) {
if (interpreter.autoDetected) {
const FilePath &cmd = interpreter.command;
if (!cmd.isLocal() || cmd.parentDir().pathAppended("activate").exists())
@@ -1035,8 +1046,6 @@ void PythonSettings::initFromSettings(QtcSettings *settings)
}
addKitsForInterpreter(interpreter, false);
}
- } else {
- fixupPythonKits();
}
for (const Interpreter &outdated : outdatedInterpreters)