Commit 6ca9812e authored by Romain Casati's avatar Romain Casati

List modules launched by user.

parent 8c252918
......@@ -290,6 +290,13 @@
return pyodide.globals.basthon.kernel.put_module(filename, content);
};
/**
* List modules launched via putModule.
*/
that.userModules = function () {
return pyodide.globals.basthon.kernel.user_modules();
};
/**
* Put a ressource (file or *.py module) on the local (emulated)
* filesystem. Detection is based on extension.
......
......@@ -85,9 +85,6 @@ def put_module(filename, content):
Put a module (*.py file) on the (emulated) local filesystem
bypassing the Pyodide' single-import-issue by invalidate caches
https://github.com/iodide-project/pyodide/issues/737
/!\ Warning: the dependencies loading is done on the JS side by
basthon.js.
"""
def callback(*args):
_, fname = os.path.split(filename)
......@@ -104,6 +101,16 @@ def put_module(filename, content):
return packages.load_and_hack(pkgs).then(callback)
def user_modules():
"""
List modules launched via put_module.
"""
if not os.path.exists(_user_modules_root):
return []
return [f for f in os.listdir(_user_modules_root)
if f.endswith('.py')]
def get_file(filepath):
"""
Download a file from the (emulated) local filesystem.
......
......@@ -49,6 +49,7 @@ def test_put_file(selenium):
def test_put_module(selenium):
assert not selenium.run_js("return Basthon.userModules();")
content = "foo = 42"
selenium.driver.execute_async_script("""
const done = arguments[arguments.length - 1];
......@@ -58,6 +59,7 @@ def test_put_module(selenium):
import bar
print(bar.foo, end='', flush=True)""")['stdout']
assert result == "42"
assert selenium.run_js("return Basthon.userModules();") == ["bar.py"]
# with a second module
......@@ -70,6 +72,7 @@ def test_put_module(selenium):
import foo
foo.bar""")['result']['result']['text/plain']
assert result == "24"
assert set(selenium.run_js("return Basthon.userModules();")) == set(["bar.py", "foo.py"])
def test_importables(selenium):
......
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