New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/SOF-7286 #12
Feature/SOF-7286 #12
Conversation
…ange and new notebook
extensions/src/data_bridge/index.ts
Outdated
) => { | ||
console.log("JupyterLab extension data-bridge is activated!"); | ||
|
||
// Send path of the currently opened notebook to the host page when the notebook is opened | ||
notebookTracker.currentChanged.connect((sender, notebookPanel) => { | ||
// Variable to hold the data from the host page, accessible from any notebook and kernel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe `Reusing the "app" variable ..."
extensions/src/data_bridge/index.ts
Outdated
); | ||
sessionContext.session?.kernel?.statusChanged.connect((kernel, status) => { | ||
// @ts-ignore | ||
console.debug(status, kernel.id, kernel.dataFromHost); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
extensions/src/data_bridge/index.ts
Outdated
// @ts-ignore | ||
app.dataFromHost = JSON.stringify(event.data.payload); | ||
//@ts-ignore | ||
console.debug("Data from host received. app:", app.dataFromHost); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
extensions/src/data_bridge/index.ts
Outdated
action: "get-data", | ||
payload: {} | ||
}, | ||
"*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define as a variable MESSAGE_GET_DATA_CONTENT above
extensions/src/data_bridge/index.ts
Outdated
console.debug(status, kernel.id, kernel.dataFromHost); | ||
// @ts-ignore | ||
if (status === 'idle' && kernel.dataFromHost !== app.dataFromHost) { | ||
// Custom flag to prevent from loading the same data multiple times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save previous data inside the current kernel to avoid reloading
extensions/src/data_bridge/index.ts
Outdated
window.parent.postMessage( | ||
{ | ||
type: "from-iframe-to-host", | ||
data: data, | ||
action: "set-data", | ||
payload: data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - MESSAGE_SET_DATA_CONTENT
extensions/src/data_bridge/index.ts
Outdated
console.error("Current active widget is not a notebook"); | ||
} | ||
// @ts-ignore | ||
app.dataFromHost = JSON.stringify(event.data.payload); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON stringify should be executed before we send the message, probably and/or we should do the validation with schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, validation happens when we do the entity.toJSON()
and send it, then here we use stringify due to how it's going to be consumed by pyodide code execution.
extensions/src/data_bridge/index.ts
Outdated
* @param data | ||
*/ | ||
const loadData = (kernel: IKernelConnection, data: JSON) => { | ||
const dataFromHostString = JSON.stringify(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually necessary to escape all the special characteres, so that this can be used directly in the Python code.
package.json
Outdated
@@ -3,4 +3,5 @@ | |||
"start": "python -m http.server -b localhost -d ./dist", | |||
"build": "python -m pip install -r requirements.txt; cp -rL content content-resolved; jupyter lite build --contents content-resolved --output-dir dist" | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
extensions/src/data_bridge/index.ts
Outdated
* @param data string representation of JSON | ||
*/ | ||
const loadData = (kernel: IKernelConnection, data: string) => { | ||
const code = `import json\ndata_from_host = json.loads("${data}")`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the approach from https://github.com/Exabyte-io/standata/blob/main/build_runtime_data.js#L67C8-L67C91
Adds changes to JupyterLite extension
data_bridge
that is responsible for exchanging data between JL pyodide environment and JS component/host.