File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,17 @@ import {pyodide as Pyodide} from "./dependencies.js";
2
2
3
3
export default async function py ( require ) {
4
4
const pyodide = await ( await require ( Pyodide . resolve ( ) ) ) . loadPyodide ( ) ;
5
- return async function py ( ) {
6
- const code = String . raw . apply ( String , arguments ) ;
5
+ return async function py ( strings , ...values ) {
6
+ let globals = { } ;
7
+ const code = strings . reduce ( ( code , string , i ) => {
8
+ if ( ! ( i in values ) ) return code + string ;
9
+ const name = `_${ i } ` ;
10
+ globals [ name ] = values [ i ] ;
11
+ return code + string + name ;
12
+ } , "" ) ;
13
+ globals = pyodide . toPy ( globals ) ;
7
14
await pyodide . loadPackagesFromImports ( code ) ;
8
- const value = await pyodide . runPython ( code ) ;
15
+ const value = await pyodide . runPythonAsync ( code , { globals } ) ;
9
16
return pyodide . isPyProxy ( value ) ? value . toJs ( ) : value ;
10
17
} ;
11
18
}
You can’t perform that action at this time.
0 commit comments