mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Little hack to distribute precompiled cutter_*.py files (#465)
This commit is contained in:
parent
5e4dff9639
commit
eeec725b94
@ -46,6 +46,7 @@ install:
|
|||||||
|
|
||||||
before_build:
|
before_build:
|
||||||
- cmd: git submodule update --init
|
- cmd: git submodule update --init
|
||||||
|
- cmd: python scripts\compile_python_resources.py
|
||||||
|
|
||||||
# Build config
|
# Build config
|
||||||
build_script:
|
build_script:
|
||||||
|
10
scripts/compile_python_resources.py
Normal file
10
scripts/compile_python_resources.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import compileall
|
||||||
|
import os
|
||||||
|
|
||||||
|
root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
|
||||||
|
compileall.compile_dir(os.path.join(root, 'src', 'python'), legacy=True, optimize=2)
|
||||||
|
with open(os.path.join(root, 'src', 'resources.qrc'), 'r+b') as f:
|
||||||
|
data = f.read()
|
||||||
|
data = data.replace(b'.py<', b'.pyc<')
|
||||||
|
f.seek(0)
|
||||||
|
f.write(data)
|
@ -1,6 +1,7 @@
|
|||||||
#ifdef CUTTER_ENABLE_JUPYTER
|
#ifdef CUTTER_ENABLE_JUPYTER
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
#include <marshal.h>
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
@ -85,13 +86,23 @@ void JupyterConnection::createCutterJupyterModule()
|
|||||||
PyEval_RestoreThread(pyThreadState);
|
PyEval_RestoreThread(pyThreadState);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile moduleFile(":/python/cutter_jupyter.py");
|
QFile moduleFile(":/python/cutter_jupyter.pyc");
|
||||||
|
bool isBytecode = moduleFile.exists();
|
||||||
|
if (!isBytecode) {
|
||||||
|
moduleFile.setFileName(":/python/cutter_jupyter.py");
|
||||||
|
}
|
||||||
moduleFile.open(QIODevice::ReadOnly);
|
moduleFile.open(QIODevice::ReadOnly);
|
||||||
QByteArray moduleCode = moduleFile.readAll();
|
QByteArray moduleCode = moduleFile.readAll();
|
||||||
moduleFile.close();
|
moduleFile.close();
|
||||||
|
|
||||||
auto moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_jupyter.py",
|
PyObject *moduleCodeObject;
|
||||||
|
if (isBytecode) {
|
||||||
|
moduleCodeObject = PyMarshal_ReadObjectFromString(moduleCode.constData() + 12,
|
||||||
|
moduleCode.size() - 12);
|
||||||
|
} else {
|
||||||
|
moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_jupyter.py",
|
||||||
Py_file_input);
|
Py_file_input);
|
||||||
|
}
|
||||||
if (!moduleCodeObject) {
|
if (!moduleCodeObject) {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
qWarning() << "Could not compile cutter_jupyter.";
|
qWarning() << "Could not compile cutter_jupyter.";
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#ifdef CUTTER_ENABLE_JUPYTER
|
#ifdef CUTTER_ENABLE_JUPYTER
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
#include <marshal.h>
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
@ -19,13 +20,23 @@ NestedIPyKernel *NestedIPyKernel::start(const QStringList &argv)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile moduleFile(":/python/cutter_ipykernel.py");
|
QFile moduleFile(":/python/cutter_ipykernel.pyc");
|
||||||
|
bool isBytecode = moduleFile.exists();
|
||||||
|
if (!isBytecode) {
|
||||||
|
moduleFile.setFileName(":/python/cutter_ipykernel.py");
|
||||||
|
}
|
||||||
moduleFile.open(QIODevice::ReadOnly);
|
moduleFile.open(QIODevice::ReadOnly);
|
||||||
QByteArray moduleCode = moduleFile.readAll();
|
QByteArray moduleCode = moduleFile.readAll();
|
||||||
moduleFile.close();
|
moduleFile.close();
|
||||||
|
|
||||||
auto moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_ipykernel.py",
|
PyObject *moduleCodeObject;
|
||||||
|
if (isBytecode) {
|
||||||
|
moduleCodeObject = PyMarshal_ReadObjectFromString(moduleCode.constData() + 12,
|
||||||
|
moduleCode.size() - 12);
|
||||||
|
} else {
|
||||||
|
moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_ipykernel.py",
|
||||||
Py_file_input);
|
Py_file_input);
|
||||||
|
}
|
||||||
if (!moduleCodeObject) {
|
if (!moduleCodeObject) {
|
||||||
qWarning() << "Could not compile cutter_ipykernel.";
|
qWarning() << "Could not compile cutter_ipykernel.";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user