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

Proposal: Isomorphic pythonVariableRequester and debuggerVariables.ts #10142

Merged
merged 7 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 4 additions & 6 deletions src/kernels/kernel.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

'use strict';
import * as path from '../platform/vscode-path/path';
import { NotebookController, Uri } from 'vscode';
import { IApplicationShell, IWorkspaceService } from '../platform/common/application/types';
import { traceInfo, traceError } from '../platform/logging';
Expand All @@ -27,7 +26,6 @@ import { IStatusProvider } from '../platform/progress/types';
import { getAssociatedNotebookDocument } from '../notebooks/controllers/kernelSelector';
import { sendTelemetryForPythonKernelExecutable } from './helpers.node';
import { BaseKernel } from './kernel.base';
import { EXTENSION_ROOT_DIR } from '../platform/constants.node';

export class Kernel extends BaseKernel {
constructor(
Expand All @@ -46,7 +44,7 @@ export class Kernel extends BaseKernel {
private readonly pythonExecutionFactory: IPythonExecutionFactory,
statusProvider: IStatusProvider,
creator: KernelActionSource,
context: IExtensionContext,
private readonly context: IExtensionContext,
formatters: ITracebackFormatter[]
) {
super(
Expand Down Expand Up @@ -81,9 +79,9 @@ export class Kernel extends BaseKernel {
if (getAssociatedNotebookDocument(this)?.notebookType === InteractiveWindowView) {
// If using ipykernel 6, we need to set the IPYKERNEL_CELL_NAME so that
// debugging can work. However this code is harmless for IPYKERNEL 5 so just always do it
const scriptPath = path.join(EXTENSION_ROOT_DIR, AddRunCellHook.ScriptPath);
if (await this.fs.localFileExists(scriptPath)) {
const fileContents = await this.fs.readLocalFile(scriptPath);
const scriptPath = AddRunCellHook.getScriptPath(this.context);
if (await this.fs.localFileExists(scriptPath.fsPath)) {
const fileContents = await this.fs.readLocalFile(scriptPath.fsPath);
return fileContents.splitLines({ trim: false });
}
traceError(`Cannot run non-existent script file: ${scriptPath}`);
Expand Down
14 changes: 7 additions & 7 deletions src/kernels/variables/debuggerVariables.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getAssociatedNotebookDocument } from '../../notebooks/controllers/kerne
import { IDebugService, IVSCodeNotebook } from '../../platform/common/application/types';
import { DataFrameLoading, GetVariableInfo } from '../../platform/common/scriptConstants';
import { traceError } from '../../platform/logging';
import { IConfigurationService, Resource } from '../../platform/common/types';
import { IConfigurationService, IExtensionContext, Resource } from '../../platform/common/types';
import { DebugLocationTracker } from '../debugger/debugLocationTracker';
import { sendTelemetryEvent } from '../../telemetry';
import { Identifiers, Telemetry } from '../../webviews/webview-side/common/constants';
Expand All @@ -24,7 +24,6 @@ import {
IJupyterVariablesResponse
} from './types';
import { convertDebugProtocolVariableToIJupyterVariable, DataViewableTypes } from './helpers';
import { EXTENSION_ROOT_DIR } from '../../platform/constants.node';
import { IFileSystemNode } from '../../platform/common/platform/types.node';

const KnownExcludedVariables = new Set<string>(['In', 'Out', 'exit', 'quit']);
Expand All @@ -49,7 +48,8 @@ export class DebuggerVariables
@inject(IDebuggingManager) private readonly debuggingManager: IDebuggingManager,
@inject(IConfigurationService) private configService: IConfigurationService,
@inject(IVSCodeNotebook) private readonly vscNotebook: IVSCodeNotebook,
@inject(IFileSystemNode) private readonly fs: IFileSystemNode
@inject(IFileSystemNode) private readonly fs: IFileSystemNode,
@inject(IExtensionContext) private readonly context: IExtensionContext
) {
super(undefined);
this.debuggingManager.onDoneDebugging(() => this.refreshEventEmitter.fire(), this);
Expand Down Expand Up @@ -319,8 +319,8 @@ export class DebuggerVariables
// Run our dataframe scripts only once per session because they're slow
const key = this.debugService.activeDebugSession?.id;
if (key && !this.importedDataFrameScriptsIntoKernel.has(key)) {
const scriptPath = path.join(EXTENSION_ROOT_DIR, DataFrameLoading.ScriptPath);
const contents = await this.fs.readLocalFile(scriptPath);
const scriptPath = DataFrameLoading.getScriptPath(this.context);
sadasant marked this conversation as resolved.
Show resolved Hide resolved
const contents = await this.fs.readLocalFile(scriptPath.fsPath);
await this.evaluate(contents);
this.importedDataFrameScriptsIntoKernel.add(key);
}
Expand All @@ -334,8 +334,8 @@ export class DebuggerVariables
// Run our variable info scripts only once per session because they're slow
const key = this.debugService.activeDebugSession?.id;
if (key && !this.importedGetVariableInfoScriptsIntoKernel.has(key)) {
const scriptPath = path.join(EXTENSION_ROOT_DIR, DataFrameLoading.ScriptPath);
const contents = await this.fs.readLocalFile(scriptPath);
const scriptPath = DataFrameLoading.getScriptPath(this.context);
const contents = await this.fs.readLocalFile(scriptPath.fsPath);
await this.evaluate(contents);
this.importedGetVariableInfoScriptsIntoKernel.add(key);
}
Expand Down
5 changes: 2 additions & 3 deletions src/kernels/variables/pythonVariableRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { IKernel } from '../types';
import { IKernelVariableRequester, IJupyterVariable } from './types';
import { getAssociatedNotebookDocument } from '../../notebooks/controllers/kernelSelector';
import { DataFrameLoading, GetVariableInfo } from '../../platform/common/scriptConstants';
import { joinPath } from '../../platform/vscode-path/resources';
import { IExtensionContext } from '../../platform/common/types';

type DataFrameSplitFormat = {
Expand Down Expand Up @@ -227,7 +226,7 @@ export class PythonVariablesRequester implements IKernelVariableRequester {
disposables.push(kernel.onRestarted(handler));

// First put the code from our helper files into the notebook
await this.runScriptFile(kernel, joinPath(this.context.extensionUri, DataFrameLoading.ScriptPath));
await this.runScriptFile(kernel, DataFrameLoading.getScriptPath(this.context));

this.importedDataFrameScripts.set(key, true);
}
Expand All @@ -245,7 +244,7 @@ export class PythonVariablesRequester implements IKernelVariableRequester {
disposables.push(kernel.onDisposed(handler));
disposables.push(kernel.onRestarted(handler));

await this.runScriptFile(kernel, joinPath(this.context.extensionUri, GetVariableInfo.ScriptPath));
await this.runScriptFile(kernel, GetVariableInfo.getScriptPath(this.context));

this.importedGetVariableInfoScripts.set(key, true);
}
Expand Down
39 changes: 30 additions & 9 deletions src/platform/common/scriptConstants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import * as path from '../vscode-path/path';

export * from './constants';
import { joinPath } from '../vscode-path/resources';
import { IExtensionContext } from './types';

export namespace DataFrameLoading {
export const SysPath = path.join('pythonFiles', 'vscode_datascience_helpers', 'dataframes');
export const ScriptPath = path.join(SysPath, 'vscodeDataFrame.py');
export function getScriptPath(context: IExtensionContext) {
return joinPath(
context.extensionUri,
'pythonFiles',
'vscode_datascience_helpers',
'dataframes',
'vscodeDataFrame.py'
);
}

export const DataFrameInfoFunc = '_VSCODE_getDataFrameInfo';
export const DataFrameRowFunc = '_VSCODE_getDataFrameRows';
Expand All @@ -16,8 +22,16 @@ export namespace DataFrameLoading {
}

export namespace GetVariableInfo {
export const SysPath = path.join('pythonFiles', 'vscode_datascience_helpers', 'getVariableInfo');
export const ScriptPath = path.join(SysPath, 'vscodeGetVariableInfo.py');
export function getScriptPath(context: IExtensionContext) {
return joinPath(
context.extensionUri,
'pythonFiles',
'vscode_datascience_helpers',
'getVariableInfo',
'vscodeGetVariableInfo.py'
);
}

export const VariableInfoFunc = '_VSCODE_getVariableInfo';
export const VariablePropertiesFunc = '_VSCODE_getVariableProperties';
export const VariableTypesFunc = '_VSCODE_getVariableTypes';
Expand All @@ -28,6 +42,13 @@ export namespace GetVariableInfo {
}

export namespace AddRunCellHook {
export const SysPath = path.join('pythonFiles', 'vscode_datascience_helpers', 'kernel');
export const ScriptPath = path.join(SysPath, 'addRunCellHook.py');
export function getScriptPath(context: IExtensionContext) {
return joinPath(
context.extensionUri,
'pythonFiles',
'vscode_datascience_helpers',
'kernel',
'addRunCellHook.py'
);
}
}
6 changes: 3 additions & 3 deletions src/test/datascience/widgets/notebooks/bqplot_widgets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -27,13 +27,13 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4d526b44599140a794c03e362abdc492",
"model_id": "f3105e6a4c5a40ffb76b1c53af545298",
"version_major": 2,
"version_minor": 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IKernel } from '../../../kernels/types';
import { IJupyterVariable, IJupyterVariables } from '../../../kernels/variables/types';
import { traceError } from '../../../platform/logging';
import { Identifiers } from '../../webview-side/common/constants';
import { getFilePath } from '../../../platform/common/platform/fs-paths';

@injectable()
export class JupyterVariableDataProvider implements IJupyterVariableDataProvider {
Expand Down Expand Up @@ -115,7 +116,7 @@ export class JupyterVariableDataProvider implements IJupyterVariableDataProvider
type: variable.type,
maximumRowChunkSize: variable.maximumRowChunkSize,
name: variable.name,
fileName: variable.fileName?.path
fileName: getFilePath(variable.fileName)
};
}
if (isRefresh) {
Expand Down