-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Implement deepnote big number chart support and renderer #41
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
Changes from 51 commits
a422532
3f9c6af
e334698
87f4a09
62297c2
7878345
a12d042
c19acd4
066229a
e36b9c0
558035f
5113db6
1ba9ab4
a51a150
98d7fe6
a476bfd
3a4d579
40ede24
d220422
78d3cb7
4fa78e2
e8ce411
8ae05ab
3597ce3
9fec8d4
0537364
9b9216a
e5a1bba
e7cccb9
895fe09
54ca963
8309267
df330bc
8b88881
8386006
8121bfa
3bdf030
d9afa1a
e2b6c36
722ab50
628ab6e
ed5329d
6649ca8
a3007ac
b25656b
8014bc3
85c8b70
68567e0
067f757
cc3f23c
6ee3612
95fd687
05ab7a0
5f05be1
8d83d0c
60442ec
236cccd
f8dcd85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import { | |
| window, | ||
| extensions | ||
| } from 'vscode'; | ||
| import { coerce, SemVer } from 'semver'; | ||
|
|
||
| import type { Kernel } from '@jupyterlab/services'; | ||
| import { CellExecutionCreator } from './cellExecutionCreator'; | ||
|
|
@@ -45,7 +46,7 @@ import { handleTensorBoardDisplayDataOutput } from './executionHelpers'; | |
| import { Identifiers, RendererExtension, WIDGET_MIMETYPE } from '../../platform/common/constants'; | ||
| import { CellOutputDisplayIdTracker } from './cellDisplayIdTracker'; | ||
| import { createDeferred } from '../../platform/common/utils/async'; | ||
| import { coerce, SemVer } from 'semver'; | ||
| import { CHART_BIG_NUMBER_MIME_TYPE } from '../../platform/deepnote/deepnoteConstants'; | ||
|
|
||
| // Helper interface for the set_next_input execute reply payload | ||
| interface ISetNextInputPayload { | ||
|
|
@@ -1181,6 +1182,13 @@ export class CellExecutionMessageHandler implements IDisposable { | |
| const output = translateCellDisplayOutput( | ||
| new NotebookCellOutput(outputToBeUpdated.outputItems, outputToBeUpdated.outputContainer.metadata) | ||
| ); | ||
|
|
||
| const data = msg.content.data; | ||
| if (outputToBeUpdated.cell.metadata['__deepnotePocket']?.['type'] === 'big-number') { | ||
| data[CHART_BIG_NUMBER_MIME_TYPE] = data['text/plain']; | ||
| delete data['text/plain']; | ||
| } | ||
|
Comment on lines
+1189
to
+1192
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comment why we need this |
||
|
|
||
| const newOutput = cellOutputToVSCCellOutput( | ||
| { | ||
| ...output, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,30 +2,32 @@ | |
| // Licensed under the MIT License. | ||
|
|
||
| import type * as nbformat from '@jupyterlab/nbformat'; | ||
| import { NotebookCellOutput, NotebookCellOutputItem, NotebookCell, Position, Range } from 'vscode'; | ||
| import { NotebookCell, NotebookCellOutput, NotebookCellOutputItem, Position, Range } from 'vscode'; | ||
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| import type { KernelMessage } from '@jupyterlab/services'; | ||
| import fastDeepEqual from 'fast-deep-equal'; | ||
| import * as path from '../../platform/vscode-path/path'; | ||
| import * as uriPath from '../../platform/vscode-path/resources'; | ||
| import { Pocket } from '../../platform/deepnote/pocket'; | ||
| import { PYTHON_LANGUAGE } from '../../platform/common/constants'; | ||
| import { concatMultilineString, splitMultilineString } from '../../platform/common/utils'; | ||
| import { StopWatch } from '../../platform/common/utils/stopWatch'; | ||
| import { base64ToUint8Array, uint8ArrayToBase64 } from '../../platform/common/utils/string'; | ||
| import { CHART_BIG_NUMBER_MIME_TYPE } from '../../platform/deepnote/deepnoteConstants'; | ||
| import { getExtensionSpecificStack } from '../../platform/errors/errors'; | ||
| import { createOutputWithErrorMessageForDisplay } from '../../platform/errors/errorUtils'; | ||
| import { getCachedEnvironment, getVersion } from '../../platform/interpreter/helpers'; | ||
| import { logger } from '../../platform/logging'; | ||
| import type { NotebookCellExecutionState } from '../../platform/notebooks/cellExecutionStateService'; | ||
| import * as path from '../../platform/vscode-path/path'; | ||
| import * as uriPath from '../../platform/vscode-path/resources'; | ||
| import { sendTelemetryEvent, Telemetry } from '../../telemetry'; | ||
| import { createOutputWithErrorMessageForDisplay } from '../../platform/errors/errorUtils'; | ||
| import { CellExecutionCreator } from './cellExecutionCreator'; | ||
| import { IKernelController, KernelConnectionMetadata } from '../types'; | ||
| import { | ||
| isPythonKernelConnection, | ||
| getInterpreterFromKernelConnectionMetadata, | ||
| kernelConnectionMetadataHasKernelModel, | ||
| getKernelRegistrationInfo | ||
| getKernelRegistrationInfo, | ||
| isPythonKernelConnection, | ||
| kernelConnectionMetadataHasKernelModel | ||
| } from '../helpers'; | ||
| import { StopWatch } from '../../platform/common/utils/stopWatch'; | ||
| import { getExtensionSpecificStack } from '../../platform/errors/errors'; | ||
| import { getCachedEnvironment, getVersion } from '../../platform/interpreter/helpers'; | ||
| import { base64ToUint8Array, uint8ArrayToBase64 } from '../../platform/common/utils/string'; | ||
| import type { NotebookCellExecutionState } from '../../platform/notebooks/cellExecutionStateService'; | ||
| import { IKernelController, KernelConnectionMetadata } from '../types'; | ||
| import { CellExecutionCreator } from './cellExecutionCreator'; | ||
|
|
||
| export enum CellOutputMimeTypes { | ||
| error = 'application/vnd.code.notebook.error', | ||
|
|
@@ -260,6 +262,10 @@ function translateDisplayDataOutput( | |
| } | ||
| } | ||
| */ | ||
| // TODO - add DeepnotePocket zod schema validation | ||
|
||
| const deepnotePocket = cellMetadata?.__deepnotePocket as Pocket | undefined; | ||
| const deepnoteBlockType = deepnotePocket?.type; | ||
|
|
||
| const metadata = getOutputMetadata(output, cellIndex, cellId, cellMetadata); | ||
| // If we have SVG or PNG, then add special metadata to indicate whether to display `open plot` | ||
| if ('image/svg+xml' in output.data || 'image/png' in output.data) { | ||
|
|
@@ -269,7 +275,9 @@ function translateDisplayDataOutput( | |
| if (output.data) { | ||
| // eslint-disable-next-line no-restricted-syntax | ||
| for (const key in output.data) { | ||
| items.push(convertJupyterOutputToBuffer(key, output.data[key])); | ||
| // TODO - remove this once this is handled in the deepnote-toolkit | ||
| let effectiveKey = deepnoteBlockType === 'big-number' ? CHART_BIG_NUMBER_MIME_TYPE : key; | ||
| items.push(convertJupyterOutputToBuffer(effectiveKey, output.data[key] ?? output.data[effectiveKey])); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { NotebookCellData, NotebookCellKind } from 'vscode'; | ||
| import { z } from 'zod'; | ||
|
|
||
| import type { BlockConverter } from './blockConverter'; | ||
| import type { DeepnoteBlock } from '../../../platform/deepnote/deepnoteTypes'; | ||
| import { DeepnoteBigNumberMetadataSchema } from '../deepnoteSchemas'; | ||
| import { parseJsonWithFallback } from '../dataConversionUtils'; | ||
| import { DEEPNOTE_VSCODE_RAW_CONTENT_KEY } from './constants'; | ||
|
|
||
| const DEFAULT_BIG_NUMBER_CONFIG = DeepnoteBigNumberMetadataSchema.parse({}); | ||
|
|
||
| export class ChartBigNumberBlockConverter implements BlockConverter { | ||
| applyChangesToBlock(block: DeepnoteBlock, cell: NotebookCellData): void { | ||
| block.content = ''; | ||
|
|
||
| const config = DeepnoteBigNumberMetadataSchema.safeParse(parseJsonWithFallback(cell.value)); | ||
|
|
||
| if (config.success !== true) { | ||
| block.metadata = { | ||
| ...block.metadata, | ||
| [DEEPNOTE_VSCODE_RAW_CONTENT_KEY]: cell.value | ||
| }; | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (block.metadata != null) { | ||
| delete block.metadata[DEEPNOTE_VSCODE_RAW_CONTENT_KEY]; | ||
| } | ||
|
|
||
| block.metadata = { | ||
| ...(block.metadata ?? {}), | ||
| ...config.data | ||
| }; | ||
| } | ||
|
|
||
| canConvert(blockType: string): boolean { | ||
| return blockType.toLowerCase() === 'big-number'; | ||
| } | ||
|
|
||
| convertToCell(block: DeepnoteBlock): NotebookCellData { | ||
| const deepnoteJupyterRawContentResult = z.string().safeParse(block.metadata?.[DEEPNOTE_VSCODE_RAW_CONTENT_KEY]); | ||
| const deepnoteBigNumberMetadataResult = DeepnoteBigNumberMetadataSchema.safeParse(block.metadata); | ||
|
|
||
| if (deepnoteBigNumberMetadataResult.error != null) { | ||
| console.error('Error parsing deepnote big number metadata:', deepnoteBigNumberMetadataResult.error); | ||
| console.debug('Metadata:', JSON.stringify(block.metadata)); | ||
| } | ||
|
|
||
| const configStr = deepnoteJupyterRawContentResult.success | ||
| ? deepnoteJupyterRawContentResult.data | ||
| : deepnoteBigNumberMetadataResult.success | ||
| ? JSON.stringify(deepnoteBigNumberMetadataResult.data, null, 2) | ||
| : JSON.stringify(DEFAULT_BIG_NUMBER_CONFIG, null, 2); | ||
|
|
||
| const cell = new NotebookCellData(NotebookCellKind.Code, configStr, 'json'); | ||
|
|
||
| return cell; | ||
| } | ||
|
|
||
| getSupportedTypes(): string[] { | ||
| return ['big-number']; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.