mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-20 10:01:24 -05:00
synclink integration (#1258)
synclink integration + fixes for `py-repl` related tests and `display` tests
This commit is contained in:
@@ -132,10 +132,10 @@ export function make_PyRepl(interpreter: InterpreterClient, app: PyScriptApp) {
|
||||
const outEl = this.outDiv;
|
||||
|
||||
// execute the python code
|
||||
app.plugins.beforePyReplExec({ interpreter: interpreter, src: pySrc, outEl: outEl, pyReplTag: this });
|
||||
await app.plugins.beforePyReplExec({ interpreter: interpreter, src: pySrc, outEl: outEl, pyReplTag: this });
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const { result } = await pyExec(interpreter, pySrc, outEl);
|
||||
app.plugins.afterPyReplExec({
|
||||
await app.plugins.afterPyReplExec({
|
||||
interpreter: interpreter,
|
||||
src: pySrc,
|
||||
outEl: outEl,
|
||||
|
||||
@@ -23,6 +23,7 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp)
|
||||
*
|
||||
* Concurrent access to the multiple py-script tags is thus avoided.
|
||||
*/
|
||||
app.incrementPendingTags();
|
||||
let releaseLock: () => void;
|
||||
try {
|
||||
releaseLock = await app.tagExecutionLock();
|
||||
@@ -34,10 +35,10 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp)
|
||||
const pySrc = await this.getPySrc();
|
||||
this.innerHTML = '';
|
||||
|
||||
app.plugins.beforePyScriptExec({ interpreter: interpreter, src: pySrc, pyScriptTag: this });
|
||||
await app.plugins.beforePyScriptExec({ interpreter: interpreter, src: pySrc, pyScriptTag: this });
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
const result = (await pyExec(interpreter, pySrc, this)).result;
|
||||
app.plugins.afterPyScriptExec({
|
||||
await app.plugins.afterPyScriptExec({
|
||||
interpreter: interpreter,
|
||||
src: pySrc,
|
||||
pyScriptTag: this,
|
||||
@@ -46,6 +47,7 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp)
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-assignment */
|
||||
} finally {
|
||||
releaseLock();
|
||||
app.decrementPendingTags();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { PyProxy, PyProxyCallable } from 'pyodide';
|
||||
import { getLogger } from '../logger';
|
||||
import { robustFetch } from '../fetch';
|
||||
import { InterpreterClient } from '../interpreter_client';
|
||||
import type { Remote } from 'synclink';
|
||||
|
||||
const logger = getLogger('py-register-widget');
|
||||
|
||||
@@ -13,8 +14,8 @@ function createWidget(interpreter: InterpreterClient, name: string, code: string
|
||||
name: string = name;
|
||||
klass: string = klass;
|
||||
code: string = code;
|
||||
proxy: PyProxy & { connect(): void };
|
||||
proxyClass: PyProxyCallable;
|
||||
proxy: Remote<PyProxy & { connect(): void }>;
|
||||
proxyClass: Remote<PyProxyCallable>;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -28,15 +29,15 @@ function createWidget(interpreter: InterpreterClient, name: string, code: string
|
||||
|
||||
async connectedCallback() {
|
||||
await interpreter.runButDontRaise(this.code);
|
||||
this.proxyClass = interpreter.globals.get(this.klass) as PyProxyCallable;
|
||||
this.proxy = this.proxyClass(this) as PyProxy & { connect(): void };
|
||||
this.proxy.connect();
|
||||
this.registerWidget();
|
||||
this.proxyClass = (await interpreter.globals.get(this.klass)) as Remote<PyProxyCallable>;
|
||||
this.proxy = (await this.proxyClass(this)) as Remote<PyProxy & { connect(): void }>;
|
||||
await this.proxy.connect();
|
||||
await this.registerWidget();
|
||||
}
|
||||
|
||||
registerWidget() {
|
||||
async registerWidget() {
|
||||
logger.info('new widget registered:', this.name);
|
||||
interpreter.globals.set(this.id, this.proxy);
|
||||
await interpreter.globals.set(this.id, this.proxy);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
||||
Reference in New Issue
Block a user