summaryrefslogtreecommitdiff
path: root/src/plugins/python/pythonutils.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-06-09 15:21:35 +0200
committerDavid Schulz <david.schulz@qt.io>2022-06-15 05:44:42 +0000
commit02bfd03c226a15d2ed90ca43580df7e099e310a6 (patch)
tree954fa15c5b3f9983b2225cdf7e788a542fe6764b /src/plugins/python/pythonutils.cpp
parent3341fa827f9fee6812b15bcb8eefb41211358958 (diff)
downloadqt-creator-02bfd03c226a15d2ed90ca43580df7e099e310a6.tar.gz
Python: simplify detect python for document path
Change-Id: I49b943e8b89db32c11b12ee66c0ad3add9a695af Reviewed-by: Christian Stenger <christian.stenger@qt.io>
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)