diff --git a/src/client/datascience/jupyter/jupyterDebugger.ts b/src/client/datascience/jupyter/jupyterDebugger.ts index 7637dd23831..e1c27677eb2 100644 --- a/src/client/datascience/jupyter/jupyterDebugger.ts +++ b/src/client/datascience/jupyter/jupyterDebugger.ts @@ -5,11 +5,12 @@ import type { nbformat } from '@jupyterlab/coreutils'; import { inject, injectable, named } from 'inversify'; import { DebugConfiguration, Disposable } from 'vscode'; import { ServerStatus } from '../../../datascience-ui/interactive-common/mainState'; -import { IPythonDebuggerPathProvider, IPythonInstaller } from '../../api/types'; +import { IPythonDebuggerPathProvider } from '../../api/types'; import { traceInfo, traceWarning } from '../../common/logger'; import { IPlatformService } from '../../common/platform/types'; -import { IConfigurationService, Product, ProductInstallStatus } from '../../common/types'; +import { IConfigurationService } from '../../common/types'; import * as localize from '../../common/utils/localize'; +import { isUsingIpykernel6OrLater } from '../../debugger/jupyter/helper'; import { Identifiers } from '../constants'; import { ICellHashListener, @@ -40,8 +41,7 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener { @inject(IJupyterDebugService) @named(Identifiers.MULTIPLEXING_DEBUGSERVICE) private debugService: IJupyterDebugService, - @inject(IPlatformService) private platform: IPlatformService, - @inject(IPythonInstaller) private installer: IPythonInstaller + @inject(IPlatformService) private platform: IPlatformService ) { this.debuggerPackage = 'debugpy'; this.enableDebuggerCode = `import debugpy;debugpy.listen(('localhost', 0))`; @@ -54,13 +54,9 @@ export class JupyterDebugger implements IJupyterDebugger, ICellHashListener { if (!notebook) { throw new Error('Notebook not initialized'); } - const result = await this.installer.isProductVersionCompatible( - Product.ipykernel, - '>=6.0.0', - notebook.getKernelConnection()?.interpreter - ); + const settings = this.configService.getSettings(notebook.resource); - this.isUsingPyKernel6OrLater = result === ProductInstallStatus.Installed; + this.isUsingPyKernel6OrLater = await isUsingIpykernel6OrLater(kernel); return this.startDebugSession( (c) => this.debugService.startDebugging(undefined, c), notebook, diff --git a/src/client/debugger/jupyter/debuggingManager.ts b/src/client/debugger/jupyter/debuggingManager.ts index 6a784c20ba4..050ba419432 100644 --- a/src/client/debugger/jupyter/debuggingManager.ts +++ b/src/client/debugger/jupyter/debuggingManager.ts @@ -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 } from './helper'; +import { assertIsDebugConfig, isUsingIpykernel6OrLater } from './helper'; import { Debugger } from './debugger'; /** @@ -428,18 +428,11 @@ export class DebuggingManager implements IExtensionSingleActivationService, IDeb } if (kernel) { - const code = 'import ipykernel\nprint(ipykernel.__version__)'; - const output = await kernel.executeHidden(code); - - if (output[0].text) { - const majorVersion = Number(output[0].text.toString().charAt(0)); - const result = majorVersion >= 6; - - sendTelemetryEvent(DebuggingTelemetry.ipykernel6Status, undefined, { - status: result ? 'installed' : 'notInstalled' - }); - return result; - } + const result = await isUsingIpykernel6OrLater(kernel); + sendTelemetryEvent(DebuggingTelemetry.ipykernel6Status, undefined, { + status: result ? 'installed' : 'notInstalled' + }); + return result; } } catch { traceError('Debugging: Could not check for ipykernel 6'); diff --git a/src/client/debugger/jupyter/helper.ts b/src/client/debugger/jupyter/helper.ts index 48c3d8614c7..48efd56c4fb 100644 --- a/src/client/debugger/jupyter/helper.ts +++ b/src/client/debugger/jupyter/helper.ts @@ -2,8 +2,22 @@ // Licensed under the MIT License. import { DebugProtocol } from 'vscode-debugprotocol'; +import { IKernel } from '../../datascience/jupyter/kernels/types'; import { IKernelDebugAdapterConfig, KernelDebugMode } from '../types'; +export async function isUsingIpykernel6OrLater(kernel: IKernel): Promise { + 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 false; +} + export function assertIsDebugConfig(thing: unknown): asserts thing is IKernelDebugAdapterConfig { const config = thing as IKernelDebugAdapterConfig; if (