-
Notifications
You must be signed in to change notification settings - Fork 0
feat: convert Deepnote file to Jupyter on the frontend #4
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 32 commits
b9aa168
2102e32
28cae64
e488759
a155977
50e8536
91bc7e5
7e98a3c
fab6c39
9863cae
aec4f6b
3ed238f
c765dad
5799272
d8c1a9a
a4fa6c7
5120d9e
af2227b
07bb549
cb26de0
017e92f
1d72fb1
08c2d1b
95cebf9
5e6f235
0ae0e56
d7d8256
8426c75
8dbf78a
44818e9
1b3b369
eac52df
765d531
0caae37
9538a18
fe7c9f0
09a1e0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| name: Check Release | ||
| on: | ||
| push: | ||
| branches: ["main"] | ||
| branches: ['main'] | ||
| pull_request: | ||
| branches: ["*"] | ||
| branches: ['*'] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
|
|
@@ -15,13 +15,21 @@ jobs: | |
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Configure npm registry for GitHub Packages | ||
| run: | | ||
| echo "@deepnote:registry=https://npm.pkg.github.com" >> ~/.npmrc | ||
| echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> ~/.npmrc | ||
|
||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Base Setup | ||
| uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 | ||
| - name: Check Release | ||
| uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2 | ||
| with: | ||
|
|
||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Upload Distributions | ||
| uses: actions/upload-artifact@v4 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,6 @@ | ||
| nodeLinker: node-modules | ||
| npmScopes: | ||
| deepnote: | ||
| npmRegistryServer: 'https://npm.pkg.github.com' | ||
| npmAlwaysAuth: true | ||
| npmAuthToken: '${GITHUB_TOKEN}' | ||
andyjakubowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||
| createMarkdown, | ||||||||||||||||||||||||||||||||||||||||||
| createPythonCode, | ||||||||||||||||||||||||||||||||||||||||||
| DeepnoteBlock | ||||||||||||||||||||||||||||||||||||||||||
| } from '@deepnote/blocks'; | ||||||||||||||||||||||||||||||||||||||||||
| import _cloneDeep from 'lodash/cloneDeep'; | ||||||||||||||||||||||||||||||||||||||||||
| import { ICodeCell, IMarkdownCell } from '@jupyterlab/nbformat'; | ||||||||||||||||||||||||||||||||||||||||||
| import { convertDeepnoteBlockTypeToJupyter } from './convert-deepnote-block-type-to-jupyter'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export function convertDeepnoteBlockToJupyterCell(block: DeepnoteBlock) { | ||||||||||||||||||||||||||||||||||||||||||
| const blockCopy = _cloneDeep(block); | ||||||||||||||||||||||||||||||||||||||||||
| const jupyterCellMetadata = { ...blockCopy.metadata, cell_id: blockCopy.id }; | ||||||||||||||||||||||||||||||||||||||||||
| const jupyterCellType = convertDeepnoteBlockTypeToJupyter(blockCopy.type); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
andyjakubowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
| if (jupyterCellType === 'code') { | ||||||||||||||||||||||||||||||||||||||||||
| const blockOutputs = blockCopy.outputs ?? []; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (Array.isArray(blockOutputs)) { | ||||||||||||||||||||||||||||||||||||||||||
| blockOutputs.forEach(output => { | ||||||||||||||||||||||||||||||||||||||||||
| delete output.truncated; | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const source = createPythonCode(blockCopy); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const jupyterCell: ICodeCell = { | ||||||||||||||||||||||||||||||||||||||||||
| cell_type: 'code', | ||||||||||||||||||||||||||||||||||||||||||
| metadata: jupyterCellMetadata, | ||||||||||||||||||||||||||||||||||||||||||
| execution_count: blockCopy.executionCount ?? null, | ||||||||||||||||||||||||||||||||||||||||||
| outputs: blockOutputs, | ||||||||||||||||||||||||||||||||||||||||||
| source | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| return jupyterCell; | ||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||
| // Markdown cell | ||||||||||||||||||||||||||||||||||||||||||
| const source = createMarkdown(blockCopy); | ||||||||||||||||||||||||||||||||||||||||||
| const jupyterCell: IMarkdownCell = { | ||||||||||||||||||||||||||||||||||||||||||
| cell_type: 'markdown', | ||||||||||||||||||||||||||||||||||||||||||
| metadata: {}, | ||||||||||||||||||||||||||||||||||||||||||
| source | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
| return jupyterCell; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+43
Contributor
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. Markdown cells discard block metadata. Unlike code cells (line 28), markdown cells use Apply this diff if block metadata should be preserved: const source = createMarkdown(blockCopy);
const jupyterCell: IMarkdownCell = {
cell_type: 'markdown',
- metadata: {},
+ metadata: jupyterCellMetadata,
source
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| export function convertDeepnoteBlockTypeToJupyter(blockType: string) { | ||
andyjakubowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| switch (blockType) { | ||
| case 'big-number': | ||
| case 'code': | ||
| case 'sql': | ||
| case 'notebook-function': | ||
| case 'input-text': | ||
| case 'input-checkbox': | ||
| case 'input-textarea': | ||
| case 'input-file': | ||
| case 'input-select': | ||
| case 'input-date-range': | ||
| case 'input-date': | ||
| case 'input-slider': | ||
| case 'visualization': | ||
| return 'code'; | ||
|
|
||
| case 'markdown': | ||
| case 'text-cell-h1': | ||
| case 'text-cell-h3': | ||
| case 'text-cell-h2': | ||
| case 'text-cell-p': | ||
| case 'text-cell-bullet': | ||
| case 'text-cell-todo': | ||
| case 'text-cell-callout': | ||
| case 'image': | ||
| case 'button': | ||
| case 'separator': | ||
| default: | ||
| return 'markdown'; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.