forked from qt-creator/qt-creator
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:
@@ -580,7 +580,7 @@ void InterpreterOptionsWidget::generateKit()
|
|||||||
{
|
{
|
||||||
const QModelIndex &index = m_view->currentIndex();
|
const QModelIndex &index = m_view->currentIndex();
|
||||||
if (index.isValid())
|
if (index.isValid())
|
||||||
PythonSettings::addKitsForInterpreter(m_model.itemAt(index.row())->itemData);
|
PythonSettings::addKitsForInterpreter(m_model.itemAt(index.row())->itemData, true);
|
||||||
m_generateKitButton->setEnabled(false);
|
m_generateKitButton->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -808,19 +808,20 @@ static void setRelevantAspectsToKit(Kit *k)
|
|||||||
k->setRelevantAspects(relevantAspects);
|
k->setRelevantAspects(relevantAspects);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PythonSettings::addKitsForInterpreter(const Interpreter &interpreter)
|
void PythonSettings::addKitsForInterpreter(const Interpreter &interpreter, bool force)
|
||||||
{
|
{
|
||||||
if (!KitManager::isLoaded()) {
|
if (!KitManager::isLoaded()) {
|
||||||
connect(KitManager::instance(), &KitManager::kitsLoaded, settingsInstance, [interpreter]() {
|
connect(KitManager::instance(),
|
||||||
addKitsForInterpreter(interpreter);
|
&KitManager::kitsLoaded,
|
||||||
});
|
settingsInstance,
|
||||||
|
[interpreter, force]() { addKitsForInterpreter(interpreter, force); });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Id kitId = Id::fromString(interpreter.id);
|
const Id kitId = Id::fromString(interpreter.id);
|
||||||
if (Kit *k = KitManager::kit(kitId)) {
|
if (Kit *k = KitManager::kit(kitId)) {
|
||||||
setRelevantAspectsToKit(k);
|
setRelevantAspectsToKit(k);
|
||||||
} else if (!isVenvPython(interpreter.command)) {
|
} else if (force || !isVenvPython(interpreter.command)) {
|
||||||
KitManager::registerKit(
|
KitManager::registerKit(
|
||||||
[interpreter](Kit *k) {
|
[interpreter](Kit *k) {
|
||||||
k->setAutoDetected(true);
|
k->setAutoDetected(true);
|
||||||
@@ -856,7 +857,7 @@ void PythonSettings::setInterpreter(const QList<Interpreter> &interpreters, cons
|
|||||||
QList<Interpreter> toRemove = settingsInstance->m_interpreters;
|
QList<Interpreter> toRemove = settingsInstance->m_interpreters;
|
||||||
for (const Interpreter &interpreter : interpreters) {
|
for (const Interpreter &interpreter : interpreters) {
|
||||||
if (!Utils::eraseOne(toRemove, Utils::equal(&Interpreter::id, interpreter.id)))
|
if (!Utils::eraseOne(toRemove, Utils::equal(&Interpreter::id, interpreter.id)))
|
||||||
addKitsForInterpreter(interpreter);
|
addKitsForInterpreter(interpreter, false);
|
||||||
}
|
}
|
||||||
for (const Interpreter &interpreter : toRemove)
|
for (const Interpreter &interpreter : toRemove)
|
||||||
removeKitsForInterpreter(interpreter);
|
removeKitsForInterpreter(interpreter);
|
||||||
@@ -901,7 +902,7 @@ void PythonSettings::addInterpreter(const Interpreter &interpreter, bool isDefau
|
|||||||
if (isDefault)
|
if (isDefault)
|
||||||
settingsInstance->m_defaultInterpreterId = interpreter.id;
|
settingsInstance->m_defaultInterpreterId = interpreter.id;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
addKitsForInterpreter(interpreter);
|
addKitsForInterpreter(interpreter, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpreter PythonSettings::addInterpreter(const FilePath &interpreterPath,
|
Interpreter PythonSettings::addInterpreter(const FilePath &interpreterPath,
|
||||||
@@ -1071,7 +1072,7 @@ void PythonSettings::initFromSettings(QtcSettings *settings)
|
|||||||
if (cmd.needsDevice() || cmd.parentDir().pathAppended("activate").exists())
|
if (cmd.needsDevice() || cmd.parentDir().pathAppended("activate").exists())
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
addKitsForInterpreter(interpreter);
|
addKitsForInterpreter(interpreter, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fixupPythonKits();
|
fixupPythonKits();
|
||||||
|
@@ -43,7 +43,7 @@ public:
|
|||||||
const Utils::FilePath &directory,
|
const Utils::FilePath &directory,
|
||||||
const std::function<void(const Utils::FilePath &)> &callback = {});
|
const std::function<void(const Utils::FilePath &)> &callback = {});
|
||||||
static QList<Interpreter> detectPythonVenvs(const Utils::FilePath &path);
|
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);
|
static void removeKitsForInterpreter(const Interpreter &interpreter);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
Reference in New Issue
Block a user