move variable providers to /standalone (#15627)

* move variable providers to /standalone

* move parent class back to kernel

* fix imports

* formatting

* reverted unneeded changes

* formatting

* better relevance check
This commit is contained in:
Aaron Munger 2024-04-30 14:33:51 -07:00 коммит произвёл GitHub
Родитель 12db3c8029
Коммит 9cd315582c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
19 изменённых файлов: 114 добавлений и 161 удалений

Просмотреть файл

@ -16,8 +16,7 @@ import {
IJupyterConnection,
GetServerOptions,
LiveRemoteKernelConnectionMetadata,
RemoteKernelConnectionMetadata,
IKernel
RemoteKernelConnectionMetadata
} from '../types';
import { ClassType } from '../../platform/ioc/types';
import { ContributedKernelFinderKind, IContributedKernelFinder } from '../internalTypes';
@ -258,12 +257,3 @@ export interface IJupyterServerProviderRegistry {
serverProvider: JupyterServerProvider
): JupyterServerCollection;
}
export const IBackgroundThreadService = Symbol('IBackgroundThreadService');
export interface IBackgroundThreadService {
execCodeInBackgroundThread<T>(
kernel: IKernel,
codeWithReturnStatement: string[],
token: CancellationToken
): Promise<T | undefined>;
}

Просмотреть файл

@ -42,10 +42,7 @@ import {
IThirdPartyKernelProvider
} from './types';
import { JupyterVariables } from './variables/jupyterVariables';
import { KernelVariables } from './variables/kernelVariables';
import { PreWarmActivatedJupyterEnvironmentVariables } from './variables/preWarmVariables.node';
import { PythonVariablesRequester } from './variables/pythonVariableRequester';
import { IJupyterVariables, IKernelVariableRequester } from './variables/types';
import { IJupyterVariables } from './variables/types';
import { LastCellExecutionTracker } from './execution/lastCellExecutionTracker';
import { ClearJupyterServersCommand } from './jupyter/clearJupyterServersCommand';
import { KernelChatStartupCodeProvider } from './chat/kernelStartupCodeProvider';
@ -91,17 +88,8 @@ export function registerTypes(serviceManager: IServiceManager, isDevMode: boolea
);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelStatusProvider);
serviceManager.addSingleton<IExtensionSyncActivationService>(
IExtensionSyncActivationService,
PreWarmActivatedJupyterEnvironmentVariables
);
serviceManager.addSingleton<IJupyterVariables>(IJupyterVariables, JupyterVariables, Identifiers.ALL_VARIABLES);
serviceManager.addSingleton<IJupyterVariables>(IJupyterVariables, KernelVariables, Identifiers.KERNEL_VARIABLES);
serviceManager.addSingleton<IKernelVariableRequester>(
IKernelVariableRequester,
PythonVariablesRequester,
Identifiers.PYTHON_VARIABLES_REQUESTER
);
serviceManager.addSingleton<IKernelDependencyService>(IKernelDependencyService, KernelDependencyService);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelCrashMonitor);
serviceManager.addSingleton<IExtensionSyncActivationService>(

Просмотреть файл

@ -21,10 +21,8 @@ import {
import { KernelProvider, ThirdPartyKernelProvider } from './kernelProvider.web';
import { KernelFinder } from './kernelFinder';
import { PreferredRemoteKernelIdProvider } from './jupyter/connection/preferredRemoteKernelIdProvider';
import { IJupyterVariables, IKernelVariableRequester } from './variables/types';
import { KernelVariables } from './variables/kernelVariables';
import { IJupyterVariables } from './variables/types';
import { JupyterVariables } from './variables/jupyterVariables';
import { PythonVariablesRequester } from './variables/pythonVariableRequester';
import { CellOutputDisplayIdTracker } from './execution/cellDisplayIdTracker';
import { KernelAutoReconnectMonitor } from './kernelAutoReConnectMonitor';
import { TrustedKernelPaths } from './raw/finder/trustedKernelPaths.web';
@ -58,13 +56,7 @@ export function registerTypes(serviceManager: IServiceManager, isDevMode: boolea
const rawService = serviceManager.get<IRawNotebookSupportedService>(IRawNotebookSupportedService);
setSharedProperty('rawKernelSupported', rawService.isSupported ? 'true' : 'false');
serviceManager.addSingleton<IStartupCodeProviders>(IStartupCodeProviders, KernelStartupCodeProviders);
serviceManager.addSingleton<IKernelVariableRequester>(
IKernelVariableRequester,
PythonVariablesRequester,
Identifiers.PYTHON_VARIABLES_REQUESTER
);
serviceManager.addSingleton<IJupyterVariables>(IJupyterVariables, JupyterVariables, Identifiers.ALL_VARIABLES);
serviceManager.addSingleton<IJupyterVariables>(IJupyterVariables, KernelVariables, Identifiers.KERNEL_VARIABLES);
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelCrashMonitor);
serviceManager.addSingleton<IExtensionSyncActivationService>(

Просмотреть файл

@ -29,3 +29,25 @@ export function convertDebugProtocolVariableToIJupyterVariable(variable: DebugPr
frameId: variable.variablesReference
};
}
export type DataFrameSplitFormat = {
index: (number | string)[];
columns: string[];
data: Record<string, unknown>[];
};
export function parseDataFrame(df: DataFrameSplitFormat) {
const rowIndexValues = df.index;
const columns = df.columns;
const rowData = df.data;
const data = rowData.map((row, index) => {
const rowData: Record<string, unknown> = {
index: rowIndexValues[index]
};
columns.forEach((column, columnIndex) => {
rowData[column] = row[columnIndex];
});
return rowData;
});
return { data };
}

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { CancellationToken, Event, Uri, Variable } from 'vscode';
import { CancellationToken, Event, NotebookVariableProvider, Uri, Variable } from 'vscode';
import { IKernel } from '../types';
import type { JSONObject } from '@lumino/coreutils';
@ -143,3 +143,6 @@ export interface IKernelVariableRequester {
): Promise<string | undefined>;
getDataFrameInfo(targetVariable: IJupyterVariable, kernel: IKernel, expression: string): Promise<IJupyterVariable>;
}
export const IJupyterVariablesProvider = Symbol('IJupyterVariablesProvider');
export interface IJupyterVariablesProvider extends NotebookVariableProvider {}

Просмотреть файл

@ -9,7 +9,7 @@ import { IKernelFinder, IKernelProvider, isRemoteConnection, KernelConnectionMet
import { IExtensionSyncActivationService } from '../../platform/activation/types';
import { IPythonExtensionChecker } from '../../platform/api/types';
import { isCancellationError } from '../../platform/common/cancellation';
import { isCI, JupyterNotebookView, InteractiveWindowView, Identifiers } from '../../platform/common/constants';
import { isCI, JupyterNotebookView, InteractiveWindowView } from '../../platform/common/constants';
import {
IDisposableRegistry,
IConfigurationService,
@ -30,7 +30,7 @@ import {
IVSCodeNotebookControllerUpdateEvent
} from './types';
import { VSCodeNotebookController } from './vscodeNotebookController';
import { IJupyterVariables } from '../../kernels/variables/types';
import { IJupyterVariablesProvider } from '../../kernels/variables/types';
/**
* Keeps track of registered controllers and available KernelConnectionMetadatas.
@ -360,7 +360,7 @@ export class ControllerRegistration implements IControllerRegistration, IExtensi
this.extensionChecker,
this.serviceContainer,
this.serviceContainer.get<IConnectionDisplayDataProvider>(IConnectionDisplayDataProvider),
this.serviceContainer.get<IJupyterVariables>(IJupyterVariables, Identifiers.KERNEL_VARIABLES)
this.serviceContainer.get<IJupyterVariablesProvider>(IJupyterVariablesProvider)
);
// Hook up to if this NotebookController is selected or de-selected
const controllerDisposables: IDisposable[] = [];

Просмотреть файл

@ -80,10 +80,9 @@ import { getParentHeaderMsgId } from '../../kernels/execution/cellExecutionMessa
import { DisposableStore } from '../../platform/common/utils/lifecycle';
import { openInBrowser } from '../../platform/common/net/browser';
import { KernelError } from '../../kernels/errors/kernelError';
import { JupyterVariablesProvider } from '../../kernels/variables/JupyterVariablesProvider';
import { IJupyterVariables } from '../../kernels/variables/types';
import { getVersion } from '../../platform/interpreter/helpers';
import { getNotebookTelemetryTracker, trackControllerCreation } from '../../kernels/telemetry/notebookTelemetry';
import { IJupyterVariablesProvider } from '../../kernels/variables/types';
/**
* Our implementation of the VSCode Notebook Controller. Called by VS code to execute cells in a notebook. Also displayed
@ -159,7 +158,7 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
extensionChecker: IPythonExtensionChecker,
serviceContainer: IServiceContainer,
displayDataProvider: IConnectionDisplayDataProvider,
jupyterVariables: IJupyterVariables
jupyterVairablesProvider: IJupyterVariablesProvider
): IVSCodeNotebookController {
const controller = new VSCodeNotebookController(
kernelConnection,
@ -174,7 +173,12 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
serviceContainer,
displayDataProvider
);
controller.attachVariableProvider(jupyterVariables);
try {
controller.controller.variableProvider = jupyterVairablesProvider;
} catch (ex) {
traceWarning('Failed to attach variable provider', ex);
}
return controller;
}
@ -225,21 +229,6 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
);
}
private attachVariableProvider(jupyterVariables: IJupyterVariables) {
try {
if (this.controller.supportedLanguages && this.controller.supportedLanguages.includes('python')) {
this.controller.variableProvider = new JupyterVariablesProvider(
jupyterVariables,
this.kernelProvider,
this.id,
this.disposables
);
}
} catch (ex) {
traceWarning('Failed to attach variable provider', ex);
}
}
private readonly restoredConnections = new WeakSet<NotebookDocument>();
public async restoreConnection(notebook: NotebookDocument) {

Просмотреть файл

@ -8,8 +8,11 @@ import * as uriPath from '../../platform/vscode-path/resources';
import { DebugAdapterTracker, Disposable, Event, EventEmitter, window } from 'vscode';
import { DebugProtocol } from 'vscode-debugprotocol';
import { IKernel, IKernelProvider } from '../../kernels/types';
import { convertDebugProtocolVariableToIJupyterVariable, DataViewableTypes } from '../../kernels/variables/helpers';
import { parseDataFrame } from '../../kernels/variables/pythonVariableRequester';
import {
convertDebugProtocolVariableToIJupyterVariable,
DataViewableTypes,
parseDataFrame
} from '../../kernels/variables/helpers';
import {
IConditionalJupyterVariables,
IJupyterVariable,

Просмотреть файл

@ -10,19 +10,6 @@ import { raceCancellation } from '../../../platform/common/cancellation';
import { getNotebookCellOutputMetadata } from '../../../kernels/execution/helpers';
import { unTrackDisplayDataForExtension } from '../../../kernels/execution/extensionDisplayDataTracker';
import { traceWarning } from '../../../platform/logging';
import { IBackgroundThreadService } from '../../../kernels/jupyter/types';
import { injectable } from 'inversify';
@injectable()
export class BackgroundThreadService implements IBackgroundThreadService {
execCodeInBackgroundThread<T>(
kernel: IKernel,
codeWithReturnStatement: string[],
token: CancellationToken
): Promise<T | undefined> {
return execCodeInBackgroundThread(kernel, codeWithReturnStatement, token);
}
}
export const executionCounters = new WeakMap<IKernel, number>();
export async function execCodeInBackgroundThread<T>(

Просмотреть файл

@ -7,7 +7,7 @@ import { IKernel, IKernelProvider } from '../../kernels/types';
import { execCodeInBackgroundThread } from '../api/kernels/backgroundExecution';
import { ServiceContainer } from '../../platform/ioc/container';
import { IControllerRegistration } from '../../notebooks/controllers/types';
import { JupyterVariablesProvider } from '../../kernels/variables/JupyterVariablesProvider';
import { JupyterVariablesProvider } from '../variables/JupyterVariablesProvider';
import { traceWarning } from '../../platform/logging';
export async function activate(context: vscode.ExtensionContext): Promise<void> {

Просмотреть файл

@ -3,7 +3,7 @@
import { IExtensionActivationManager, IExtensionSyncActivationService } from '../platform/activation/types';
import { IServiceManager } from '../platform/ioc/types';
import { IBackgroundThreadService, INotebookExporter, INotebookImporter } from '../kernels/jupyter/types';
import { INotebookExporter, INotebookImporter } from '../kernels/jupyter/types';
import { JupyterExporter } from './import-export/jupyterExporter';
import { JupyterImporter } from './import-export/jupyterImporter.node';
import { CommandRegistry as ExportCommandRegistry } from './import-export/commandRegistry';
@ -27,7 +27,12 @@ import { EagerlyActivateJupyterUriProviders } from './api/unstable/activateJupyt
import { ExposeUsedAzMLServerHandles } from './api/unstable/usedAzMLServerHandles.deprecated';
import { IExportedKernelServiceFactory } from './api/unstable/types';
import { KernelApi } from './api/kernels/accessManagement';
import { BackgroundThreadService } from './api/kernels/backgroundExecution';
import { JupyterVariablesProvider } from './variables/JupyterVariablesProvider';
import { IJupyterVariables, IJupyterVariablesProvider, IKernelVariableRequester } from '../kernels/variables/types';
import { KernelVariables } from './variables/kernelVariables';
import { Identifiers } from '../platform/common/constants';
import { PythonVariablesRequester } from './variables/pythonVariableRequester';
import { PreWarmActivatedJupyterEnvironmentVariables } from './variables/preWarmVariables.node';
export function registerTypes(context: IExtensionContext, serviceManager: IServiceManager, isDevMode: boolean) {
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, GlobalActivation);
@ -99,5 +104,16 @@ export function registerTypes(context: IExtensionContext, serviceManager: IServi
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelApi);
serviceManager.addSingleton<IBackgroundThreadService>(IBackgroundThreadService, BackgroundThreadService);
// Variables
serviceManager.addSingleton<IJupyterVariablesProvider>(IJupyterVariablesProvider, JupyterVariablesProvider);
serviceManager.addSingleton<IJupyterVariables>(IJupyterVariables, KernelVariables, Identifiers.KERNEL_VARIABLES);
serviceManager.addSingleton<IKernelVariableRequester>(
IKernelVariableRequester,
PythonVariablesRequester,
Identifiers.PYTHON_VARIABLES_REQUESTER
);
serviceManager.addSingleton<IExtensionSyncActivationService>(
IExtensionSyncActivationService,
PreWarmActivatedJupyterEnvironmentVariables
);
}

Просмотреть файл

@ -6,7 +6,7 @@ import { IExtensionActivationManager, IExtensionSyncActivationService } from '..
import { CommandRegistry as ExportCommandRegistry } from './import-export/commandRegistry';
import { ActiveEditorContextService } from './context/activeEditorContext';
import { GlobalActivation } from './activation/globalActivation';
import { IBackgroundThreadService, INotebookExporter } from '../kernels/jupyter/types';
import { INotebookExporter } from '../kernels/jupyter/types';
import { JupyterExporter } from './import-export/jupyterExporter';
import { JupyterKernelServiceFactory } from './api/unstable/kernelApi';
import { ApiAccessService } from './api/unstable/apiAccessService';
@ -23,7 +23,11 @@ import { EagerlyActivateJupyterUriProviders } from './api/unstable/activateJupyt
import { ExposeUsedAzMLServerHandles } from './api/unstable/usedAzMLServerHandles.deprecated';
import { IExportedKernelServiceFactory } from './api/unstable/types';
import { KernelApi } from './api/kernels/accessManagement';
import { BackgroundThreadService } from './api/kernels/backgroundExecution';
import { JupyterVariablesProvider } from './variables/JupyterVariablesProvider';
import { IJupyterVariables, IJupyterVariablesProvider, IKernelVariableRequester } from '../kernels/variables/types';
import { Identifiers } from '../platform/common/constants';
import { KernelVariables } from './variables/kernelVariables';
import { PythonVariablesRequester } from './variables/pythonVariableRequester';
export function registerTypes(context: IExtensionContext, serviceManager: IServiceManager, isDevMode: boolean) {
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, GlobalActivation);
@ -87,5 +91,12 @@ export function registerTypes(context: IExtensionContext, serviceManager: IServi
serviceManager.addSingleton<IExtensionSyncActivationService>(IExtensionSyncActivationService, KernelApi);
serviceManager.addSingleton<IBackgroundThreadService>(IBackgroundThreadService, BackgroundThreadService);
// Variables
serviceManager.addSingleton<IJupyterVariablesProvider>(IJupyterVariablesProvider, JupyterVariablesProvider);
serviceManager.addSingleton<IJupyterVariables>(IJupyterVariables, KernelVariables, Identifiers.KERNEL_VARIABLES);
serviceManager.addSingleton<IKernelVariableRequester>(
IKernelVariableRequester,
PythonVariablesRequester,
Identifiers.PYTHON_VARIABLES_REQUESTER
);
}

Просмотреть файл

@ -5,8 +5,8 @@ import { assert } from 'chai';
import { JupyterVariablesProvider } from './JupyterVariablesProvider';
import { NotebookDocument, CancellationTokenSource, EventEmitter, VariablesResult, Variable, Disposable } from 'vscode';
import { mock, instance, when, anything, verify, objectContaining } from 'ts-mockito';
import { IKernelProvider, IKernel } from '../types';
import { IJupyterVariables, IVariableDescription } from './types';
import { IKernelProvider, IKernel } from '../../kernels/types';
import { IJupyterVariables, IVariableDescription } from '../../kernels/variables/types';
suite('JupyterVariablesProvider', () => {
let variables: IJupyterVariables;
@ -81,12 +81,7 @@ suite('JupyterVariablesProvider', () => {
kernelProvider = mock<IKernelProvider>();
when(kernelProvider.onKernelStatusChanged).thenReturn(kernelEventEmitter.event);
when(kernelProvider.get(anything())).thenReturn(instance(kernel));
provider = new JupyterVariablesProvider(
instance(variables),
instance(kernelProvider),
controllerId,
disposables
);
provider = new JupyterVariablesProvider(instance(variables), instance(kernelProvider));
});
test('provideVariables without parent should yield variables', async () => {
@ -328,19 +323,4 @@ suite('JupyterVariablesProvider', () => {
assert.include(variablesChangedForNotebooks, '/1.ipynb');
assert.include(variablesChangedForNotebooks, '/2.ipynb');
});
test('Kernel restart are handled by only one variable provider', async () => {
new JupyterVariablesProvider(instance(variables), instance(kernelProvider), 'different', disposables);
let variablesChangedForNotebooks: string[] = [];
provider.onDidChangeVariables((e) => {
variablesChangedForNotebooks.push(e.uri.path);
});
fireKernelStatusChange('/1.ipynb', 'idle');
fireKernelStatusChange('/1.ipynb', 'restarting');
fireKernelStatusChange('/1.ipynb', 'idle');
assert.equal(variablesChangedForNotebooks.length, 1, 'variable change event should have fired once');
});
});

Просмотреть файл

@ -4,18 +4,20 @@
import {
CancellationToken,
NotebookDocument,
NotebookVariableProvider,
Variable,
NotebookVariablesRequestKind,
VariablesResult,
EventEmitter
} from 'vscode';
import { IJupyterVariables, IRichVariableResult, IVariableDescription } from './types';
import { IKernel, IKernelProvider } from '../types';
import { IJupyterVariables, IRichVariableResult, IVariableDescription } from '../../kernels/variables/types';
import { IKernel, IKernelProvider } from '../../kernels/types';
import { VariableResultCache, VariableSummaryCache } from './variableResultCache';
import { IDisposable } from '../../platform/common/types';
import { inject, injectable, named } from 'inversify';
import { Identifiers } from '../../platform/common/constants';
import { IJupyterVariablesProvider } from '../../kernels/variables/types';
export class JupyterVariablesProvider implements NotebookVariableProvider {
@injectable()
export class JupyterVariablesProvider implements IJupyterVariablesProvider {
private variableResultCache = new VariableResultCache();
private variableSummaryCache = new VariableSummaryCache();
private runningKernels = new Set<string>();
@ -24,24 +26,23 @@ export class JupyterVariablesProvider implements NotebookVariableProvider {
onDidChangeVariables = this._onDidChangeVariables.event;
constructor(
private readonly variables: IJupyterVariables,
private readonly kernelProvider: IKernelProvider,
private readonly controllerId: string,
disposables: IDisposable[]
@inject(IJupyterVariables) @named(Identifiers.KERNEL_VARIABLES) private variables: IJupyterVariables,
@inject(IKernelProvider) private kernelProvider: IKernelProvider
) {
disposables.push(this.kernelProvider.onKernelStatusChanged(this.onKernelStatusChanged, this));
this.kernelProvider.onKernelStatusChanged(this.onKernelStatusChanged, this);
}
private onKernelStatusChanged({ kernel }: { kernel: IKernel }) {
if (kernel.controller.id !== this.controllerId) {
if ('variableProvider' in kernel.controller && kernel.controller.variableProvider !== this) {
return;
}
const kernelWasRunning = this.runningKernels.has(kernel.notebook.uri.toString());
const notebookUri = kernel.notebook.uri.toString();
const kernelWasRunning = this.runningKernels.has(notebookUri);
if (kernel.status === 'idle' && !kernelWasRunning) {
this.runningKernels.add(kernel.notebook.uri.toString());
this.runningKernels.add(notebookUri);
} else if (kernel.status !== 'busy' && kernel.status !== 'idle' && kernelWasRunning) {
this.runningKernels.delete(kernel.notebook.uri.toString());
this.runningKernels.delete(notebookUri);
this._onDidChangeVariables.fire(kernel.notebook);
}
}
@ -65,6 +66,7 @@ export class JupyterVariablesProvider implements NotebookVariableProvider {
if (token.isCancellationRequested) {
return;
}
const kernel = this.kernelProvider.get(notebook);
if (!kernel || kernel.status === 'dead' || kernel.status === 'terminating') {
return;

Просмотреть файл

@ -8,8 +8,8 @@ import { Identifiers, PYTHON_LANGUAGE } from '../../platform/common/constants';
import { IConfigurationService, IDisposableRegistry } from '../../platform/common/types';
import { createDeferred } from '../../platform/common/utils/async';
import { stripAnsi } from '../../platform/common/utils/regexp';
import { getKernelConnectionLanguage, isPythonKernelConnection } from '../helpers';
import { IKernel, IKernelProvider } from '../types';
import { getKernelConnectionLanguage, isPythonKernelConnection } from '../../kernels/helpers';
import { IKernel, IKernelProvider } from '../../kernels/types';
import {
IJupyterVariable,
IJupyterVariables,
@ -17,7 +17,7 @@ import {
IJupyterVariablesResponse,
IKernelVariableRequester,
IVariableDescription
} from './types';
} from '../../kernels/variables/types';
import type { Kernel } from '@jupyterlab/services';
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports

Просмотреть файл

@ -8,8 +8,8 @@ import { CondaService } from '../../platform/interpreter/condaService.node';
import { IDisposableRegistry } from '../../platform/common/types';
import { noop } from '../../platform/common/utils/misc';
import { IEnvironmentActivationService } from '../../platform/interpreter/activation/types';
import { JupyterInterpreterService } from '../jupyter/interpreter/jupyterInterpreterService.node';
import { IRawNotebookSupportedService } from '../raw/types';
import { JupyterInterpreterService } from '../../kernels/jupyter/interpreter/jupyterInterpreterService.node';
import { IRawNotebookSupportedService } from '../../kernels/raw/types';
/**
* Computes interpreter environment variables when starting up.

Просмотреть файл

@ -10,10 +10,10 @@ import { CondaService } from '../../platform/interpreter/condaService.node';
import { createDeferred } from '../../platform/common/utils/async';
import { IEnvironmentActivationService } from '../../platform/interpreter/activation/types';
import { PythonEnvironment } from '../../platform/pythonEnvironments/info';
import { JupyterInterpreterService } from '../jupyter/interpreter/jupyterInterpreterService.node';
import { JupyterInterpreterService } from '../../kernels/jupyter/interpreter/jupyterInterpreterService.node';
import { PreWarmActivatedJupyterEnvironmentVariables } from './preWarmVariables.node';
import { sleep } from '../../test/core';
import { IRawNotebookSupportedService } from '../raw/types';
import { IRawNotebookSupportedService } from '../../kernels/raw/types';
suite('PreWarm Env Vars', () => {
let activationService: IExtensionSyncActivationService;

Просмотреть файл

@ -9,34 +9,13 @@ import { DataScience } from '../../platform/common/utils/localize';
import { stripAnsi } from '../../platform/common/utils/regexp';
import { JupyterDataRateLimitError } from '../../platform/errors/jupyterDataRateLimitError';
import { Telemetry } from '../../telemetry';
import { executeSilently, SilentExecutionErrorOptions } from '../helpers';
import { IKernel } from '../types';
import { IKernelVariableRequester, IJupyterVariable, IVariableDescription } from './types';
import { executeSilently, SilentExecutionErrorOptions } from '../../kernels/helpers';
import { IKernel } from '../../kernels/types';
import { IKernelVariableRequester, IJupyterVariable, IVariableDescription } from '../../kernels/variables/types';
import { IDataFrameScriptGenerator, IVariableScriptGenerator } from '../../platform/common/types';
import { SessionDisposedError } from '../../platform/errors/sessionDisposedError';
import { IBackgroundThreadService } from '../jupyter/types';
type DataFrameSplitFormat = {
index: (number | string)[];
columns: string[];
data: Record<string, unknown>[];
};
export function parseDataFrame(df: DataFrameSplitFormat) {
const rowIndexValues = df.index;
const columns = df.columns;
const rowData = df.data;
const data = rowData.map((row, index) => {
const rowData: Record<string, unknown> = {
index: rowIndexValues[index]
};
columns.forEach((column, columnIndex) => {
rowData[column] = row[columnIndex];
});
return rowData;
});
return { data };
}
import { execCodeInBackgroundThread } from '../api/kernels/backgroundExecution';
import { DataFrameSplitFormat, parseDataFrame } from '../../kernels/variables/helpers';
async function safeExecuteSilently(
kernel: IKernel,
@ -76,8 +55,7 @@ async function safeExecuteSilently(
export class PythonVariablesRequester implements IKernelVariableRequester {
constructor(
@inject(IVariableScriptGenerator) private readonly varScriptGenerator: IVariableScriptGenerator,
@inject(IDataFrameScriptGenerator) private readonly dfScriptGenerator: IDataFrameScriptGenerator,
@inject(IBackgroundThreadService) private readonly backgroundThreadService: IBackgroundThreadService
@inject(IDataFrameScriptGenerator) private readonly dfScriptGenerator: IDataFrameScriptGenerator
) {}
public async getDataFrameInfo(
@ -154,11 +132,7 @@ export class PythonVariablesRequester implements IKernelVariableRequester {
const code = await this.varScriptGenerator.generateCodeToGetVariableValueSummary(targetVariable.name);
try {
const content = await this.backgroundThreadService.execCodeInBackgroundThread<{ summary: string }>(
kernel,
code.split(/\r?\n/),
token
);
const content = await execCodeInBackgroundThread<{ summary: string }>(kernel, code.split(/\r?\n/), token);
return content?.summary;
} catch (ex) {
@ -182,11 +156,7 @@ export class PythonVariablesRequester implements IKernelVariableRequester {
const options = parent ? { root: parent.root, propertyChain: parent.propertyChain, startIndex } : undefined;
const code = await this.varScriptGenerator.generateCodeToGetAllVariableDescriptions(options);
const content = await this.backgroundThreadService.execCodeInBackgroundThread<IVariableDescription[]>(
kernel,
code.split(/\r?\n/),
token
);
const content = await execCodeInBackgroundThread<IVariableDescription[]>(kernel, code.split(/\r?\n/), token);
if (kernel.disposed || kernel.disposing || token?.isCancellationRequested || !content) {
return [];