Skip to content
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

Update Jupyter Npm To Latest #15897

Merged
merged 11 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions build/ci/postInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,7 @@ const path = require('path');
const constants = require('../constants');
const common = require('../webpack/common');
const { downloadZMQ } = require('@vscode/zeromq');
/**
* In order to get raw kernels working, we reuse the default kernel that jupyterlab ships.
* However it expects to be talking to a websocket which is serializing the messages to strings.
* Our raw kernel is not a web socket and needs to do its own serialization. To do so, we make a copy
* of the default kernel with the serialization stripped out. This is simpler than making a copy of the module
* at runtime.
*/
function createJupyterKernelWithoutSerialization() {
var relativePath = path.join('node_modules', '@jupyterlab', 'services', 'lib', 'kernel', 'default.js');
var filePath = path.join(constants.ExtensionRootDir, relativePath);
if (!fs.existsSync(filePath)) {
throw new Error(
"Jupyter lab default kernel not found '" + filePath + "' (Jupyter Extension post install script)"
);
}
var fileContents = fs.readFileSync(filePath, { encoding: 'utf8' });
var replacedContents = fileContents
.replace(/^const serialize =.*$/gm, 'const serialize = { serialize: (a) => a, deserialize: (a) => a };')
.replace(
'const owned = team.session === this.clientId;',
'const owned = parentHeader.session === this.clientId;'
);
if (replacedContents === fileContents) {
throw new Error('Jupyter lab default kernel cannot be made non serializing');
}
var destPath = path.join(path.dirname(filePath), 'nonSerializingKernel.js');
fs.writeFileSync(destPath, replacedContents);
console.log(colors.green(destPath + ' file generated (by Jupyter VSC)'));
}

function fixVariableNameInKernelDefaultJs() {
var relativePath = path.join('node_modules', '@jupyterlab', 'services', 'lib', 'kernel', 'default.js');
var filePath = path.join(constants.ExtensionRootDir, relativePath);
Expand Down Expand Up @@ -228,7 +200,6 @@ function commentOutInvalidExport() {

fixJupyterLabRenderers();
makeVariableExplorerAlwaysSorted();
createJupyterKernelWithoutSerialization();
fixVariableNameInKernelDefaultJs();
removeUnnecessaryLoggingFromKernelDefault();
fixStripComments();
Expand Down
2 changes: 1 addition & 1 deletion build/esbuild/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const deskTopNodeModulesToExternalize = [
'@jupyterlab/services',
'@jupyterlab/nbformat',
'@jupyterlab/services/lib/kernel/serialize',
'@jupyterlab/services/lib/kernel/nonSerializingKernel',
'@jupyterlab/services/lib/kernel/default',
'vscode-jsonrpc' // Used by a few modules, might as well pull this out, instead of duplicating it in separate bundles.
];
const commonExternals = [
Expand Down
1,514 changes: 1,179 additions & 335 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2128,13 +2128,13 @@
"dependencies": {
"@c4312/evt": "^0.1.1",
"@enonic/fnv-plus": "^1.3.0",
"@jupyter-widgets/base": "4.0.0",
"@jupyter-widgets/controls": "3.0.0",
"@jupyter-widgets/schema": "0.4.0",
"@jupyterlab/coreutils": "5.1.17",
"@jupyterlab/nbformat": "3.1.17",
"@jupyterlab/services": "6.1.17",
"@lumino/widgets": "^1.28.0",
"@jupyter-widgets/base": "^6.0.8",
"@jupyter-widgets/controls": "^5.0.9",
"@jupyter-widgets/schema": "^0.5.5",
"@jupyterlab/coreutils": "^6.2.4",
"@jupyterlab/nbformat": "^4.2.4",
"@jupyterlab/services": "^7.2.4",
"@lumino/widgets": "^2.4.0",
"@nteract/messaging": "^7.0.0",
"@vscode/extension-telemetry": "^0.7.7",
"@vscode/python-extension": "^1.0.4",
Expand Down
10 changes: 10 additions & 0 deletions src/kernels/common/baseJupyterSessionConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export abstract class BaseJupyterSessionConnection<
* The kernel anyMessage signal, proxied from the current kernel.
*/
anyMessage = new Signal<this, Kernel.IAnyMessageArgs>(this);
/**
* The kernel pendingInput signal, proxied from the current
* kernel.
*/
pendingInput = new Signal<this, boolean>(this);

constructor(
public readonly kind: T,
Expand All @@ -70,6 +75,7 @@ export abstract class BaseJupyterSessionConnection<
session.connectionStatusChanged.connect(this.onConnectionStatusChanged, this);
session.iopubMessage.connect(this.onIOPubMessage, this);
session.unhandledMessage.connect(this.onUnhandledMessage, this);
session.pendingInput.connect(this.onPendingInput, this);
session.anyMessage.connect(this.onAnyMessage, this);

this._register({
Expand All @@ -80,6 +86,7 @@ export abstract class BaseJupyterSessionConnection<
this.session.connectionStatusChanged.disconnect(this.onConnectionStatusChanged, this);
this.session.iopubMessage.disconnect(this.onIOPubMessage, this);
this.session.unhandledMessage.disconnect(this.onUnhandledMessage, this);
this.session.pendingInput.disconnect(this.onPendingInput, this);
this.session.anyMessage.disconnect(this.onAnyMessage, this);
}
});
Expand Down Expand Up @@ -187,6 +194,9 @@ export abstract class BaseJupyterSessionConnection<
private onAnyMessage(_: unknown, value: Kernel.IAnyMessageArgs) {
this.anyMessage.emit(value);
}
private onPendingInput(_: unknown, value: boolean) {
this.pendingInput.emit(value);
}
public setPath(value: string) {
return this.session.setPath(value);
}
Expand Down
2 changes: 2 additions & 0 deletions src/kernels/common/baseJupyterSessionConnection.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ suite('Base Jupyter Session Connection', () => {
when(kernel.status).thenReturn('idle');
when(kernel.connectionStatus).thenReturn('connected');
when(kernel.statusChanged).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, Kernel.Status>>()));
when(kernel.pendingInput).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, boolean>>()));
when(kernel.iopubMessage).thenReturn(
instance(
mock<ISignal<Kernel.IKernelConnection, KernelMessage.IIOPubMessage<KernelMessage.IOPubMessageType>>>()
Expand Down Expand Up @@ -96,6 +97,7 @@ suite('Base Jupyter Session Connection', () => {
when(session.statusChanged).thenReturn(
new Signal<Session.ISessionConnection, Kernel.Status>(instance(session))
);
when(session.pendingInput).thenReturn(instance(mock<ISignal<Session.ISessionConnection, boolean>>()));
when(session.unhandledMessage).thenReturn(sessionUnhandledMessage);
when(session.connectionStatusChanged).thenReturn(sessionConnectionStatusChanged);
when(session.anyMessage).thenReturn(sessionAnyMessage);
Expand Down
3 changes: 2 additions & 1 deletion src/kernels/execution/cellExecutionMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,8 @@ export class CellExecutionMessageHandler implements IDisposable {
cancelToken.token
)
.then((v) => {
this.kernel.sendInputReply({ value: v || '', status: 'ok' });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.kernel.sendInputReply({ value: v || '', status: 'ok' }, msg.header as any);
}, noop);

this.prompts.delete(cancelToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ suite('New Jupyter Kernel Session Factory', () => {
when(session.statusChanged).thenReturn(
new Signal<Session.ISessionConnection, Kernel.Status>(instance(session))
);
when(session.pendingInput).thenReturn(instance(mock<ISignal<Session.ISessionConnection, boolean>>()));
when(session.unhandledMessage).thenReturn(sessionUnhandledMessage);
when(session.connectionStatusChanged).thenReturn(sessionConnectionStatusChanged);
when(session.anyMessage).thenReturn(sessionAnyMessage);
when(session.isDisposed).thenReturn(false);
when(kernel.status).thenReturn('idle');
when(kernel.connectionStatus).thenReturn('connected');
when(kernel.statusChanged).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, Kernel.Status>>()));
when(kernel.pendingInput).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, boolean>>()));
when(kernel.iopubMessage).thenReturn(
instance(
mock<ISignal<Kernel.IKernelConnection, KernelMessage.IIOPubMessage<KernelMessage.IOPubMessageType>>>()
Expand Down
4 changes: 2 additions & 2 deletions src/kernels/jupyter/session/jupyterLabHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export class JupyterLabHelper extends ObservableDisposable {

const sessions: Session.IModel[] = [];
const iterator = this.sessionManager.running();
let session = iterator.next();
let session = iterator.next().value;

while (session) {
sessions.push(session);
session = iterator.next();
session = iterator.next().value;
}

return sessions;
Expand Down
2 changes: 2 additions & 0 deletions src/kernels/jupyter/session/jupyterSession.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ suite('JupyterSession', () => {
when(session.unhandledMessage).thenReturn(sessionUnhandledMessage);
when(session.connectionStatusChanged).thenReturn(sessionConnectionStatusChanged);
when(session.anyMessage).thenReturn(sessionAnyMessage);
when(session.pendingInput).thenReturn(instance(mock<ISignal<Session.ISessionConnection, boolean>>()));
when(session.isDisposed).thenReturn(false);
when(kernel.status).thenReturn('idle');
when(kernel.connectionStatus).thenReturn('connected');
Expand All @@ -90,6 +91,7 @@ suite('JupyterSession', () => {
instance(mock<ISignal<Kernel.IKernelConnection, KernelMessage.IMessage<KernelMessage.MessageType>>>())
);
when(kernel.disposed).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, void>>()));
when(kernel.pendingInput).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, boolean>>()));
when(kernel.connectionStatusChanged).thenReturn(
instance(mock<ISignal<Kernel.IKernelConnection, Kernel.ConnectionStatus>>())
);
Expand Down
2 changes: 2 additions & 0 deletions src/kernels/raw/session/rawJupyterSession.node.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ suite('Raw Jupyter Session Wrapper', () => {
when(session.connectionStatusChanged).thenReturn(sessionConnectionStatusChanged);
when(session.anyMessage).thenReturn(sessionAnyMessage);
when(session.isDisposed).thenReturn(false);
when(session.pendingInput).thenReturn(instance(mock<Signal<RawSessionConnection, boolean>>()));
when(kernel.status).thenReturn('idle');
when(kernel.connectionStatus).thenReturn('connected');
when(kernel.statusChanged).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, Kernel.Status>>()));
Expand All @@ -63,6 +64,7 @@ suite('Raw Jupyter Session Wrapper', () => {
instance(mock<ISignal<Kernel.IKernelConnection, KernelMessage.IMessage<KernelMessage.MessageType>>>())
);
when(kernel.disposed).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, void>>()));
when(kernel.pendingInput).thenReturn(instance(mock<ISignal<Kernel.IKernelConnection, boolean>>()));
when(kernel.connectionStatusChanged).thenReturn(
instance(mock<ISignal<Kernel.IKernelConnection, Kernel.ConnectionStatus>>())
);
Expand Down
38 changes: 30 additions & 8 deletions src/kernels/raw/session/rawKernelConnection.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { KernelProcessExitedError } from '../../errors/kernelProcessExitedError'
import { once } from '../../../platform/common/utils/functional';
import { disposeAsync } from '../../../platform/common/utils';

let nonSerializingKernel: typeof import('@jupyterlab/services/lib/kernel/default');
let jupyterLabKernel: typeof import('@jupyterlab/services/lib/kernel/default');

/*
RawKernel class represents the mapping from the JupyterLab services IKernel interface
Expand All @@ -54,6 +54,7 @@ export class RawKernelConnection implements Kernel.IKernelConnection {
public readonly unhandledMessage = new Signal<this, IMessage<MessageType>>(this);
public readonly anyMessage = new Signal<this, Kernel.IAnyMessageArgs>(this);
public readonly disposed = new Signal<this, void>(this);
public readonly pendingInput = new Signal<this, boolean>(this);
public get connectionStatus() {
return this.realKernel ? this.realKernel.connectionStatus : 'connecting';
}
Expand Down Expand Up @@ -90,6 +91,9 @@ export class RawKernelConnection implements Kernel.IKernelConnection {
public get handleComms(): boolean {
return this.realKernel!.handleComms;
}
public get hasPendingInput(): boolean {
return this.realKernel!.hasPendingInput;
}
private isDisposing?: boolean;
private _isDisposed?: boolean;
public get isDisposed(): boolean {
Expand Down Expand Up @@ -302,6 +306,9 @@ export class RawKernelConnection implements Kernel.IKernelConnection {
public hasComm(commId: string): boolean {
return this.realKernel!.hasComm(commId);
}
public removeInputGuard() {
this.realKernel!.removeInputGuard();
}
public clone(
_options?: Pick<Kernel.IKernelConnection.IOptions, 'clientId' | 'username' | 'handleComms'>
): Kernel.IKernelConnection {
Expand Down Expand Up @@ -417,8 +424,11 @@ export class RawKernelConnection implements Kernel.IKernelConnection {
}): Promise<KernelMessage.ICommInfoReplyMsg> {
return this.realKernel!.requestCommInfo(content);
}
public sendInputReply(content: KernelMessage.IInputReplyMsg['content']): void {
return this.realKernel!.sendInputReply(content);
public sendInputReply(
content: KernelMessage.IInputReplyMsg['content'],
parent_header: KernelMessage.IInputReplyMsg['parent_header']
): void {
return this.realKernel!.sendInputReply(content, parent_header);
}
public registerCommTarget(
targetName: string,
Expand Down Expand Up @@ -449,12 +459,14 @@ export class RawKernelConnection implements Kernel.IKernelConnection {
this.realKernel!.iopubMessage.connect(this.onIOPubMessage, this);
this.realKernel!.unhandledMessage.connect(this.onUnhandledMessage, this);
this.realKernel!.statusChanged.connect(this.onStatusChanged, this);
this.realKernel!.pendingInput.connect(this.onPendingInput, this);
this.realKernel!.disposed.connect(this.onDisposed, this);
}
private stopHandlingKernelMessages() {
this.realKernel!.anyMessage.disconnect(this.onAnyMessage, this);
this.realKernel!.iopubMessage.disconnect(this.onIOPubMessage, this);
this.realKernel!.unhandledMessage.disconnect(this.onUnhandledMessage, this);
this.realKernel!.pendingInput.disconnect(this.onPendingInput, this);
this.realKernel!.statusChanged.disconnect(this.onStatusChanged, this);
this.realKernel!.disposed.disconnect(this.onDisposed, this);
}
Expand All @@ -464,6 +476,9 @@ export class RawKernelConnection implements Kernel.IKernelConnection {
private onIOPubMessage(_connection: Kernel.IKernelConnection, msg: IIOPubMessage) {
this.iopubMessage.emit(msg);
}
private onPendingInput(_connection: Kernel.IKernelConnection, msg: boolean) {
this.pendingInput.emit(msg);
}
private onUnhandledMessage(_connection: Kernel.IKernelConnection, msg: IMessage<MessageType>) {
this.unhandledMessage.emit(msg);
}
Expand Down Expand Up @@ -640,18 +655,25 @@ function newRawKernel(kernelProcess: IKernelProcess, clientId: string, username:
const settings = jupyterLab.ServerConnection.makeSettings({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
WebSocket: RawSocketWrapper as any, // NOSONAR
wsUrl: 'RAW'
wsUrl: 'RAW',
serializer: {
deserialize: (data) => {
return data as any; // NOSONAR
},
serialize: (data) => {
return data as any; // NOSONAR
}
}
});

// Then create the real kernel. We will remap its serialize/deserialize functions
// to do nothing so that we can control serialization at our socket layer.
if (!nonSerializingKernel) {
if (!jupyterLabKernel) {
// Note, this is done with a postInstall step (found in build\ci\postInstall.js). In that post install step
// we eliminate the serialize import from the default kernel and remap it to do nothing.
nonSerializingKernel =
require('@jupyterlab/services/lib/kernel/nonSerializingKernel') as typeof import('@jupyterlab/services/lib/kernel/default'); // NOSONAR
jupyterLabKernel = require('@jupyterlab/services/lib/kernel/default'); // NOSONAR
}
const realKernel = new nonSerializingKernel.KernelConnection({
const realKernel = new jupyterLabKernel.KernelConnection({
serverSettings: settings,
clientId,
handleComms: true,
Expand Down
2 changes: 2 additions & 0 deletions src/kernels/raw/session/rawSessionConnection.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class RawSessionConnection implements Session.ISessionConnection {
public readonly anyMessage = new Signal<this, Kernel.IAnyMessageArgs>(this);
public readonly disposed = new Signal<this, void>(this);
public readonly connectionStatusChanged = new Signal<this, Kernel.ConnectionStatus>(this);
public readonly pendingInput = new Signal<this, boolean>(this);
public readonly propertyChanged = new Signal<this, 'path' | 'name' | 'type'>(this);
private _didShutDownOnce = false;
private _isDisposing?: boolean;
Expand Down Expand Up @@ -106,6 +107,7 @@ export class RawSessionConnection implements Session.ISessionConnection {
this._kernel.unhandledMessage.connect(this.onUnhandledMessage, this);
this._kernel.anyMessage.connect(this.onAnyMessage, this);
this._kernel.disposed.connect(this.onDisposed, this);
this._kernel.disposed.connect(this.onDisposed, this);
}
public async startKernel(options: { token: CancellationToken }): Promise<void> {
await trackKernelResourceInformation(this.resource, { kernelConnection: this.kernelConnectionMetadata });
Expand Down
Loading
Loading