From 2b428d5de09659220b7b94d793fdce401ed9d2bf Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 9 Jun 2022 15:29:11 +0200 Subject: Python: prefer python from path when detecting python for document Change-Id: I794a741fa7257833f0b4efbc25dfae43b8748427 Reviewed-by: Christian Stenger --- src/plugins/python/pythonutils.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/plugins/python/pythonutils.cpp') diff --git a/src/plugins/python/pythonutils.cpp b/src/plugins/python/pythonutils.cpp index fdecc5e37c..08c8750c21 100644 --- a/src/plugins/python/pythonutils.cpp +++ b/src/plugins/python/pythonutils.cpp @@ -47,18 +47,20 @@ namespace Internal { FilePath detectPython(const FilePath &documentPath) { - PythonProject *project = documentPath.isEmpty() - ? nullptr - : qobject_cast( - SessionManager::projectForFile(documentPath)); + Project *project = documentPath.isEmpty() ? nullptr + : SessionManager::projectForFile(documentPath); if (!project) - project = qobject_cast(SessionManager::startupProject()); + project = SessionManager::startupProject(); + + Environment env = Environment::systemEnvironment(); if (project) { if (auto target = project->activeTarget()) { if (auto runConfig = target->activeRunConfiguration()) { if (auto interpreter = runConfig->aspect()) return interpreter->currentInterpreter().command; + if (auto environmentAspect = runConfig->aspect()) + env = environmentAspect->environment(); } } } @@ -72,6 +74,14 @@ FilePath detectPython(const FilePath &documentPath) if (defaultInterpreter.exists()) return defaultInterpreter; + const FilePath python3FromPath = env.searchInPath("python3"); + if (python3FromPath.exists()) + return python3FromPath; + + const FilePath pythonFromPath = env.searchInPath("python"); + if (pythonFromPath.exists()) + return pythonFromPath; + return PythonSettings::interpreters().value(0).command; } -- cgit v1.2.1