summaryrefslogtreecommitdiff
path: root/src/plugins/python/pythonutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/python/pythonutils.cpp')
-rw-r--r--src/plugins/python/pythonutils.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp
index ae4fd3a1f7..fdecc5e37c 100644
--- a/src/plugins/python/pythonutils.cpp
+++ b/src/plugins/python/pythonutils.cpp
@@ -47,8 +47,6 @@ namespace Internal {
FilePath detectPython(const FilePath &documentPath)
{
- FilePath python;
-
PythonProject *project = documentPath.isEmpty()
? nullptr
: qobject_cast<PythonProject *>(
@@ -60,23 +58,21 @@ FilePath detectPython(const FilePath &documentPath)
if (auto target = project->activeTarget()) {
if (auto runConfig = target->activeRunConfiguration()) {
if (auto interpreter = runConfig->aspect<InterpreterAspect>())
- python = interpreter->currentInterpreter().command;
+ return interpreter->currentInterpreter().command;
}
}
}
// check whether this file is inside a python virtual environment
- QList<Interpreter> venvInterpreters = PythonSettings::detectPythonVenvs(documentPath);
- if (!python.exists() && !venvInterpreters.isEmpty())
- python = venvInterpreters.first().command;
-
- if (!python.exists())
- python = PythonSettings::defaultInterpreter().command;
+ const QList<Interpreter> venvInterpreters = PythonSettings::detectPythonVenvs(documentPath);
+ if (!venvInterpreters.isEmpty())
+ return venvInterpreters.first().command;
- if (!python.exists() && !PythonSettings::interpreters().isEmpty())
- python = PythonSettings::interpreters().constFirst().command;
+ auto defaultInterpreter = PythonSettings::defaultInterpreter().command;
+ if (defaultInterpreter.exists())
+ return defaultInterpreter;
- return python;
+ return PythonSettings::interpreters().value(0).command;
}
static QStringList replImportArgs(const FilePath &pythonFile, ReplType type)