Skip to content

Commit

Permalink
Fix file id not available for jupyter-server
Browse files Browse the repository at this point in the history
Improve notebook cell server-side executor

Fix for testing drive

Allow to request a document from its document_id/room_id

Add documentation

Improve linter ignore

Apply pre-commit

Support long execution and (not working stdin)

Add support for input
  • Loading branch information
fcollonval committed May 15, 2024
1 parent 0cc728a commit 7f5ec20
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 204 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
**/*.d.ts
**/test
**/ui-tests
**/labextension

docs
tests
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
**/tsconfig.test.json
**/*.d.ts
**/test
**/labextension

docs
tests
Expand Down
2 changes: 1 addition & 1 deletion packages/collaboration-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.5",
"@types/react": "~18.0.26",
"@types/react": "~18.3.1",
"npm-run-all": "^4.1.5",
"rimraf": "^4.1.2",
"typescript": "~5.0.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/collaboration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"yjs": "^13.5.40"
},
"devDependencies": {
"@types/react": "^18.0.27",
"@types/react": "~18.3.1",
"rimraf": "^4.1.2",
"typescript": "~5.0.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/docprovider-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"yjs": "^13.5.40"
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.5",
"@types/react": "~18.0.26",
"@jupyterlab/builder": "^4.0.0",
"@types/react": "~18.3.1",
"npm-run-all": "^4.1.5",
"rimraf": "^4.1.2",
"typescript": "~5.0.4"
Expand Down
55 changes: 5 additions & 50 deletions packages/docprovider-extension/src/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
* @module docprovider-extension
*/

import { NotebookCellServerExecutor } from '@jupyter/docprovider';
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
import { ServerConnection } from '@jupyterlab/services';

import { type MarkdownCell } from '@jupyterlab/cells';
import { PageConfig } from '@jupyterlab/coreutils';
import { INotebookCellExecutor, runCell } from '@jupyterlab/notebook';

export const notebookCellExecutor: JupyterFrontEndPlugin<INotebookCellExecutor> =
Expand All @@ -24,53 +22,10 @@ export const notebookCellExecutor: JupyterFrontEndPlugin<INotebookCellExecutor>
provides: INotebookCellExecutor,
activate: (app: JupyterFrontEnd): INotebookCellExecutor => {
if (PageConfig.getOption('serverSideExecution') === 'true') {
return Object.freeze({ runCell: runCellServerSide });
return new NotebookCellServerExecutor({
serverSettings: app.serviceManager.serverSettings
});
}
return Object.freeze({ runCell });
}
};

async function runCellServerSide({
cell,
notebook,
notebookConfig,
onCellExecuted,
onCellExecutionScheduled,
sessionContext,
sessionDialogs,
translator
}: INotebookCellExecutor.IRunCellOptions): Promise<boolean> {
switch (cell.model.type) {
case 'markdown':
(cell as MarkdownCell).rendered = true;
cell.inputHidden = false;
onCellExecuted({ cell, success: true });
break;
case 'code': {
const kernelId = sessionContext?.session?.kernel?.id;
const settings = ServerConnection.makeSettings();
const apiURL = URLExt.join(
settings.baseUrl,
`api/kernels/${kernelId}/execute`
);
const cellId = cell.model.sharedModel.getId();
const documentId = `json:notebook:${notebook.sharedModel.getState(
'file_id'
)}`;
const body = `{"cell_id":"${cellId}","document_id":"${documentId}"}`;
const init = {
method: 'POST',
body
};
try {
await ServerConnection.makeRequest(apiURL, init, settings);
} catch (error: any) {
throw new ServerConnection.NetworkError(error);
}
break;
}
default:
break;
}
return Promise.resolve(true);
}
12 changes: 9 additions & 3 deletions packages/docprovider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,23 @@
},
"dependencies": {
"@jupyter/ydoc": "^2.0.0",
"@jupyterlab/coreutils": "^6.0.5",
"@jupyterlab/services": "^7.0.5",
"@jupyterlab/apputils": "^4.2.0",
"@jupyterlab/cells": "^4.2.0",
"@jupyterlab/coreutils": "^6.2.0",
"@jupyterlab/notebook": "^4.2.0",
"@jupyterlab/outputarea": "^4.2.0",
"@jupyterlab/services": "^7.2.0",
"@jupyterlab/translation": "^4.2.0",
"@lumino/coreutils": "^2.1.0",
"@lumino/disposable": "^2.1.0",
"@lumino/signaling": "^2.1.0",
"@lumino/widgets": "^2.2.0",
"y-protocols": "^1.0.5",
"y-websocket": "^1.3.15",
"yjs": "^13.5.40"
},
"devDependencies": {
"@jupyterlab/testing": "^4.0.5",
"@jupyterlab/testing": "^4.0.0",
"@types/jest": "^29.2.0",
"jest": "^29.5.0",
"rimraf": "^4.1.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/docprovider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/

export * from './awareness';
export * from './notebookCellExecutor';
export * from './requests';
export * from './ydrive';
export * from './yprovider';
export * from './tokens';
Loading

0 comments on commit 7f5ec20

Please sign in to comment.