Skip to content

Conversation

DonJayamanne
Copy link
Contributor

@DonJayamanne DonJayamanne commented Jun 14, 2022

@@ -379,7 +379,9 @@ export abstract class BaseJupyterSession implements IJupyterSession {
const jupyterLabSerialize =
require('@jupyterlab/services/lib/kernel/serialize') as typeof import('@jupyterlab/services/lib/kernel/serialize'); // NOSONAR
const message =
typeof msg.msg === 'string' ? jupyterLabSerialize.deserialize(msg.msg) : msg.msg;
typeof msg.msg === 'string' || msg.msg instanceof ArrayBuffer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was incorrect, when we were firing this event we weren't deserializing buffers

}

private async configureWidgets(): Promise<void> {
if (this.configuredScriptSources.length !== 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved code related to displaying messages for CDN into the CDN class, instaead of having that elsewhere.

});
} else if (message === IPyWidgetMessages.IPyWidgets_IsOnline) {
const isOnline = (payload as { isOnline: boolean }).isOnline;
this.isWebViewOnline.resolve(isOnline);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helps us determine from exension host whether the webview has access to the internet (i.e. whether we can access CDN resources from webview)

@@ -127,7 +118,7 @@ export class IPyWidgetScriptSource {
}

if (!this.kernel) {
this.kernel = await this.kernelProvider.get(this.document.uri);
this.kernel = this.kernelProvider.get(this.document.uri);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary await

@codecov-commenter
Copy link

codecov-commenter commented Jun 15, 2022

Codecov Report

Merging #10459 (c3730db) into main (94de3cd) will increase coverage by 0%.
The diff coverage is 80%.

❗ Current head c3730db differs from pull request most recent head 9aba5b1. Consider uploading reports for the commit 9aba5b1 to get more accurate results

@@           Coverage Diff           @@
##            main   #10459    +/-   ##
=======================================
  Coverage     71%      71%            
=======================================
  Files        480      486     +6     
  Lines      29003    29157   +154     
  Branches    4885     4902    +17     
=======================================
+ Hits       20640    20756   +116     
- Misses      6421     6449    +28     
- Partials    1942     1952    +10     
Impacted Files Coverage Δ
...tive-window/debugger/jupyter/kernelDebugAdapter.ts 58% <ø> (-2%) ⬇️
src/kernels/common/baseJupyterSession.ts 78% <0%> (ø)
src/platform/common/platform/types.node.ts 100% <ø> (ø)
src/telemetry/types.ts 100% <ø> (ø)
...ssage-coordination/remoteIPyWidgetScriptManager.ts 63% <63%> (ø)
...sage-coordination/cdnWidgetScriptSourceProvider.ts 71% <71%> (ø)
...message-coordination/baseIPyWidgetScriptManager.ts 76% <76%> (ø)
...gets-message-coordination/ipyWidgetScriptSource.ts 78% <76%> (+<1%) ⬆️
...sage-coordination/ipyWidgetScriptSourceProvider.ts 75% <81%> (-10%) ⬇️
src/platform/common/platform/fileSystem.node.ts 82% <84%> (+2%) ⬆️
... and 39 more

@DonJayamanne DonJayamanne changed the title WIP Fixes related to loading widget scripts Jun 16, 2022
@DonJayamanne DonJayamanne marked this pull request as ready for review June 16, 2022 02:16
@DonJayamanne DonJayamanne requested a review from a team as a code owner June 16, 2022 02:16
@@ -0,0 +1,201 @@
Apache License
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to use the actual extension.js files for tests instead of crafting our own content.
Included the license files along with the extesnsion.js files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if some automated check tool is going to flag us for having a different license in the repo. But I guess we'll see if anything like that crops up moving forward.

@@ -379,7 +379,9 @@ export abstract class BaseJupyterSession implements IJupyterSession {
const jupyterLabSerialize =
require('@jupyterlab/services/lib/kernel/serialize') as typeof import('@jupyterlab/services/lib/kernel/serialize'); // NOSONAR
const message =
typeof msg.msg === 'string' ? jupyterLabSerialize.deserialize(msg.msg) : msg.msg;
typeof msg.msg === 'string' || msg.msg instanceof ArrayBuffer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug i found while testing, we weren't deserializing buffers

* Given an widget module name & version, this will attempt to find the Url on a CDN.
* We'll need to stick to the order of preference prescribed by the user.
*/
export class CDNWidgetScriptSourceProvider implements IWidgetScriptSourceProvider {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged the web and node files into one, we don't need to download the cdn files into the local file system anymore.
If we do that then things will not work, e.g. ipyvolume and a few other widgets don't work with that approach.

If user doesn't have access to the internet from the webview, then we'll not use CDN, this way we're consistent. I.e. we always use CDN when there's network connection, else fallback.
If here's no network access we're now displaying a warning message.

const uri = vscode.Uri.file(filename);
const data = await this.vscfs.readFile(uri);
return Buffer.from(data);
return fs.readFile(filename);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using VSC API here is totally unnecessary its very slow.
Since these are local only (the methods are local , hence easier & more efficient to just use native node modules.

@@ -0,0 +1 @@
Ensure IPyWidgets get loaded correctly when loading resources from the CDN, Remote Jupyter or local the Python Environment.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still requires some more testing, but this is ready for review.
Will look into adding more tests or at least re-enabling some of the widget tests tomorrow.

Copy link
Contributor

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job. Looks like we're going to have ALL widgets working now.

}
try {
// Value will be an array of the form `['xyz', 'abc']`
const items = (output.text as string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Language conversions like this always feel a bit scary. Like I think that , is a valid file path character on linux. I think since you have the logging in the catch case this should be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed,
Also I don't see why it will work not work as we own this code along with the output generated (I could optionally send a JSON output back but that felt a little overkill for me).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come to think of it, that might be better.
Let me see if I can add the JSON output, at least we know the output is JSON and dpoesn't need to be parsed in this manner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work as expected, not going to spend more time on that.

@amunger
Copy link
Contributor

amunger commented Jun 16, 2022

empty news file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up support for ipywidgets in remote jupyter scenarios
5 participants