Add a proxy to get global objects from Python

This commit is contained in:
Michael Droettboom 2018-12-19 14:22:18 -05:00
parent 09d8afea93
commit f4400b12f1
2 changed files with 14 additions and 0 deletions

View File

@ -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();

View File

@ -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