Skip to content

Commit

Permalink
Fix kernel spec crash (#3285)
Browse files Browse the repository at this point in the history
* Fix kernel spec parsing crash

* getInterpreterDetails returns a default if the path doesnt exist

* Make sure version info exists
  • Loading branch information
rchiodo authored Nov 9, 2018
1 parent 72be786 commit abdd5f9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/client/datascience/jupyterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as localize from '../common/utils/localize';
import { RegExpValues } from './constants';
import { JupyterInstallError } from './jupyterInstallError';
import { CellState, ICell, IJupyterExecution, INotebookProcess, INotebookServer } from './types';
import { IInterpreterService } from '../interpreter/contracts';

// This code is based on the examples here:
// https://www.npmjs.com/package/@jupyterlab/services
Expand All @@ -40,7 +41,8 @@ export class JupyterServer implements INotebookServer {
@inject(IFileSystem) private fileSystem: IFileSystem,
@inject(IDisposableRegistry) private disposableRegistry: IDisposableRegistry,
@inject(IJupyterExecution) private jupyterExecution : IJupyterExecution,
@inject(IWorkspaceService) private workspaceService: IWorkspaceService) {
@inject(IWorkspaceService) private workspaceService: IWorkspaceService,
@inject(IInterpreterService) private interpreterService: IInterpreterService) {
}

public start = async () : Promise<boolean> => {
Expand Down Expand Up @@ -355,11 +357,23 @@ export class JupyterServer implements INotebookServer {
score += 1;

// See if the version is the same
if (pythonVersion) {
const digits = spec.name.match(/\d+/g);
if (digits.length > 0 && parseInt(digits[0], 10) === pythonVersion[0]) {
// Major version match
score += 4;
if (pythonVersion && spec.argv.length > 0 && await fs.pathExists(spec.argv[0])) {
const details = await this.interpreterService.getInterpreterDetails(spec.argv[0])
if (details && details.version_info) {
if (details.version_info[0] === pythonVersion[0]) {
// Major version match
score += 4;

if (details.version_info[1] === pythonVersion[1]) {
// Minor version match
score += 2;

if (details.version_info[2] === pythonVersion[2]) {
// Minor version match
score += 1;
}
}
}
}
}
}
Expand Down

0 comments on commit abdd5f9

Please sign in to comment.