mirror of
https://github.com/pyscript/pyscript.git
synced 2022-05-01 19:47:48 +03:00
allow pyscript to specify source and try loading pyscript python injections from file
This commit is contained in:
@@ -98,17 +98,29 @@ pyscript = PyScript()
|
||||
|
||||
let loadInterpreter = async function(): any {
|
||||
/* @ts-ignore */
|
||||
console.log("creating pyodide runtime");
|
||||
pyodide = await loadPyodide({
|
||||
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.19.0/full/",
|
||||
stdout: console.log,
|
||||
stderr: console.log
|
||||
});
|
||||
|
||||
// now that we loaded, add additional convenience fuctions
|
||||
console.log("loading micropip");
|
||||
await pyodide.loadPackage("micropip");
|
||||
console.log('loading pyscript module');
|
||||
await pyodide.runPythonAsync(`
|
||||
from pyodide.http import pyfetch
|
||||
response = await pyfetch("/build/pyscript.py")
|
||||
with open("pyscript.py", "wb") as f:
|
||||
content = await response.bytes()
|
||||
print(content)
|
||||
f.write(content)
|
||||
`)
|
||||
let pkg = pyodide.pyimport("pyscript");
|
||||
|
||||
console.log("creating additional definitions");
|
||||
let output = pyodide.runPython(additional_definitions);
|
||||
|
||||
console.log("done setting up environment");
|
||||
/* @ts-ignore */
|
||||
return pyodide;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user