-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix file id not available for jupyter-server
Improve notebook cell server-side executor Fix for testing drive Allow to request a document from its document_id/room_id Add documentation Rename state room_id to document_id Don't include custom logic for jupyter_server_nbmodel
- Loading branch information
1 parent
0cc728a
commit a207d33
Showing
13 changed files
with
225 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
**/*.d.ts | ||
**/test | ||
**/ui-tests | ||
**/labextension | ||
|
||
docs | ||
tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
**/tsconfig.test.json | ||
**/*.d.ts | ||
**/test | ||
**/labextension | ||
|
||
docs | ||
tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* ----------------------------------------------------------------------------- | ||
| Copyright (c) Jupyter Development Team. | ||
| Distributed under the terms of the Modified BSD License. | ||
|----------------------------------------------------------------------------*/ | ||
|
||
import { Dialog, showDialog } from '@jupyterlab/apputils'; | ||
import { type ICodeCellModel, type MarkdownCell } from '@jupyterlab/cells'; | ||
import { URLExt } from '@jupyterlab/coreutils'; | ||
import { INotebookCellExecutor } from '@jupyterlab/notebook'; | ||
import { ServerConnection } from '@jupyterlab/services'; | ||
import { nullTranslator } from '@jupyterlab/translation'; | ||
|
||
/** | ||
* Notebook cell executor posting a request to the server for execution. | ||
*/ | ||
export class NotebookCellServerExecutor implements INotebookCellExecutor { | ||
private _serverSettings: ServerConnection.ISettings; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param options Constructor options; the contents manager, the collaborative drive and optionally the server settings. | ||
*/ | ||
constructor(options: { serverSettings?: ServerConnection.ISettings }) { | ||
this._serverSettings = | ||
options.serverSettings ?? ServerConnection.makeSettings(); | ||
} | ||
|
||
/** | ||
* Execute a given cell of the notebook. | ||
* | ||
* @param options Execution options | ||
* @returns Execution success status | ||
*/ | ||
async runCell({ | ||
cell, | ||
notebook, | ||
notebookConfig, | ||
onCellExecuted, | ||
onCellExecutionScheduled, | ||
sessionContext, | ||
sessionDialogs, | ||
translator | ||
}: INotebookCellExecutor.IRunCellOptions): Promise<boolean> { | ||
translator = translator ?? nullTranslator; | ||
const trans = translator.load('jupyterlab'); | ||
|
||
switch (cell.model.type) { | ||
case 'markdown': | ||
(cell as MarkdownCell).rendered = true; | ||
cell.inputHidden = false; | ||
onCellExecuted({ cell, success: true }); | ||
break; | ||
case 'code': | ||
if (sessionContext) { | ||
if (sessionContext.isTerminating) { | ||
await showDialog({ | ||
title: trans.__('Kernel Terminating'), | ||
body: trans.__( | ||
'The kernel for %1 appears to be terminating. You can not run any cell for now.', | ||
sessionContext.session?.path | ||
), | ||
buttons: [Dialog.okButton()] | ||
}); | ||
break; | ||
} | ||
if (sessionContext.pendingInput) { | ||
await showDialog({ | ||
title: trans.__('Cell not executed due to pending input'), | ||
body: trans.__( | ||
'The cell has not been executed to avoid kernel deadlock as there is another pending input! Submit your pending input and try again.' | ||
), | ||
buttons: [Dialog.okButton()] | ||
}); | ||
return false; | ||
} | ||
if (sessionContext.hasNoKernel) { | ||
const shouldSelect = await sessionContext.startKernel(); | ||
if (shouldSelect && sessionDialogs) { | ||
await sessionDialogs.selectKernel(sessionContext); | ||
} | ||
} | ||
|
||
if (sessionContext.hasNoKernel) { | ||
cell.model.sharedModel.transact(() => { | ||
(cell.model as ICodeCellModel).clearExecution(); | ||
}); | ||
return true; | ||
} | ||
|
||
const kernelId = sessionContext?.session?.kernel?.id; | ||
const apiURL = URLExt.join( | ||
this._serverSettings.baseUrl, | ||
`api/kernels/${kernelId}/execute` | ||
); | ||
const cellId = cell.model.sharedModel.getId(); | ||
const documentId = notebook.sharedModel.getState('document_id'); | ||
|
||
const init = { | ||
method: 'POST', | ||
body: JSON.stringify({ cell_id: cellId, document_id: documentId }) | ||
}; | ||
onCellExecutionScheduled({ cell }); | ||
let success = false; | ||
try { | ||
// FIXME quid of deletedCells and timing record | ||
const response = await ServerConnection.makeRequest( | ||
apiURL, | ||
init, | ||
this._serverSettings | ||
); | ||
success = response.ok; | ||
} catch (error: unknown) { | ||
onCellExecuted({ | ||
cell, | ||
success: false | ||
}); | ||
if (cell.isDisposed) { | ||
return false; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
|
||
onCellExecuted({ cell, success }); | ||
|
||
return true; | ||
} | ||
cell.model.sharedModel.transact(() => { | ||
(cell.model as ICodeCellModel).clearExecution(); | ||
}, false); | ||
break; | ||
default: | ||
break; | ||
} | ||
return Promise.resolve(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.