Skip to content

Commit 4f543c9

Browse files
committed
handle failure to load jmp dependency in jupyter
1 parent d101775 commit 4f543c9

5 files changed

Lines changed: 35 additions & 11 deletions

File tree

src/client/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ export namespace Documentation {
7878
export const GettingStarted = '/docs/jupyter_getting-started/';
7979
export const Examples = '/docs/jupyter_examples/';
8080
export const Setup = '/docs/jupyter_prerequisites/';
81+
export const VersionIncompatiblity = '/docs/troubleshooting_jupyter/#Incompatible-dependencies'
8182
}
8283
}

src/client/common/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export class JmpModuleLoadError extends Error {
3+
constructor() {
4+
const errorMessage = `Version incompatibility in Jupyter (Python extension). View 'Help' for further details.`;
5+
super(errorMessage);
6+
this.message = errorMessage;
7+
}
8+
}

src/client/jupyter/kernel-manager.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {Commands, Documentation} from '../common/constants';
1111
import {EventEmitter} from 'events';
1212
import {PythonSettings} from '../common/configSettings';
1313
import {formatErrorForLogging} from '../common/utils';
14+
import {JmpModuleLoadError} from '../common/errors';
1415

1516
// Todo: Refactor the error handling and displaying of messages
1617

@@ -98,9 +99,15 @@ export class KernelManagerImpl extends EventEmitter {
9899
return this.startKernel(kernelSpec, language);
99100
}).catch(reason => {
100101
let message = `No kernel for language '${language}' found. Ensure you have a Jupyter or IPython kernel installed for it.`;
102+
let isCompatibilityIssue = false;
103+
if (typeof reason === 'object' && reason instanceof JmpModuleLoadError) {
104+
message = reason.message;
105+
isCompatibilityIssue = true;
106+
}
101107
vscode.window.showErrorMessage(message, 'Help').then(item => {
102108
if (item === 'Help') {
103-
vscode.commands.executeCommand('python.displayHelp', Documentation.Jupyter.Setup);
109+
const helpPage = isCompatibilityIssue ? Documentation.Jupyter.VersionIncompatiblity : Documentation.Jupyter.Setup;
110+
vscode.commands.executeCommand('python.displayHelp', helpPage);
104111
}
105112
});
106113
this.outputChannel.appendLine(formatErrorForLogging(reason));

src/client/jupyter/kernel.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import * as vscode from 'vscode';
44
import * as child_process from 'child_process';
55
import * as path from 'path';
66
import {KernelspecMetadata, KernelEvents} from './contracts';
7-
const jmp = require('jmp');
8-
const uuid = require('uuid');
9-
const zmq = jmp.zmq;
107

118
export abstract class Kernel extends vscode.Disposable implements KernelEvents {
129
private watchCallbacks: any[];

src/client/jupyter/zmq-kernel.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import * as fs from 'fs';
44
import {Kernel} from './kernel';
55
import * as vscode from 'vscode';
66
import {KernelspecMetadata, JupyterMessage} from './contracts';
7-
const jmp = require('jmp');
7+
import {JmpModuleLoadError} from '../common/errors';
88
const uuid = require('uuid');
9-
const zmq = jmp.zmq;
109

1110
export class ZMQKernel extends Kernel {
1211
private executionCallbacks: Map<string, Function>;
@@ -49,7 +48,16 @@ export class ZMQKernel extends Kernel {
4948
private shellSocstdinSocketket: any;
5049
private stdinSocket: any;
5150
private ioSocket: any;
51+
private jmp: any;
5252
public _connect() {
53+
try {
54+
this.jmp = require('jmp');
55+
}
56+
catch (ex) {
57+
console.log(ex);
58+
throw new JmpModuleLoadError();
59+
}
60+
const jmp = this.jmp;
5361
const scheme = this.connection.signature_scheme.slice('hmac-'.length);
5462
const key = this.connection.key;
5563
this.shellSocket = new jmp.Socket('dealer', scheme, key);
@@ -112,6 +120,9 @@ export class ZMQKernel extends Kernel {
112120
};
113121

114122
public shutdown(restart?: boolean) {
123+
if (!this.jmp) {
124+
return;
125+
}
115126
if (restart == null) {
116127
restart = false;
117128
}
@@ -120,7 +131,7 @@ export class ZMQKernel extends Kernel {
120131
message.content = {
121132
restart: restart
122133
};
123-
return this.shellSocket.send(new jmp.Message(message));
134+
return this.shellSocket.send(new this.jmp.Message(message));
124135
};
125136

126137
public _execute(code: string, requestId: string, onResults: Function) {
@@ -133,7 +144,7 @@ export class ZMQKernel extends Kernel {
133144
allow_stdin: true
134145
};
135146
this.executionCallbacks.set(requestId, onResults);
136-
return this.shellSocket.send(new jmp.Message(message));
147+
return this.shellSocket.send(new this.jmp.Message(message));
137148
};
138149

139150
public execute(code: string, onResults: Function) {
@@ -156,7 +167,7 @@ export class ZMQKernel extends Kernel {
156167
cursor_pos: code.length
157168
};
158169
this.executionCallbacks.set(requestId, onResults);
159-
return this.shellSocket.send(new jmp.Message(message));
170+
return this.shellSocket.send(new this.jmp.Message(message));
160171
};
161172

162173
public inspect(code: string, cursor_pos, onResults: Function) {
@@ -168,7 +179,7 @@ export class ZMQKernel extends Kernel {
168179
detail_level: 0
169180
};
170181
this.executionCallbacks.set(requestId, onResults);
171-
return this.shellSocket.send(new jmp.Message(message));
182+
return this.shellSocket.send(new this.jmp.Message(message));
172183
};
173184

174185
public inputReply(input: string) {
@@ -177,7 +188,7 @@ export class ZMQKernel extends Kernel {
177188
message.content = {
178189
value: input
179190
};
180-
return this.stdinSocket.send(new jmp.Message(message));
191+
return this.stdinSocket.send(new this.jmp.Message(message));
181192
};
182193

183194
private onShellMessage(message: JupyterMessage) {

0 commit comments

Comments
 (0)