mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 10:56:11 +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:
|
||||
- cmd: git submodule update --init
|
||||
- cmd: python scripts\compile_python_resources.py
|
||||
|
||||
# Build config
|
||||
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
|
||||
|
||||
#include <Python.h>
|
||||
#include <marshal.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
@ -85,13 +86,23 @@ void JupyterConnection::createCutterJupyterModule()
|
||||
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);
|
||||
QByteArray moduleCode = moduleFile.readAll();
|
||||
moduleFile.close();
|
||||
|
||||
auto moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_jupyter.py",
|
||||
Py_file_input);
|
||||
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);
|
||||
}
|
||||
if (!moduleCodeObject) {
|
||||
PyErr_Print();
|
||||
qWarning() << "Could not compile cutter_jupyter.";
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifdef CUTTER_ENABLE_JUPYTER
|
||||
|
||||
#include <Python.h>
|
||||
#include <marshal.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <csignal>
|
||||
@ -19,13 +20,23 @@ NestedIPyKernel *NestedIPyKernel::start(const QStringList &argv)
|
||||
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);
|
||||
QByteArray moduleCode = moduleFile.readAll();
|
||||
moduleFile.close();
|
||||
|
||||
auto moduleCodeObject = Py_CompileString(moduleCode.constData(), "cutter_ipykernel.py",
|
||||
Py_file_input);
|
||||
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);
|
||||
}
|
||||
if (!moduleCodeObject) {
|
||||
qWarning() << "Could not compile cutter_ipykernel.";
|
||||
return nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user