Add --pythonhome Arg

This commit is contained in:
Florian Märkl 2018-03-06 18:21:42 +01:00
parent 5bb1a5be6c
commit 1d583fe441
3 changed files with 38 additions and 10 deletions

View File

@ -9,6 +9,10 @@
#include <QStringList> #include <QStringList>
#include <QProcess> #include <QProcess>
#ifdef CUTTER_ENABLE_JUPYTER
#include "utils/JupyterConnection.h"
#endif
CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc, argv){ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc, argv){
setOrganizationName("Cutter"); setOrganizationName("Cutter");
setApplicationName("Cutter"); setApplicationName("Cutter");
@ -32,6 +36,11 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
QObject::tr("level")); QObject::tr("level"));
cmd_parser.addOption(analOption); cmd_parser.addOption(analOption);
#ifdef CUTTER_ENABLE_JUPYTER
QCommandLineOption pythonHomeOption("pythonhome", QObject::tr("PYTHONHOME to use for Jupyter"), "PYTHONHOME");
cmd_parser.addOption(pythonHomeOption);
#endif
cmd_parser.process(*this); cmd_parser.process(*this);
QStringList args = cmd_parser.positionalArguments(); QStringList args = cmd_parser.positionalArguments();
@ -50,6 +59,13 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
exit(1); exit(1);
} }
#ifdef CUTTER_ENABLE_JUPYTER
if (cmd_parser.isSet(pythonHomeOption))
{
Jupyter()->setPythonHome(cmd_parser.value(pythonHomeOption));
}
#endif
bool analLevelSpecified = false; bool analLevelSpecified = false;
int analLevel= 0; int analLevel= 0;

View File

@ -52,21 +52,29 @@ JupyterConnection::~JupyterConnection()
void JupyterConnection::initPython() void JupyterConnection::initPython()
{ {
#if defined(APPIMAGE) || defined(MACOS_PYTHON_FRAMEWORK_BUNDLED) #if defined(APPIMAGE) || defined(MACOS_PYTHON_FRAMEWORK_BUNDLED)
auto pythonHomeDir = QDir(QCoreApplication::applicationDirPath()); if(customPythonHome.isNull())
{
auto pythonHomeDir = QDir(QCoreApplication::applicationDirPath());
# ifdef APPIMAGE # ifdef APPIMAGE
// Executable is in appdir/bin // Executable is in appdir/bin
pythonHomeDir.cdUp(); pythonHomeDir.cdUp();
qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for AppImage."; qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for AppImage.";
# else // MACOS_PYTHON_FRAMEWORK_BUNDLED # else // MACOS_PYTHON_FRAMEWORK_BUNDLED
// @executable_path/../Frameworks/Python.framework/Versions/Current // @executable_path/../Frameworks/Python.framework/Versions/Current
pythonHomeDir.cd("../Frameworks/Python.framework/Versions/Current"); pythonHomeDir.cd("../Frameworks/Python.framework/Versions/Current");
qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for macOS Application Bundle."; qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for macOS Application Bundle.";
# endif # endif
QString pythonHomeStr = pythonHomeDir.absolutePath(); customPythonHome = pythonHomeDir.absolutePath();
pythonHome = Py_DecodeLocale(pythonHomeStr.toLocal8Bit().constData(), nullptr); }
Py_SetPythonHome(pythonHome);
#endif #endif
if(!customPythonHome.isNull())
{
qInfo() << "PYTHONHOME =" << customPythonHome;
pythonHome = Py_DecodeLocale(customPythonHome.toLocal8Bit().constData(), nullptr);
Py_SetPythonHome(pythonHome);
}
PyImport_AppendInittab("cutter", &PyInit_api); PyImport_AppendInittab("cutter", &PyInit_api);
PyImport_AppendInittab("cutter_internal", &PyInit_api_internal); PyImport_AppendInittab("cutter_internal", &PyInit_api_internal);
Py_Initialize(); Py_Initialize();

View File

@ -25,6 +25,8 @@ public:
JupyterConnection(QObject *parent = nullptr); JupyterConnection(QObject *parent = nullptr);
~JupyterConnection(); ~JupyterConnection();
void setPythonHome(const QString pythonHome) { customPythonHome = pythonHome; }
void start(); void start();
QString getUrl(); QString getUrl();
@ -45,6 +47,8 @@ private:
QMap<long, NestedIPyKernel *> kernels; QMap<long, NestedIPyKernel *> kernels;
long nextKernelId = 1; long nextKernelId = 1;
QString customPythonHome;
wchar_t *pythonHome = nullptr; wchar_t *pythonHome = nullptr;
void initPython(); void initPython();