From 57f9e88b56eaaf3c291de0760d5da0586b38a65a Mon Sep 17 00:00:00 2001 From: Andrew Head Date: Mon, 26 Nov 2018 10:55:09 -0800 Subject: [PATCH] Upgrade JupyterLab dependencies to 0.17.2, update build rules and README --- README.md | 11 +++++++++ package.json | 12 +++++----- src/lab/index.ts | 36 +++++++++++++++--------------- src/packages/displaydata/widget.ts | 2 +- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a7002b9..163e529 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,17 @@ But I don't know if either of these *really* fixed the issue. They're worth tryi Then run `jupyter notebook` and the extension will be running. +### `500` message when launching Jupyter notebook + +Install these versions of Jupyter notebook and dependencies +to see something working, before trying out other versions: + +``` +nbconvert==5.3.1 +nbformat==4.4.0 +notebook==5.6.0 +``` + ### Backend (logging) extension (optional) If you want to add logging to the project, look in the `src/nb/python` directory. This Python plugin needs to be installed to receive logging requests and save them to file (`~/.jupyter/events.txt`). To register this Python extension in Jupyter notebook or lab, see this guide: https://jupyter-notebook.readthedocs.io/en/latest/extending/handlers.html. As of the time of this writing, installation involves: diff --git a/package.json b/package.json index a0acade..68da3fc 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "build_nb_extension": "npm run build && npx webpack", "watch_nb_extension": "npx webpack -w", "install_nb_extension": "jupyter nbextension install dist && jupyter nbextension enable dist/gather", - "prepack": "npm run clean && npm run build_parser && npm run build", + "prepack": "npm run clean && npm run build && npm run build_parser ", "clean": "rimraf lib", "watch": "tsc -w", "test": "mocha -r ts-node/register src/test/*.test.ts" @@ -27,12 +27,12 @@ "extension": true }, "dependencies": { - "@jupyterlab/application": "^0.16.3", - "@jupyterlab/apputils": "^0.16.4", + "@jupyterlab/application": "^0.17.2", + "@jupyterlab/apputils": "^0.17.2", "@jupyterlab/coreutils": "^2.0.0-0", - "@jupyterlab/docmanager": "^0.16.3", - "@jupyterlab/fileeditor": "^0.16.3", - "@jupyterlab/notebook": "^0.16.3", + "@jupyterlab/docmanager": "^0.17.2", + "@jupyterlab/fileeditor": "^0.17.2", + "@jupyterlab/notebook": "^0.17.2", "@phosphor/widgets": "^1.6.0", "diff-match-patch": "^1.0.1", "jquery": "^3.3.1" diff --git a/src/lab/index.ts b/src/lab/index.ts index 648c9a7..e2729ec 100644 --- a/src/lab/index.ts +++ b/src/lab/index.ts @@ -7,7 +7,7 @@ import { IClientSession, ICommandPalette } from '@jupyterlab/apputils'; import { Clipboard } from '@jupyterlab/apputils'; import { ICellModel, CodeCell, ICodeCellModel } from '@jupyterlab/cells'; import { IDocumentManager } from '@jupyterlab/docmanager'; -import { DocumentRegistry } from '@jupyterlab/docregistry'; +import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry'; import { FileEditor } from '@jupyterlab/fileeditor'; import { NotebookPanel, INotebookModel, Notebook, INotebookTracker } from '@jupyterlab/notebook'; import { IObservableList } from '@jupyterlab/observables'; @@ -68,9 +68,9 @@ class ExecutionLoggerExtension implements DocumentRegistry.IWidgetExtension): IDisposable { - panel.notebook.model.cells.changed.connect( + panel.content.model.cells.changed.connect( (cells, value) => - this.onCellsChanged(panel.notebook, panel.session, cells, value), + this.onCellsChanged(panel.content, panel.session, cells, value), this); /* @@ -204,13 +204,13 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: // Choose cell from options or the active cell. let chosenCell; if (options.cellId) { - let cells = notebooks.currentWidget.notebook.widgets.filter(cell => cell.model.id == options.cellId); + let cells = notebooks.currentWidget.content.widgets.filter(cell => cell.model.id == options.cellId); if (cells.length > 0) { chosenCell = cells.pop(); } } - if (!chosenCell && panel && panel.notebook && panel.notebook.activeCell && panel.notebook.activeCell.model.type === 'code') { - chosenCell = panel.notebook.activeCell; + if (!chosenCell && panel && panel.content && panel.content.activeCell && panel.content.activeCell.model.type === 'code') { + chosenCell = panel.content.activeCell; } if (!chosenCell || !(chosenCell.model.type == 'code')) return; @@ -252,8 +252,8 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: addCommand('livecells:gatherToNotebook', 'Gather this result into a new notebook', () => { const panel = notebooks.currentWidget; - if (panel && panel.notebook && panel.notebook.activeCell.model.type === 'code') { - const activeCell = panel.notebook.activeCell; + if (panel && panel.content && panel.content.activeCell.model.type === 'code') { + const activeCell = panel.content.activeCell; let slicer = executionLogger.executionSlicer; let cellModel = activeCell.model as ICodeCellModel; let slice = slicer.sliceLatestExecution(new LabCell(cellModel)); @@ -261,7 +261,7 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: docManager.newUntitled({ ext: 'ipynb' }).then(model => { const widget = docManager.open(model.path, undefined, panel.session.kernel.model) as NotebookPanel; - const newModel = widget.notebook.model; + const newModel = widget.content.model; setTimeout(() => { newModel.cells.remove(0); // remove the default blank cell newModel.cells.pushAll(cells.map(c => { @@ -274,8 +274,8 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: addCommand('livecells:gatherToScript', 'Gather this result into a new script', () => { const panel = notebooks.currentWidget; - if (panel && panel.notebook && panel.notebook.activeCell.model.type === 'code') { - const activeCell = panel.notebook.activeCell; + if (panel && panel.content && panel.content.activeCell.model.type === 'code') { + const activeCell = panel.content.activeCell; let slicer = executionLogger.executionSlicer; let cellModel = activeCell.model as ICodeCellModel; let slice = slicer.sliceLatestExecution(new LabCell(cellModel)); @@ -289,9 +289,9 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: console.log(selection); docManager.newUntitled({ ext: 'py' }).then(model => { - const editor = docManager.open(model.path, undefined, panel.session.kernel.model) as FileEditor; + const editor = docManager.open(model.path, undefined, panel.session.kernel.model) as IDocumentWidget; setTimeout(() => { - editor.model.value.text = scriptText; + editor.content.model.value.text = scriptText; }, 100); }); } @@ -300,8 +300,8 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: addCommand('livecells:gatherFromHistory', 'Compare previous versions of this result', () => { const panel = notebooks.currentWidget; - if (panel && panel.notebook && panel.notebook.activeCell.model.type === 'code') { - const activeCell = panel.notebook.activeCell; + if (panel && panel.content && panel.content.activeCell.model.type === 'code') { + const activeCell = panel.content.activeCell; let slicer = executionLogger.executionSlicer; let cellModel = activeCell.model as ICodeCellModel; let slicedExecutions = slicer.sliceAllExecutions(new LabCell(cellModel)); @@ -328,7 +328,7 @@ export class LiveCheckboxExtension implements DocumentRegistry.IWidgetExtension< private liveness: CellLiveness; createNew(panel: NotebookPanel, context: DocumentRegistry.IContext): IDisposable { - const checkbox = new ToolbarCheckbox(panel.notebook); + const checkbox = new ToolbarCheckbox(panel.content); panel.toolbar.insertItem(9, 'liveCode', checkbox); this.liveness = new CellLiveness(checkbox, panel); @@ -350,9 +350,9 @@ class CellLiveness { private checkbox: ToolbarCheckbox, panel: NotebookPanel ) { - panel.notebook.model.cells.changed.connect( + panel.content.model.cells.changed.connect( (cells, value) => - this.onCellsChanged(panel.notebook, panel.session, cells, value), + this.onCellsChanged(panel.content, panel.session, cells, value), this); } diff --git a/src/packages/displaydata/widget.ts b/src/packages/displaydata/widget.ts index ade66ec..7bf587d 100644 --- a/src/packages/displaydata/widget.ts +++ b/src/packages/displaydata/widget.ts @@ -27,7 +27,7 @@ export class DisplayData extends Widget { // TODO(andrewhead): support other types of display data. // TODO(andrewhead): change second argument (preferSafe) based on display data field. if (nbformat.isExecuteResult(model) || nbformat.isDisplayData(model)) { - let mimeType = rendermime.preferredMimeType(model.data, true); + let mimeType = rendermime.preferredMimeType(model.data, "ensure"); let output = rendermime.createRenderer(mimeType); output.renderModel(new OutputModel({ value: model })); layout.addWidget(output);