mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 03:16:10 +00:00
Add --pythonhome Arg
This commit is contained in:
parent
5bb1a5be6c
commit
1d583fe441
@ -9,6 +9,10 @@
|
||||
#include <QStringList>
|
||||
#include <QProcess>
|
||||
|
||||
#ifdef CUTTER_ENABLE_JUPYTER
|
||||
#include "utils/JupyterConnection.h"
|
||||
#endif
|
||||
|
||||
CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc, argv){
|
||||
setOrganizationName("Cutter");
|
||||
setApplicationName("Cutter");
|
||||
@ -32,6 +36,11 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
|
||||
QObject::tr("level"));
|
||||
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);
|
||||
|
||||
QStringList args = cmd_parser.positionalArguments();
|
||||
@ -50,6 +59,13 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef CUTTER_ENABLE_JUPYTER
|
||||
if (cmd_parser.isSet(pythonHomeOption))
|
||||
{
|
||||
Jupyter()->setPythonHome(cmd_parser.value(pythonHomeOption));
|
||||
}
|
||||
#endif
|
||||
|
||||
bool analLevelSpecified = false;
|
||||
int analLevel= 0;
|
||||
|
||||
|
@ -52,21 +52,29 @@ JupyterConnection::~JupyterConnection()
|
||||
void JupyterConnection::initPython()
|
||||
{
|
||||
#if defined(APPIMAGE) || defined(MACOS_PYTHON_FRAMEWORK_BUNDLED)
|
||||
auto pythonHomeDir = QDir(QCoreApplication::applicationDirPath());
|
||||
if(customPythonHome.isNull())
|
||||
{
|
||||
auto pythonHomeDir = QDir(QCoreApplication::applicationDirPath());
|
||||
# ifdef APPIMAGE
|
||||
// Executable is in appdir/bin
|
||||
pythonHomeDir.cdUp();
|
||||
qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for AppImage.";
|
||||
// Executable is in appdir/bin
|
||||
pythonHomeDir.cdUp();
|
||||
qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for AppImage.";
|
||||
# else // MACOS_PYTHON_FRAMEWORK_BUNDLED
|
||||
// @executable_path/../Frameworks/Python.framework/Versions/Current
|
||||
pythonHomeDir.cd("../Frameworks/Python.framework/Versions/Current");
|
||||
qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for macOS Application Bundle.";
|
||||
// @executable_path/../Frameworks/Python.framework/Versions/Current
|
||||
pythonHomeDir.cd("../Frameworks/Python.framework/Versions/Current");
|
||||
qInfo() << "Setting PYTHONHOME =" << pythonHomeDir.absolutePath() << " for macOS Application Bundle.";
|
||||
# endif
|
||||
QString pythonHomeStr = pythonHomeDir.absolutePath();
|
||||
pythonHome = Py_DecodeLocale(pythonHomeStr.toLocal8Bit().constData(), nullptr);
|
||||
Py_SetPythonHome(pythonHome);
|
||||
customPythonHome = pythonHomeDir.absolutePath();
|
||||
}
|
||||
#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_internal", &PyInit_api_internal);
|
||||
Py_Initialize();
|
||||
|
@ -25,6 +25,8 @@ public:
|
||||
JupyterConnection(QObject *parent = nullptr);
|
||||
~JupyterConnection();
|
||||
|
||||
void setPythonHome(const QString pythonHome) { customPythonHome = pythonHome; }
|
||||
|
||||
void start();
|
||||
QString getUrl();
|
||||
|
||||
@ -45,6 +47,8 @@ private:
|
||||
QMap<long, NestedIPyKernel *> kernels;
|
||||
long nextKernelId = 1;
|
||||
|
||||
QString customPythonHome;
|
||||
|
||||
wchar_t *pythonHome = nullptr;
|
||||
|
||||
void initPython();
|
||||
|
Loading…
Reference in New Issue
Block a user