Skip to content

Commit 41aab59

Browse files
prascletmontaigu
authored andcommitted
embedded python
bundle or system or local
1 parent f4c050c commit 41aab59

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/PythonConfig.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static QString PathToPythonExecutableInEnv(PythonConfig::Type envType, const QSt
171171

172172
void PythonConfig::initDefault()
173173
{
174-
#ifdef Q_OS_WIN32
174+
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
175175
initBundled();
176176
#else
177177
// On Non windows platform
@@ -180,10 +180,14 @@ void PythonConfig::initDefault()
180180
#endif
181181
}
182182

183-
#ifdef Q_OS_WIN32
183+
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
184184
void PythonConfig::initBundled()
185185
{
186+
#if defined(Q_OS_MACOS)
187+
const QString pythonEnvDirPath(QApplication::applicationDirPath() + "/../Resources/python");
188+
#else
186189
const QString pythonEnvDirPath(QApplication::applicationDirPath() + "/plugins/Python");
190+
#endif
187191
initFromLocation(pythonEnvDirPath);
188192
}
189193
#endif
@@ -231,6 +235,22 @@ void PythonConfig::initFromLocation(const QString &prefix)
231235
}
232236
}
233237
else
238+
#if defined(Q_OS_MACOS)
239+
{
240+
QString pythonExePath = PathToPythonExecutableInEnv(Type::Unknown, prefix);
241+
initFromPythonExecutable(pythonExePath);
242+
if (m_pythonHome.isEmpty() && m_pythonPath.isEmpty())
243+
{
244+
qDebug() << "Failed to get paths info from python executable at (bundled)"
245+
<< pythonExePath;
246+
initVenv(envRoot.path());
247+
}
248+
else
249+
{
250+
m_type = Type::Unknown;
251+
}
252+
}
253+
#else
234254
{
235255
m_pythonHome = envRoot.path();
236256
m_pythonPath = QString("%1/DLLs;%1/lib;%1/Lib/site-packages;").arg(m_pythonHome);
@@ -240,6 +260,7 @@ void PythonConfig::initFromLocation(const QString &prefix)
240260
m_pythonPath.append(WindowsBundledSitePackagesPath());
241261
#endif
242262
}
263+
#endif
243264
}
244265

245266
void PythonConfig::initCondaEnv(const QString &condaPrefix)

src/PythonConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class PythonConfig final
154154
/// # Other Platforms
155155
/// Does nothing, as we rely on the system's python to be properly installed
156156
void initDefault();
157-
#ifdef Q_OS_WIN32
157+
#if defined(Q_OS_WIN32) || defined(Q_OS_MACOS)
158158
/// Initialize the paths to point to where the Python
159159
/// environment was bundled on a Windows installation
160160
void initBundled();

src/PythonRuntimeSettings.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ PythonRuntimeSettings::PythonRuntimeSettings(QWidget *parent)
144144
{
145145
m_ui->setupUi(this);
146146
m_ui->localEnvSettingsWidget->hide();
147-
#if defined(Q_OS_WIN)
147+
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
148148
m_ui->envTypeComboBox->addItem("Bundled");
149-
#else
149+
#endif
150+
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
150151
m_ui->envTypeComboBox->addItem("System");
151152
#endif
152153
m_ui->envTypeComboBox->addItem("Local");
@@ -264,7 +265,7 @@ PythonConfig PythonRuntimeSettings::pythonEnvConfig() const
264265
config.initDefault();
265266
return config;
266267
}
267-
#if defined(Q_OS_WINDOWS)
268+
#if defined(Q_OS_WINDOWS) || defined(Q_OS_MACOS)
268269
if (selectedEnvType() == "Bundled")
269270
{
270271
PythonConfig config;

0 commit comments

Comments
 (0)