Restore output attribute of py-script tags, add py-script exec lifecycle hooks (#1063)

* Add beforePyScriptExec, afterPyScriptExec lifecycle hooks

* Add stdiodirector plugin for `output`, `stderr` attributes of py-script tag

* Add docs on `output` and `stderr` attributes of py-script tag

* Tests

* Removed output deprecation warning for `output` attribute

* Add createSingularWarning(), with createDeprecationWarning as alias
This commit is contained in:
Jeff Glass
2023-01-10 13:00:29 -06:00
committed by GitHub
parent e1b4415193
commit 470c3489dd
15 changed files with 748 additions and 33 deletions

View File

@@ -39,6 +39,25 @@ export class Plugin {
*/
afterSetup(runtime: Runtime) {}
/** The source of a <py-script>> tag has been fetched, and we're about
* to evaluate that source using the provided runtime.
*
* @param runtime The Runtime object that will be used to evaluated the Python source code
* @param src {string} The Python source code to be evaluated
* @param PyScriptTag The <py-script> HTML tag that originated the evaluation
*/
beforePyScriptExec(runtime, src, PyScriptTag) {}
/** The Python in a <py-script> has just been evaluated, but control
* has not been ceded back to the JavaScript event loop yet
*
* @param runtime The Runtime object that will be used to evaluated the Python source code
* @param src {string} The Python source code to be evaluated
* @param PyScriptTag The <py-script> HTML tag that originated the evaluation
* @param result The returned result of evaluating the Python (if any)
*/
afterPyScriptExec(runtime, src, PyScriptTag, result) {}
/** Startup complete. The interpreter is initialized and ready, user
* scripts have been executed: the main initialization logic ends here and
* the page is ready to accept user interactions.
@@ -89,6 +108,18 @@ export class PluginManager {
for (const p of this._pythonPlugins) p.afterStartup?.(runtime);
}
beforePyScriptExec(runtime, src, pyscriptTag) {
for (const p of this._plugins) p.beforePyScriptExec(runtime, src, pyscriptTag);
for (const p of this._pythonPlugins) p.beforePyScriptExec?.(runtime, src, pyscriptTag);
}
afterPyScriptExec(runtime: Runtime, src, pyscriptTag, result) {
for (const p of this._plugins) p.afterPyScriptExec(runtime, src, pyscriptTag, result);
for (const p of this._pythonPlugins) p.afterPyScriptExec?.(runtime, src, pyscriptTag, result);
}
onUserError(error: UserError) {
for (const p of this._plugins) p.onUserError(error);