Commit 299ff77f authored by Boxiang Sun's avatar Boxiang Sun

erp5_notebook: Extract pyodide initialization code to a independent function

parent e8cfcaf0
...@@ -423,23 +423,56 @@ ...@@ -423,23 +423,56 @@
} }
function executePyCell(line_list) { function executePyCell(line_list) {
var result_text, code_text = line_list.join('\n'); var result, code_text = line_list.join('\n');
result_text = pyodide.runPython(code_text); result = pyodide.runPython(code_text);
renderCodeblock(result_text); console.log("Result is");
console.log(result);
renderCodeblock(result);
} }
function pyodideSetting() { function pyodideSetting() {
window.pyodide = pyodide(Module); window.pyodide = pyodide(Module);
window.pyodide.loadPackage = pyodideLoadPackage;
var defer = RSVP.defer(), promise = defer.promise; var defer = RSVP.defer(), promise = defer.promise;
Module.postRun = defer.resolve; Module.postRun = defer.resolve;
promise.then(function () { promise.then(function () {
console.log("postRun get called"); console.log("postRun get called");
delete window.Module;
}); });
return defer.promise; return defer.promise;
} }
function initPyodide() {
var queue = new RSVP.Queue();
queue.push(function () {
Module.instantiateWasm = loadPyodide;
window.Module = Module;
})
.push(function () {
return loadJSResource('pyodide.asm.data.js');
})
.push(function () {
return loadJSResource('pyodide.asm.js');
})
.push(function () {
return pyodideSetting();
})
.push(function () {
return fetch(`packages.json`)
})
.push(function (response) {
return response.json();
})
.push(function (json) {
window.pyodide.packages = json;
return;
});
return queue;
}
function executeCell(cell) { function executeCell(cell) {
if (['raw', 'meta', 'plugin'].indexOf(cell._type) !== -1) { if (['raw', 'meta', 'plugin'].indexOf(cell._type) !== -1) {
// Do nothing... // Do nothing...
...@@ -471,18 +504,11 @@ ...@@ -471,18 +504,11 @@
if (!is_pyodide_loaded) { if (!is_pyodide_loaded) {
console.log("Loading pyodide"); console.log("Loading pyodide");
queue.push(function () { queue.push(function () {
Module.instantiateWasm = loadPyodide; return initPyodide();
window.Module = Module;
}) })
.push(function () { .push(function () {
return loadJSResource('pyodide.asm.data.js'); return pyodideLoadPackage('matplotlib');
}) });
.push(function () {
return loadJSResource('pyodide.asm.js');
})
.push(function () {
return pyodideSetting();
});
is_pyodide_loaded = true; is_pyodide_loaded = true;
} }
queue.push(function () { queue.push(function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment