Python: add pyside build configuration

Task-number: QTCREATORBUG-27219
Change-Id: I19340c57789933c7104ec5d6fec628ed810c5f3e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-03-30 14:42:33 +02:00
parent b0afd728d1
commit fbefd45b94
9 changed files with 250 additions and 19 deletions

View File

@@ -26,6 +26,7 @@
#include "pythonrunconfiguration.h"
#include "pyside.h"
#include "pysidebuildconfiguration.h"
#include "pythonconstants.h"
#include "pythonlanguageclient.h"
#include "pythonproject.h"
@@ -36,6 +37,7 @@
#include <languageclient/languageclientmanager.h>
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
@@ -145,27 +147,21 @@ public:
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
interpreterAspect->setSettingsDialogId(Constants::C_PYTHONOPTIONS_PAGE_ID);
connect(interpreterAspect, &InterpreterAspect::changed, this, [this, interpreterAspect] {
using namespace LanguageClient;
const FilePath python = interpreterAspect->currentInterpreter().command;
for (FilePath &file : project()->files(Project::AllFiles)) {
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
PyLSConfigureAssistant::openDocumentWithPython(python, document);
PySideInstaller::checkPySideInstallation(python, document);
}
}
}
});
connect(interpreterAspect, &InterpreterAspect::changed,
this, &PythonRunConfiguration::currentInterpreterChanged);
connect(PythonSettings::instance(), &PythonSettings::interpretersChanged,
interpreterAspect, &InterpreterAspect::updateInterpreters);
QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(project()->projectDirectory());
QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(
project()->projectDirectory());
interpreterAspect->updateInterpreters(PythonSettings::interpreters());
interpreterAspect->setDefaultInterpreter(
interpreters.isEmpty() ? PythonSettings::defaultInterpreter() : interpreters.first());
Interpreter defaultInterpreter = interpreters.isEmpty()
? PythonSettings::defaultInterpreter()
: interpreters.first();
if (!defaultInterpreter.command.isExecutableFile())
defaultInterpreter = PythonSettings::interpreters().value(0);
interpreterAspect->setDefaultInterpreter(defaultInterpreter);
auto bufferedAspect = addAspect<BoolAspect>();
bufferedAspect->setSettingsKey("PythonEditor.RunConfiguation.Buffered");
@@ -204,6 +200,24 @@ public:
connect(target, &Target::buildSystemUpdated, this, &RunConfiguration::update);
}
void currentInterpreterChanged()
{
const FilePath python = aspect<InterpreterAspect>()->currentInterpreter().command;
BuildStepList *buildSteps = target()->activeBuildConfiguration()->buildSteps();
if (auto pySideBuildStep = buildSteps->firstOfType<PySideBuildStep>())
pySideBuildStep->updateInterpreter(python);
for (FilePath &file : project()->files(Project::AllFiles)) {
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
PyLSConfigureAssistant::openDocumentWithPython(python, document);
PySideInstaller::checkPySideInstallation(python, document);
}
}
}
}
};
PythonRunConfigurationFactory::PythonRunConfigurationFactory()