mirror of https://github.com/pyodide/pyodide.git
Add a proxy to get global objects from Python
This commit is contained in:
parent
09d8afea93
commit
f4400b12f1
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue