Skip to content

Commit 7bcf6bf

Browse files
authored
feat: Track the environment information when executing blocks (#254)
1 parent 71abe5f commit 7bcf6bf

40 files changed

Lines changed: 1596 additions & 60 deletions

build/esbuild/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ const commonExternals = [
5959
'@opentelemetry/instrumentation',
6060
'@azure/functions-core',
6161
// Node.js builtins (with node: prefix)
62+
'node:child_process',
6263
'node:crypto',
6364
'node:fs/promises',
6465
'node:os',
6566
'node:path',
67+
'node:util',
6668
'ansi-regex' // Used by regexp utils
6769
];
6870
// Create separate copies to avoid shared-state mutations

cspell.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@
2323
"words": [
2424
"alloydb",
2525
"altdb",
26+
"altgraph",
2627
"altuser",
28+
"anyio",
29+
"artmann",
2730
"blockgroup",
31+
"boto",
2832
"channeldef",
33+
"cpython",
2934
"clickhouse",
3035
"dataframe",
3136
"datascience",
37+
"dateutil",
3238
"dbname",
3339
"deepnote",
3440
"deepnoteserver",
@@ -53,6 +59,8 @@
5359
"matplotlib",
5460
"millis",
5561
"mindsdb",
62+
"msgspec",
63+
"mypackage",
5664
"mydb",
5765
"nbformat",
5866
"nbinsx",
@@ -61,12 +69,16 @@
6169
"pids",
6270
"Pids",
6371
"plotly",
72+
"pyenv",
6473
"pylsp",
6574
"PYTHONHOME",
75+
"pyyaml",
6676
"Reselecting",
6777
"rootpass",
78+
"scikit",
6879
"scipy",
6980
"sklearn",
81+
"sqlalchemy",
7082
"taskkill",
7183
"testdb",
7284
"toolsai",

package-lock.json

Lines changed: 47 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@
25002500
},
25012501
"dependencies": {
25022502
"@c4312/evt": "^0.1.1",
2503-
"@deepnote/blocks": "^1.3.5",
2503+
"@deepnote/blocks": "^1.4.0",
25042504
"@deepnote/convert": "^1.3.0",
25052505
"@deepnote/database-integrations": "^1.3.0",
25062506
"@deepnote/sql-language-server": "^3.0.0",

src/kernels/execution/cellExecutionQueue.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import { CancellationToken, Disposable, EventEmitter, NotebookCell } from 'vscode';
4+
import { CancellationToken, Disposable, EventEmitter, NotebookCell, NotebookDocument } from 'vscode';
5+
56
import { logger } from '../../platform/logging';
67
import { noop } from '../../platform/common/utils/misc';
78
import { traceCellMessage } from './helpers';
@@ -13,6 +14,7 @@ import { CodeExecution } from './codeExecution';
1314
import { once } from '../../platform/common/utils/events';
1415
import { getCellMetadata } from '../../platform/common/utils';
1516
import { NotebookCellExecutionState, notebookCellExecutions } from '../../platform/notebooks/cellExecutionStateService';
17+
import { ISnapshotMetadataService } from '../../platform/notebooks/deepnote/types';
1618

1719
/**
1820
* A queue responsible for execution of cells.
@@ -48,7 +50,9 @@ export class CellExecutionQueue implements Disposable {
4850
private readonly session: Promise<IKernelSession>,
4951
private readonly executionFactory: CellExecutionFactory,
5052
readonly metadata: Readonly<KernelConnectionMetadata>,
51-
readonly resourceUri: Resource
53+
readonly resourceUri: Resource,
54+
private readonly notebook?: NotebookDocument,
55+
private readonly snapshotService?: ISnapshotMetadataService
5256
) {}
5357

5458
public dispose() {
@@ -189,6 +193,18 @@ export class CellExecutionQueue implements Disposable {
189193
private async executeQueuedCells() {
190194
let notebookClosed: boolean | undefined;
191195
const kernelConnection = await this.session;
196+
197+
// Capture environment before executing any cells
198+
if (this.snapshotService && this.notebook) {
199+
const notebookUri = this.notebook.uri.toString();
200+
201+
try {
202+
await this.snapshotService.captureEnvironmentBeforeExecution(notebookUri);
203+
} catch (error) {
204+
logger.warn('[CellExecutionQueue] Failed to capture environment before execution', error);
205+
}
206+
}
207+
192208
this.queueOfItemsToExecute.forEach(
193209
(exec) => exec.type === 'cell' && traceCellMessage(exec.cell, 'Ready to execute')
194210
);

src/kernels/kernelExecution.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
import { CodeExecution } from './execution/codeExecution';
4646
import type { ICodeExecution } from './execution/types';
4747
import { NotebookCellExecutionState, notebookCellExecutions } from '../platform/notebooks/cellExecutionStateService';
48+
import { ISnapshotMetadataService } from '../platform/notebooks/deepnote/types';
4849

4950
/**
5051
* Everything in this classes gets disposed via the `onWillCancel` hook.
@@ -65,7 +66,8 @@ export class NotebookKernelExecution implements INotebookKernelExecution {
6566
private readonly kernel: IKernel,
6667
context: IExtensionContext,
6768
formatters: ITracebackFormatter[],
68-
private readonly notebook: NotebookDocument
69+
private readonly notebook: NotebookDocument,
70+
private readonly snapshotService?: ISnapshotMetadataService
6971
) {
7072
const requestListener = new CellExecutionMessageHandlerService(
7173
kernel.controller,
@@ -361,7 +363,9 @@ export class NotebookKernelExecution implements INotebookKernelExecution {
361363
sessionPromise,
362364
this.executionFactory,
363365
this.kernel.kernelConnectionMetadata,
364-
this.kernel.resourceUri
366+
this.kernel.resourceUri,
367+
document,
368+
this.snapshotService
365369
);
366370
this.disposables.push(newCellExecutionQueue);
367371

src/kernels/kernelProvider.node.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
import { inject, injectable, multiInject, named } from 'inversify';
4+
import { inject, injectable, multiInject, named, optional } from 'inversify';
55
import { Memento, NotebookDocument, Uri } from 'vscode';
6+
67
import {
78
IAsyncDisposableRegistry,
89
IConfigurationService,
@@ -31,6 +32,7 @@ import { IReplNotebookTrackerService } from '../platform/notebooks/replNotebookT
3132
import { logger } from '../platform/logging';
3233
import { getDisplayPath } from '../platform/common/platform/fs-paths.node';
3334
import { IRawNotebookSupportedService } from './raw/types';
35+
import { ISnapshotMetadataService } from '../platform/notebooks/deepnote/types';
3436

3537
/**
3638
* Node version of a kernel provider. Needed in order to create the node version of a kernel.
@@ -50,7 +52,8 @@ export class KernelProvider extends BaseCoreKernelProvider {
5052
@inject(IMemento) @named(WORKSPACE_MEMENTO) private readonly workspaceStorage: Memento,
5153
@inject(IReplNotebookTrackerService) private readonly replTracker: IReplNotebookTrackerService,
5254
@inject(IKernelWorkingDirectory) private readonly kernelWorkingDirectory: IKernelWorkingDirectory,
53-
@inject(IRawNotebookSupportedService) private readonly rawKernelSupported: IRawNotebookSupportedService
55+
@inject(IRawNotebookSupportedService) private readonly rawKernelSupported: IRawNotebookSupportedService,
56+
@inject(ISnapshotMetadataService) @optional() private readonly snapshotService?: ISnapshotMetadataService
5457
) {
5558
super(asyncDisposables, disposables);
5659
disposables.push(jupyterServerUriStorage.onDidRemove(this.handleServerRemoval.bind(this)));
@@ -109,7 +112,10 @@ export class KernelProvider extends BaseCoreKernelProvider {
109112
this.disposables
110113
);
111114

112-
this.executions.set(kernel, new NotebookKernelExecution(kernel, this.context, this.formatters, notebook));
115+
this.executions.set(
116+
kernel,
117+
new NotebookKernelExecution(kernel, this.context, this.formatters, notebook, this.snapshotService)
118+
);
113119
this.asyncDisposables.push(kernel);
114120
this.storeKernel(notebook, options, kernel);
115121
this.deleteMappingIfKernelIsDisposed(kernel);

src/notebooks/deepnote/converters/blockConverter.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import type { DeepnoteBlock } from '@deepnote/blocks';
12
import type { NotebookCellData } from 'vscode';
23

3-
import type { DeepnoteBlock } from '../../../platform/deepnote/deepnoteTypes';
4-
54
export interface BlockConverter {
65
applyChangesToBlock(block: DeepnoteBlock, cell: NotebookCellData): void;
76
canConvert(blockType: string): boolean;

src/notebooks/deepnote/converters/chartBigNumberBlockConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import type { DeepnoteBlock } from '@deepnote/blocks';
12
import { NotebookCellData, NotebookCellKind } from 'vscode';
23

34
import type { BlockConverter } from './blockConverter';
4-
import type { DeepnoteBlock } from '../../../platform/deepnote/deepnoteTypes';
55
import { DeepnoteBigNumberMetadataSchema } from '../deepnoteSchemas';
66
import { DEEPNOTE_VSCODE_RAW_CONTENT_KEY } from './constants';
77

src/notebooks/deepnote/converters/chartBigNumberBlockConverter.unit.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import type { DeepnoteBlock } from '@deepnote/blocks';
12
import { assert } from 'chai';
23
import { NotebookCellData, NotebookCellKind } from 'vscode';
3-
4-
import type { DeepnoteBlock } from '../../../platform/deepnote/deepnoteTypes';
54
import { ChartBigNumberBlockConverter } from './chartBigNumberBlockConverter';
65
import { DEEPNOTE_VSCODE_RAW_CONTENT_KEY } from './constants';
76

0 commit comments

Comments
 (0)