Python: try to find interpreter on device for run configuration

If the default interpreter is not on the run device of the kit try to
find any interpreter on that device and use it as the default
interpreter for this run configuration.

Change-Id: I52985281f0f1d2ac88759169400d64121299f95d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2022-10-18 10:30:06 +02:00
parent c81a5c0644
commit f012f1b245

View File

@@ -20,6 +20,8 @@
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/buildsystem.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/localenvironmentaspect.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/target.h>
@@ -130,13 +132,23 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Id id)
connect(PythonSettings::instance(), &PythonSettings::interpretersChanged,
interpreterAspect, &InterpreterAspect::updateInterpreters);
QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(
const QList<Interpreter> interpreters = PythonSettings::detectPythonVenvs(
project()->projectDirectory());
interpreterAspect->updateInterpreters(PythonSettings::interpreters());
Interpreter defaultInterpreter = interpreters.isEmpty() ? PythonSettings::defaultInterpreter()
: interpreters.first();
if (!defaultInterpreter.command.isExecutableFile())
defaultInterpreter = PythonSettings::interpreters().value(0);
if (defaultInterpreter.command.isExecutableFile()) {
const IDeviceConstPtr device = DeviceKitAspect::device(target->kit());
if (device && !device->handlesFile(defaultInterpreter.command)) {
defaultInterpreter = Utils::findOr(PythonSettings::interpreters(),
defaultInterpreter,
[device](const Interpreter &interpreter) {
return device->handlesFile(interpreter.command);
});
}
}
interpreterAspect->setDefaultInterpreter(defaultInterpreter);
auto bufferedAspect = addAspect<BoolAspect>();