|
|
@ -44,6 +44,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "base/global.h" |
|
|
|
#include "base/global.h" |
|
|
|
#include "base/logger.h" |
|
|
|
#include "base/logger.h" |
|
|
|
|
|
|
|
#include "base/path.h" |
|
|
|
|
|
|
|
#include "base/preferences.h" |
|
|
|
#include "base/utils/bytearray.h" |
|
|
|
#include "base/utils/bytearray.h" |
|
|
|
|
|
|
|
|
|
|
|
using namespace Utils::ForeignApps; |
|
|
|
using namespace Utils::ForeignApps; |
|
|
@ -52,6 +54,8 @@ namespace |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool testPythonInstallation(const QString &exeName, PythonInfo &info) |
|
|
|
bool testPythonInstallation(const QString &exeName, PythonInfo &info) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
info = {}; |
|
|
|
|
|
|
|
|
|
|
|
QProcess proc; |
|
|
|
QProcess proc; |
|
|
|
proc.start(exeName, {u"--version"_s}, QIODevice::ReadOnly); |
|
|
|
proc.start(exeName, {u"--version"_s}, QIODevice::ReadOnly); |
|
|
|
if (proc.waitForFinished() && (proc.exitCode() == QProcess::NormalExit)) |
|
|
|
if (proc.waitForFinished() && (proc.exitCode() == QProcess::NormalExit)) |
|
|
@ -77,7 +81,7 @@ namespace |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
info = {exeName, version}; |
|
|
|
info = {exeName, version}; |
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Python detected, executable name: '%1', version: %2") |
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Found Python executable. Name: \"%1\". Version: \"%2\"") |
|
|
|
.arg(info.executableName, info.version.toString()), Log::INFO); |
|
|
|
.arg(info.executableName, info.version.toString()), Log::INFO); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -254,20 +258,43 @@ bool Utils::ForeignApps::PythonInfo::isSupportedVersion() const |
|
|
|
PythonInfo Utils::ForeignApps::pythonInfo() |
|
|
|
PythonInfo Utils::ForeignApps::pythonInfo() |
|
|
|
{ |
|
|
|
{ |
|
|
|
static PythonInfo pyInfo; |
|
|
|
static PythonInfo pyInfo; |
|
|
|
if (!pyInfo.isValid()) |
|
|
|
|
|
|
|
|
|
|
|
const QString preferredPythonPath = Preferences::instance()->getPythonExecutablePath().toString(); |
|
|
|
|
|
|
|
if (pyInfo.isValid() && (preferredPythonPath == pyInfo.executableName)) |
|
|
|
|
|
|
|
return pyInfo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!preferredPythonPath.isEmpty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (testPythonInstallation(u"python3"_s, pyInfo)) |
|
|
|
if (testPythonInstallation(preferredPythonPath, pyInfo)) |
|
|
|
return pyInfo; |
|
|
|
return pyInfo; |
|
|
|
|
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Failed to find Python executable. Path: \"%1\".") |
|
|
|
|
|
|
|
.arg(preferredPythonPath), Log::WARNING); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// auto detect only when there are no preferred python path
|
|
|
|
|
|
|
|
|
|
|
|
if (testPythonInstallation(u"python"_s, pyInfo)) |
|
|
|
if (!pyInfo.isValid()) |
|
|
|
return pyInfo; |
|
|
|
{ |
|
|
|
|
|
|
|
if (testPythonInstallation(u"python3"_s, pyInfo)) |
|
|
|
|
|
|
|
return pyInfo; |
|
|
|
|
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Failed to find `python3` executable in PATH environment variable. PATH: \"%1\"") |
|
|
|
|
|
|
|
.arg(qEnvironmentVariable("PATH")), Log::INFO); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (testPythonInstallation(u"python"_s, pyInfo)) |
|
|
|
|
|
|
|
return pyInfo; |
|
|
|
|
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Failed to find `python` executable in PATH environment variable. PATH: \"%1\"") |
|
|
|
|
|
|
|
.arg(qEnvironmentVariable("PATH")), Log::INFO); |
|
|
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN) |
|
|
|
#if defined(Q_OS_WIN) |
|
|
|
if (testPythonInstallation(findPythonPath(), pyInfo)) |
|
|
|
if (testPythonInstallation(findPythonPath(), pyInfo)) |
|
|
|
return pyInfo; |
|
|
|
return pyInfo; |
|
|
|
|
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Failed to find `python` executable in Windows Registry."), Log::INFO); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Python not detected"), Log::INFO); |
|
|
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Failed to find Python executable"), Log::WARNING); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return pyInfo; |
|
|
|
return pyInfo; |
|
|
|