-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into michal/6437
* origin/master: removing error message from stdout in test + test refactoring (#6480) #6479 add readme to find start of documentation #6479 - fixed doc file names to match camel case (#6488) #6429 Added jupyterlab and jupyterhub. (#6472) Spot/6483 (#6485) #6410 implement %%javascript magic for rendering the `application/javascript` mime (#6482)
- Loading branch information
Showing
37 changed files
with
994 additions
and
435 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { IRenderMime } from '@jupyterlab/rendermime-interfaces'; | ||
import { RenderedJavaScript } from '@jupyterlab/rendermime'; | ||
|
||
export const TEXT_JAVASCRIPT_MIMETYPE = 'text/javascript'; | ||
export const APPLICATION_JAVASCRIPT_MIMETYPE = 'application/javascript'; | ||
|
||
export class BeakerxRenderedJavascript extends RenderedJavaScript { | ||
render(model: IRenderMime.IMimeModel): Promise<void> { | ||
const evalInContext = function (str) { return eval(str); }.bind(this); | ||
|
||
try { | ||
evalInContext(String(model.data[this.mimeType])); | ||
|
||
return Promise.resolve(undefined); | ||
} catch (err) { | ||
console.error(err); | ||
|
||
const pre = document.createElement('pre'); | ||
|
||
pre.classList.add('js-error'); | ||
pre.innerHTML = `${String(err.message)}<br>See your browser Javascript console for more details.`; | ||
this.node.appendChild(pre); | ||
|
||
return Promise.resolve(undefined); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* A mime renderer factory for text/javascript data. | ||
*/ | ||
export | ||
const rendererFactory: IRenderMime.IRendererFactory = { | ||
safe: true, | ||
mimeTypes: [TEXT_JAVASCRIPT_MIMETYPE, APPLICATION_JAVASCRIPT_MIMETYPE], | ||
createRenderer: options => new BeakerxRenderedJavascript(options) | ||
}; | ||
|
||
const extension: IRenderMime.IExtension = { | ||
id: 'beakerx.javascript:factory', | ||
rendererFactory, | ||
rank: 0, | ||
dataType: 'string' | ||
}; | ||
|
||
export default extension; |
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,19 @@ | ||
<!-- | ||
Copyright 2017 TWO SIGMA OPEN SOURCE, LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# Documentation | ||
|
||
[Start Here](../StartHere.ipynb) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/lib | ||
/dist | ||
node_modules/ |
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,56 @@ | ||
/* | ||
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { IRenderMime } from '@jupyterlab/rendermime-interfaces'; | ||
import { RenderedJavaScript } from '@jupyterlab/rendermime' | ||
|
||
export const TEXT_JAVASCRIPT_MIMETYPE = 'text/javascript'; | ||
export const APPLICATION_JAVASCRIPT_MIMETYPE = 'application/javascript'; | ||
|
||
export class BeakerxRenderedJavascript extends RenderedJavaScript { | ||
render(model: IRenderMime.IMimeModel): Promise<void> { | ||
const evalInContext = function(code: string) { | ||
return eval(code); | ||
}.bind(this); | ||
|
||
try { | ||
evalInContext(String(model.data[this.mimeType])); | ||
} catch (e) { | ||
this.node.innerHTML = `<pre>${String(e.message)} - please check console</pre>`; | ||
} | ||
|
||
return Promise.resolve(undefined); | ||
} | ||
} | ||
|
||
/** | ||
* A mime renderer factory for text/javascript data. | ||
*/ | ||
export | ||
const rendererFactory: IRenderMime.IRendererFactory = { | ||
safe: true, | ||
mimeTypes: [TEXT_JAVASCRIPT_MIMETYPE, APPLICATION_JAVASCRIPT_MIMETYPE], | ||
createRenderer: options => new BeakerxRenderedJavascript(options) | ||
}; | ||
|
||
const extension: IRenderMime.IExtension = { | ||
id: 'beakerx.javascript:factory', | ||
rendererFactory, | ||
rank: 0, | ||
dataType: 'string' | ||
}; | ||
|
||
export default extension; |
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,143 @@ | ||
/* | ||
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { JSONArray } from '@phosphor/coreutils'; | ||
import { Widget } from '@phosphor/widgets'; | ||
import { DisposableDelegate } from '@phosphor/disposable'; | ||
import { DocumentRegistry } from '@jupyterlab/docregistry'; | ||
import { INotebookModel, NotebookPanel, Notebook } from '@jupyterlab/notebook'; | ||
import { Cell, CodeCell, CodeCellModel } from '@jupyterlab/cells'; | ||
import { showDialog, Dialog } from '@jupyterlab/apputils'; | ||
import { Kernel } from '@jupyterlab/services'; | ||
|
||
interface msgData { | ||
name?: string, | ||
value?: any | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
beakerx: any, | ||
require: Function | ||
} | ||
} | ||
|
||
function displayHTML(widget: Widget, html: string): void { | ||
if (!widget.node || !html) { | ||
return; | ||
} | ||
|
||
const childElement = document.createElement('pre'); | ||
|
||
childElement.classList.add('jp-RenderedHTML'); | ||
childElement.innerHTML = html; | ||
widget.node.appendChild(childElement); | ||
} | ||
|
||
function registerGlobal(): void { | ||
window.beakerx = window.beakerx || {}; | ||
window.beakerx.displayHTML = displayHTML; | ||
} | ||
|
||
function sendJupyterCodeCells( | ||
kernelInstance: Kernel.IKernelConnection, | ||
notebook: Notebook, | ||
comm: Kernel.IComm, | ||
filter: string | ||
): void { | ||
const codeCells = <JSONArray>getCodeCellsByTag(notebook, filter).map( | ||
(cell: CodeCell): object => cell.model.toJSON() | ||
); | ||
|
||
comm.send({ code_cells: codeCells }); | ||
} | ||
|
||
function getCodeCellsByTag(notebook: Notebook, tag: string): Cell[] { | ||
let cells = notebook.widgets || []; | ||
|
||
return cells.filter(function(cell) { | ||
const tags: any = cell.model.metadata.get('tags'); | ||
|
||
return ( | ||
cell.model instanceof CodeCellModel && | ||
tags && tags.length && tags.includes(tag) | ||
); | ||
}); | ||
} | ||
|
||
function registerCommTargets(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>) { | ||
const session = context.session; | ||
const kernelInstance = session.kernel; | ||
const notebook = panel.notebook; | ||
|
||
kernelInstance.registerCommTarget('beaker.getcodecells', function(comm, msg) { | ||
const data: msgData = <object>msg.content.data; | ||
|
||
comm.onMsg = function(msg) { | ||
if(data.name == "CodeCells") { | ||
sendJupyterCodeCells(kernelInstance, notebook, comm, JSON.parse(data.value)); | ||
} | ||
|
||
window.beakerx[data.name] = JSON.parse(data.value); | ||
}; | ||
}); | ||
|
||
kernelInstance.registerCommTarget('beaker.autotranslation', function(comm, msg) { | ||
comm.onMsg = function(msg) { | ||
const data: msgData = <object>msg.content.data; | ||
|
||
window.beakerx[data.name] = JSON.parse(data.value); | ||
}; | ||
}); | ||
|
||
kernelInstance.registerCommTarget('beaker.tag.run', function(comm, msg) { | ||
comm.onMsg = function(msg) { | ||
const data: { state?: any } = <object>msg.content.data; | ||
|
||
if(!data.state || !data.state.runByTag) { | ||
return; | ||
} | ||
|
||
const matchedCells = getCodeCellsByTag(notebook, data.state.runByTag); | ||
|
||
if (matchedCells.length === 0) { | ||
showDialog({ | ||
title: 'No cell with the tag !', | ||
body: 'Tag: ' + data.state.runByTag, | ||
buttons: [ Dialog.okButton({ label: 'OK' }) ] | ||
}); | ||
} else { | ||
matchedCells.forEach((cell) => { | ||
cell instanceof CodeCell && CodeCell.execute(cell, session); | ||
}); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
class BeakerxExtension implements DocumentRegistry.WidgetExtension { | ||
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>) { | ||
registerGlobal(); | ||
|
||
Promise.all([panel.ready, context.ready]).then(function() { | ||
registerCommTargets(panel, context); | ||
}); | ||
|
||
return new DisposableDelegate(() => { }); | ||
} | ||
} | ||
|
||
export default BeakerxExtension; |
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,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"noImplicitAny": true, | ||
"noEmitOnError": true, | ||
"noUnusedLocals": true, | ||
"lib": ["dom", "es5", "es2015.promise"], | ||
"types": ["node"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "ES5", | ||
"outDir": "../dist" | ||
} | ||
} |
Oops, something went wrong.