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 <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2024-09-12 15:13:42 +02:00
parent 151f9e7d04
commit 26372392d8
2 changed files with 11 additions and 10 deletions

View File

@@ -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<Interpreter> &interpreters, cons
QList<Interpreter> 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();

View File

@@ -43,7 +43,7 @@ public:
const Utils::FilePath &directory,
const std::function<void(const Utils::FilePath &)> &callback = {});
static QList<Interpreter> 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: