mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-27 11:04:05 -05:00
Refactor pyexec (#1318)
This is some refactoring I did on the way towards resolving pyscript#1313. I added a new _run_pyscript Python function which executes the code inside a context manager that sets the display target. We can then return a JS object wrapper directly from Python. I moved the "installation" of the pyscript module to loadInterpreter, and pyimport pyscript_py there and give it a type. This avoids a bunch of creating and deleting of proxies for pyscript_py and allows us to give it a type once and for all. I also did some minor logic cleanup in a few places.
This commit is contained in:
@@ -45,13 +45,23 @@ export class InterpreterClient extends Object {
|
||||
}
|
||||
|
||||
/**
|
||||
* delegates the code to be run to the underlying interface of
|
||||
* the remote interpreter.
|
||||
* Python exceptions are turned into JS exceptions.
|
||||
* */
|
||||
* Run user Python code. See also the _run_pyscript docstring.
|
||||
*
|
||||
* The result is wrapped in an object to avoid accidentally awaiting a
|
||||
* Python Task or Future returned as the result of the computation.
|
||||
*
|
||||
* @param code the code to run
|
||||
* @param id The id for the default display target (or undefined if no
|
||||
* default display target).
|
||||
* @returns Either:
|
||||
* 1. An Object of the form {result: the_result} if the result is
|
||||
* serializable (or transferable), or
|
||||
* 2. a Synclink Proxy wrapping an object of this if the result is not
|
||||
* serializable.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async run(code: string): Promise<{ result: any }> {
|
||||
return await this._remote.run(code);
|
||||
async run(code: string, id?: string): Promise<{ result: any }> {
|
||||
return this._remote.pyscript_py._run_pyscript(code, id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user