Commit 84ed860a authored by Romain Casati's avatar Romain Casati

Cleanest basthon at import and not imported in global namespace.

parent f07525c3
......@@ -121,8 +121,14 @@
const consoleErrorBck = console.error;
console.error = () => {};
return pyodide.loadPackage(that.basthonRoot + "/basthon-py/basthon.js").then(() => {
pyodide.runPythonAsync("import basthon");
console.error = consoleErrorBck;
// importing basthon to get it's kernel
return pyodide.runPythonAsync("import basthon as __basthon__");
}).then(() => {
// kernel lookup
that.__kernel__ = pyodide.globals.__basthon__.__kernel__;
// removing basthon from global namespace
return pyodide.runPythonAsync("del __basthon__");
});
};
......@@ -234,7 +240,7 @@
errCallback = function (text) { console.error(text); };
}
// loading dependencies are loaded by eval
return await pyodide.globals.basthon.kernel.eval(code, outCallback, errCallback, data);
return await that.__kernel__.eval(code, outCallback, errCallback, data);
};
/**
......@@ -272,7 +278,7 @@
errCallback(error.toString());
let dataEvent = that.clone(data);
dataEvent.error = error;
dataEvent.execution_count = pyodide.globals.basthon.kernel.execution_count();
dataEvent.execution_count = that.__kernel__.execution_count();
that.dispatchEvent("eval.error", dataEvent);
});
};
......@@ -282,14 +288,14 @@
*/
that.restart = function () {
if( !that.loaded ) { return ; }
return pyodide.globals.basthon.kernel.restart();
return that.__kernel__.restart();
};
/**
* Put a file on the local (emulated) filesystem.
*/
that.putFile = function (filename, content) {
pyodide.globals.basthon.kernel.put_file(filename, content);
that.__kernel__.put_file(filename, content);
};
/**
......@@ -297,14 +303,14 @@
* and load dependencies.
*/
that.putModule = function (filename, content) {
return pyodide.globals.basthon.kernel.put_module(filename, content);
return that.__kernel__.put_module(filename, content);
};
/**
* List modules launched via putModule.
*/
that.userModules = function () {
return pyodide.globals.basthon.kernel.user_modules();
return that.__kernel__.user_modules();
};
/**
......@@ -324,14 +330,14 @@
* Download a file from the VFS.
*/
that.getFile = function (path) {
return pyodide.globals.basthon.kernel.get_file(path);
return that.__kernel__.get_file(path);
};
/**
* Download a user module file.
*/
that.getUserModuleFile = function (filename) {
return pyodide.globals.basthon.kernel.get_user_module_file(filename);
return that.__kernel__.get_user_module_file(filename);
};
/**
......@@ -339,14 +345,14 @@
* Usefull to set ps1/ps2 for teminal prompt.
*/
that.more = function (source) {
return pyodide.globals.basthon.kernel.more(source);
return that.__kernel__.more(source);
};
/**
* Mimic the CPython's REPL banner.
*/
that.banner = function () {
return pyodide.globals.basthon.kernel.banner();
return that.__kernel__.banner();
};
/**
......@@ -356,7 +362,7 @@
* and the start index.
*/
that.complete = function (code) {
return pyodide.globals.basthon.kernel.complete(code);
return that.__kernel__.complete(code);
}
return that;
......
from . import kernel, _hack_builtins
from . import kernel as __kernel__
from . import _hack_builtins
__author__ = "Romain Casati"
......@@ -9,9 +10,13 @@ __email__ = "romain.casati@basthon.fr"
__all__ = ['display', 'download']
display = kernel.display
download = kernel.download
display = __kernel__.display
download = __kernel__.download
_hack_builtins.hack_input()
_hack_builtins.hack_help()
# avoid poluting __dict__
del _hack_builtins
......@@ -2,6 +2,7 @@ import js
import sys
from . import _pyodide_console, kernel, _pyodide_base, packages
__author__ = "Romain Casati"
__license__ = "GNU GPL v3"
__email__ = "romain.casati@basthon.fr"
......
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