From 26372392d8986f90b95c203032d2b2ec43877a41 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 12 Sep 2024 15:13:42 +0200 Subject: [PATCH] Python: Allow kit creation for virtual environments This had been intentionally disabled before, but we still should permit to explicitly create a kit for a registered virtual environment if the user requests so. Change-Id: I677c0c5093bedd1a9f50e73da173db09195e128e Reviewed-by: David Schulz --- src/plugins/python/pythonsettings.cpp | 19 ++++++++++--------- src/plugins/python/pythonsettings.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/plugins/python/pythonsettings.cpp b/src/plugins/python/pythonsettings.cpp index ba74146053e..b53977c3966 100644 --- a/src/plugins/python/pythonsettings.cpp +++ b/src/plugins/python/pythonsettings.cpp @@ -580,7 +580,7 @@ void InterpreterOptionsWidget::generateKit() { const QModelIndex &index = m_view->currentIndex(); if (index.isValid()) - PythonSettings::addKitsForInterpreter(m_model.itemAt(index.row())->itemData); + PythonSettings::addKitsForInterpreter(m_model.itemAt(index.row())->itemData, true); m_generateKitButton->setEnabled(false); } @@ -808,19 +808,20 @@ static void setRelevantAspectsToKit(Kit *k) k->setRelevantAspects(relevantAspects); } -void PythonSettings::addKitsForInterpreter(const Interpreter &interpreter) +void PythonSettings::addKitsForInterpreter(const Interpreter &interpreter, bool force) { if (!KitManager::isLoaded()) { - connect(KitManager::instance(), &KitManager::kitsLoaded, settingsInstance, [interpreter]() { - addKitsForInterpreter(interpreter); - }); + connect(KitManager::instance(), + &KitManager::kitsLoaded, + settingsInstance, + [interpreter, force]() { addKitsForInterpreter(interpreter, force); }); return; } const Id kitId = Id::fromString(interpreter.id); if (Kit *k = KitManager::kit(kitId)) { setRelevantAspectsToKit(k); - } else if (!isVenvPython(interpreter.command)) { + } else if (force || !isVenvPython(interpreter.command)) { KitManager::registerKit( [interpreter](Kit *k) { k->setAutoDetected(true); @@ -856,7 +857,7 @@ void PythonSettings::setInterpreter(const QList &interpreters, cons QList toRemove = settingsInstance->m_interpreters; for (const Interpreter &interpreter : interpreters) { if (!Utils::eraseOne(toRemove, Utils::equal(&Interpreter::id, interpreter.id))) - addKitsForInterpreter(interpreter); + addKitsForInterpreter(interpreter, false); } for (const Interpreter &interpreter : toRemove) removeKitsForInterpreter(interpreter); @@ -901,7 +902,7 @@ void PythonSettings::addInterpreter(const Interpreter &interpreter, bool isDefau if (isDefault) settingsInstance->m_defaultInterpreterId = interpreter.id; saveSettings(); - addKitsForInterpreter(interpreter); + addKitsForInterpreter(interpreter, false); } Interpreter PythonSettings::addInterpreter(const FilePath &interpreterPath, @@ -1071,7 +1072,7 @@ void PythonSettings::initFromSettings(QtcSettings *settings) if (cmd.needsDevice() || cmd.parentDir().pathAppended("activate").exists()) continue; } - addKitsForInterpreter(interpreter); + addKitsForInterpreter(interpreter, false); } } else { fixupPythonKits(); diff --git a/src/plugins/python/pythonsettings.h b/src/plugins/python/pythonsettings.h index ab5d092a5ff..6419335a32f 100644 --- a/src/plugins/python/pythonsettings.h +++ b/src/plugins/python/pythonsettings.h @@ -43,7 +43,7 @@ public: const Utils::FilePath &directory, const std::function &callback = {}); static QList detectPythonVenvs(const Utils::FilePath &path); - static void addKitsForInterpreter(const Interpreter &interpreter); + static void addKitsForInterpreter(const Interpreter &interpreter, bool force); static void removeKitsForInterpreter(const Interpreter &interpreter); signals: