Commit f4400b12 authored by Michael Droettboom's avatar Michael Droettboom

Add a proxy to get global objects from Python

parent 09d8afea
......@@ -235,6 +235,7 @@ var languagePluginLoader = new Promise((resolve, reject) => {
let PUBLIC_API = [
'loadPackage',
'loadedPackages',
'py',
'pyimport',
'repr',
'runPython',
......@@ -277,6 +278,8 @@ var languagePluginLoader = new Promise((resolve, reject) => {
.then((response) => response.json())
.then((json) => {
fixRecursionLimit(window.pyodide);
window.pyodide.py =
window.pyodide.runPython('import sys\nsys.modules["__main__"]');
window.pyodide = makePublicAPI(window.pyodide, PUBLIC_API);
window.pyodide._module.packages = json;
resolve();
......
......@@ -599,3 +599,14 @@ def test_runpythonasync_exception_after_import(selenium_standalone):
assert "ZeroDivisionError" in str(e)
else:
assert False
def test_py(selenium_standalone):
selenium_standalone.run(
"""
def func():
return 42
"""
)
assert selenium_standalone.run_js('return pyodide.py.func()') == 42
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