Skip to content

Commit

Permalink
Show kernel picker when starting RBL without a kernel
Browse files Browse the repository at this point in the history
Fix #7700
  • Loading branch information
roblourens committed Sep 30, 2021
1 parent 8d51eeb commit ccde11b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/client/datascience/jupyter/jupyterDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { traceInfo, traceWarning } from '../../common/logger';
import { IPlatformService } from '../../common/platform/types';
import { IConfigurationService } from '../../common/types';
import * as localize from '../../common/utils/localize';
import { isUsingIpykernel6OrLater } from '../../debugger/jupyter/helper';
import { IpykernelCheckResult, isUsingIpykernel6OrLater } from '../../debugger/jupyter/helper';
import { Identifiers } from '../constants';
import {
ICellHashListener,
Expand Down Expand Up @@ -56,7 +56,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener {
}

const settings = this.configService.getSettings(notebook.resource);
this.isUsingPyKernel6OrLater = await isUsingIpykernel6OrLater(kernel);
this.isUsingPyKernel6OrLater = (await isUsingIpykernel6OrLater(kernel)) === IpykernelCheckResult.Ok;
return this.startDebugSession(
(c) => this.debugService.startDebugging(undefined, c),
notebook,
Expand Down
33 changes: 23 additions & 10 deletions src/client/debugger/jupyter/debuggingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { IDebuggingManager, IKernelDebugAdapterConfig, KernelDebugMode } from '.
import { DebuggingTelemetry, pythonKernelDebugAdapter } from '../constants';
import { sendTelemetryEvent } from '../../telemetry';
import { DebugCellController, RunByLineController } from './debugControllers';
import { assertIsDebugConfig, isUsingIpykernel6OrLater } from './helper';
import { assertIsDebugConfig, IpykernelCheckResult, isUsingIpykernel6OrLater } from './helper';
import { Debugger } from './debugger';

/**
Expand Down Expand Up @@ -238,9 +238,9 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
return;
}

try {
this.notebookInProgress.add(editor.document);
if (await this.checkForIpykernel6(editor.document)) {
const checkIpykernelAndStart = async (allowSelectKernel = true): Promise<void> => {
const ipykernelResult = await this.checkForIpykernel6(editor.document);
if (ipykernelResult === IpykernelCheckResult.Ok) {
switch (mode) {
case KernelDebugMode.Everything:
await this.startDebugging(editor.document);
Expand All @@ -260,9 +260,20 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
}
break;
}
} else {
void this.installIpykernel6();
} else if (
ipykernelResult === IpykernelCheckResult.Missing ||
ipykernelResult === IpykernelCheckResult.Unknown
) {
void this.promptInstallIpykernel6();
} else if (ipykernelResult === IpykernelCheckResult.NoKernel && allowSelectKernel) {
await this.commandManager.executeCommand('notebook.selectKernel', { notebookEditor: editor });
return checkIpykernelAndStart(false);
}
};

try {
this.notebookInProgress.add(editor.document);
await checkIpykernelAndStart();
} finally {
this.notebookInProgress.delete(editor.document);
}
Expand Down Expand Up @@ -410,7 +421,7 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
return kernel;
}

private async checkForIpykernel6(doc: NotebookDocument): Promise<boolean> {
private async checkForIpykernel6(doc: NotebookDocument): Promise<IpykernelCheckResult> {
try {
let kernel = this.kernelProvider.get(doc);

Expand All @@ -429,17 +440,19 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb
if (kernel) {
const result = await isUsingIpykernel6OrLater(kernel);
sendTelemetryEvent(DebuggingTelemetry.ipykernel6Status, undefined, {
status: result ? 'installed' : 'notInstalled'
status: result === IpykernelCheckResult.Ok ? 'installed' : 'notInstalled'
});
return result;
} else {
return IpykernelCheckResult.NoKernel;
}
} catch {
traceError('Debugging: Could not check for ipykernel 6');
}
return false;
return IpykernelCheckResult.Unknown;
}

private async installIpykernel6() {
private async promptInstallIpykernel6() {
const response = await this.appShell.showInformationMessage(
DataScience.needIpykernel6(),
{ modal: true },
Expand Down
13 changes: 10 additions & 3 deletions src/client/debugger/jupyter/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ import { DebugProtocol } from 'vscode-debugprotocol';
import { IKernel } from '../../datascience/jupyter/kernels/types';
import { IKernelDebugAdapterConfig, KernelDebugMode } from '../types';

export async function isUsingIpykernel6OrLater(kernel: IKernel): Promise<boolean> {
export enum IpykernelCheckResult {
Unknown,
Ok,
Missing,
NoKernel
}

export async function isUsingIpykernel6OrLater(kernel: IKernel): Promise<IpykernelCheckResult> {
const code = 'import ipykernel\nprint(ipykernel.__version__)';
const output = await kernel.executeHidden(code);

if (output[0].text) {
const version = output[0].text.toString().split('.');
const majorVersion = Number(version[0]);
return majorVersion >= 6;
return majorVersion >= 6 ? IpykernelCheckResult.Ok : IpykernelCheckResult.Missing;
}

return false;
return IpykernelCheckResult.Unknown;
}

export function assertIsDebugConfig(thing: unknown): asserts thing is IKernelDebugAdapterConfig {
Expand Down

0 comments on commit ccde11b

Please sign in to comment.