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

fix for jupyterDebugger #7695

Merged
merged 2 commits into from
Sep 28, 2021
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
16 changes: 6 additions & 10 deletions src/client/datascience/jupyter/jupyterDebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))`;
Expand All @@ -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
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe put this into a common function somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make it easier to handle the case where the ipykernel version is greater than 10.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yees, I thought this was urgent but it isn't.
So I'll add it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this should be some common code,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave this here and fix in debt week or fix this now, i leave that upto you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not doing now, please file an issue so we don't forget (to fix in debt week)

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,
Expand Down
19 changes: 6 additions & 13 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 } from './helper';
import { assertIsDebugConfig, isUsingIpykernel6OrLater } from './helper';
import { Debugger } from './debugger';

/**
Expand Down Expand Up @@ -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');
Expand Down
14 changes: 14 additions & 0 deletions src/client/debugger/jupyter/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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 (
Expand Down