Initial support for code consoles

This commit is contained in:
Jeremy Tuloup 2021-08-29 13:48:35 +02:00
parent 9e81700947
commit f2a2a68b09
14 changed files with 243 additions and 15 deletions

View File

@ -84,6 +84,7 @@ async function main() {
let mods = [
// @retrolab plugins
require('@retrolab/application-extension'),
require('@retrolab/console-extension'),
require('@retrolab/docmanager-extension'),
require('@retrolab/help-extension'),
require('@retrolab/notebook-extension'),
@ -116,6 +117,7 @@ async function main() {
require('@jupyterlab/completer-extension').default.filter(({ id }) =>
['@jupyterlab/completer-extension:manager'].includes(id)
),
require('@jupyterlab/console-extension'),
require('@jupyterlab/docmanager-extension').default.filter(({ id }) =>
['@jupyterlab/docmanager-extension:plugin'].includes(id)
),

View File

@ -93,6 +93,7 @@
"@jupyterlab/celltags": "^3.1.8",
"@jupyterlab/codemirror-extension": "^3.1.8",
"@jupyterlab/completer-extension": "^3.1.8",
"@jupyterlab/console-extension": "^3.1.8",
"@jupyterlab/coreutils": "~5.1.8",
"@jupyterlab/docmanager-extension": "^3.1.8",
"@jupyterlab/docprovider-extension": "^3.1.8",
@ -150,6 +151,7 @@
"name": "RetroLab",
"extensions": [
"@retrolab/application-extension",
"@retrolab/console-extension",
"@retrolab/docmanager-extension",
"@retrolab/help-extension",
"@retrolab/notebook-extension",
@ -159,6 +161,7 @@
"@jupyterlab/apputils-extension",
"@jupyterlab/codemirror-extension",
"@jupyterlab/completer-extension",
"@jupyterlab/console-extension",
"@jupyterlab/docmanager-extension",
"@jupyterlab/filebrowser-extension",
"@jupyterlab/fileeditor-extension",

View File

@ -22,6 +22,7 @@
"dependencies": {
"@retrolab/application": "file:../application",
"@retrolab/application-extension": "file:../application-extension",
"@retrolab/console-extension": "file:../console-extension",
"@retrolab/docmanager-extension": "file:../docmanager-extension",
"@retrolab/help-extension": "file:../help-extension",
"@retrolab/lab-extension": "file:../lab-extension",

View File

@ -1,5 +1,6 @@
import '@retrolab/application';
import '@retrolab/application-extension';
import '@retrolab/console-extension';
import '@retrolab/docmanager-extension';
import '@retrolab/help-extension';
import '@retrolab/lab-extension';

View File

@ -8,6 +8,7 @@
"references": [
{ "path": "../application" },
{ "path": "../application-extension" },
{ "path": "../console-extension" },
{ "path": "../docmanager-extension" },
{ "path": "../help-extension" },
{ "path": "../lab-extension" },

View File

@ -0,0 +1,58 @@
{
"name": "@retrolab/console-extension",
"version": "0.3.1",
"description": "RetroLab - Console Extension",
"homepage": "https://github.com/jupyterlab/retrolab",
"bugs": {
"url": "https://github.com/jupyterlab/retrolab/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/jupyterlab/retrolab.git"
},
"license": "BSD-3-Clause",
"author": "Project Jupyter",
"sideEffects": [
"style/**/*.css",
"style/index.js"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"style": "style/index.css",
"directories": {
"lib": "lib/"
},
"files": [
"lib/*.d.ts",
"lib/*.js.map",
"lib/*.js",
"schema/*.json",
"style/**/*.css",
"style/index.js"
],
"scripts": {
"build": "tsc -b",
"build:prod": "tsc -b",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
"docs": "typedoc src",
"prepublishOnly": "npm run build",
"watch": "tsc -b --watch"
},
"dependencies": {
"@jupyterlab/application": "^3.1.8",
"@jupyterlab/console": "^3.1.8",
"@jupyterlab/coreutils": "^5.1.8",
"@lumino/algorithm": "^1.6.0"
},
"devDependencies": {
"rimraf": "~3.0.0",
"typescript": "~4.1.3"
},
"publishConfig": {
"access": "public"
},
"jupyterlab": {
"extension": true
},
"styleModule": "style/index.js"
}

View File

@ -0,0 +1,74 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
IRouter,
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { IConsoleTracker } from '@jupyterlab/console';
import { PageConfig } from '@jupyterlab/coreutils';
import { find } from '@lumino/algorithm';
/**
* A plugin to open consoles in a new tab
*/
const opener: JupyterFrontEndPlugin<void> = {
id: '@retrolab/console-extension:opener',
requires: [IRouter],
autoStart: true,
activate: (app: JupyterFrontEnd, router: IRouter) => {
const { commands } = app;
const consolePattern = new RegExp('/consoles/(.*)');
const command = 'router:console';
commands.addCommand(command, {
execute: (args: any) => {
const parsed = args as IRouter.ILocation;
const matches = parsed.path.match(consolePattern);
if (!matches) {
return;
}
const [, name] = matches;
if (!name) {
return;
}
commands.execute('console:create', { name });
}
});
router.register({ command, pattern: consolePattern });
}
};
/**
* Open consoles in a new tab.
*/
const redirect: JupyterFrontEndPlugin<void> = {
id: '@retrolab/console-extension:redirect',
requires: [IConsoleTracker],
autoStart: true,
activate: (app: JupyterFrontEnd, tracker: IConsoleTracker) => {
const baseUrl = PageConfig.getBaseUrl();
tracker.widgetAdded.connect((send, console) => {
const widget = find(app.shell.widgets('main'), w => w.id === console.id);
if (widget) {
// bail if the console is already added to the main area
return;
}
const name = console.sessionContext.name;
window.open(`${baseUrl}retro/consoles/${name}`, '_blank');
});
}
};
/**
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [opener, redirect];
export default plugins;

View File

@ -0,0 +1 @@
@import url('./base.css');

View File

@ -0,0 +1 @@
import './base.css';

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": ["src/**/*"]
}

View File

@ -130,6 +130,13 @@ class RetroTreeHandler(RetroHandler):
raise web.HTTPError(404)
class RetroConsoleHandler(RetroHandler):
@web.authenticated
def get(self, path=None):
tpl = self.render_template("consoles.html", page_config=self.get_page_config())
return self.write(tpl)
class RetroTerminalHandler(RetroHandler):
@web.authenticated
def get(self, path=None):
@ -203,6 +210,7 @@ class RetroApp(NBClassicConfigShimMixin, LabServerApp):
self.handlers.append(("/retro/tree(.*)", RetroTreeHandler))
self.handlers.append(("/retro/notebooks(.*)", RetroNotebookHandler))
self.handlers.append(("/retro/edit(.*)", RetroFileHandler))
self.handlers.append(("/retro/consoles/(.*)", RetroConsoleHandler))
self.handlers.append(("/retro/terminals/(.*)", RetroTerminalHandler))
super().initialize_handlers()

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{page_config['appName'] | e}} - Console</title>
{% block favicon %}
<link rel="icon" type="image/x-icon" href="{{ base_url | escape }}static/favicons/favicon-terminal.ico" class="favicon">
{% endblock %}
</head>
<body>
{# Copy so we do not modify the page_config with updates. #}
{% set page_config_full = page_config.copy() %}
{# Set a dummy variable - we just want the side effect of the update. #}
{% set _ = page_config_full.update(baseUrl=base_url, wsUrl=ws_url) %}
{# Sentinel value to say that we are on the tree page #}
{% set _ = page_config_full.update(retroPage='consoles') %}
<script id="jupyter-config-data" type="application/json">
{{ page_config_full | tojson }}
</script>
<script src="{{page_config['fullStaticUrl'] | e}}/bundle.js" main="index"></script>
<script type="text/javascript">
/* Remove token from URL. */
(function () {
var parsedUrl = new URL(window.location.href);
if (parsedUrl.searchParams.get('token')) {
parsedUrl.searchParams.delete('token');
window.history.replaceState({ }, '', parsedUrl.href);
}
})();
</script>
</body>
</html>

View File

@ -1824,6 +1824,29 @@
"@lumino/signaling" "^1.4.3"
"@lumino/widgets" "^1.19.0"
"@jupyterlab/console-extension@^3.1.8":
version "3.1.8"
resolved "https://registry.yarnpkg.com/@jupyterlab/console-extension/-/console-extension-3.1.8.tgz#877e14a4e4edeabd3c6ece08219123e5bf81ef98"
integrity sha512-04g8eXzvWCSg8kdu0Dy7z1GEpgEWYv+w7v204u8vTbYiz6nDqR+Mdiox415egCCuObAaMwG6knAq/WsvQai/aQ==
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/apputils" "^3.1.8"
"@jupyterlab/codeeditor" "^3.1.8"
"@jupyterlab/console" "^3.1.8"
"@jupyterlab/coreutils" "^5.1.8"
"@jupyterlab/filebrowser" "^3.1.8"
"@jupyterlab/launcher" "^3.1.8"
"@jupyterlab/mainmenu" "^3.1.8"
"@jupyterlab/rendermime" "^3.1.8"
"@jupyterlab/settingregistry" "^3.1.8"
"@jupyterlab/translation" "^3.1.8"
"@jupyterlab/ui-components" "^3.1.8"
"@lumino/algorithm" "^1.3.3"
"@lumino/coreutils" "^1.5.3"
"@lumino/disposable" "^1.4.3"
"@lumino/properties" "^1.2.3"
"@lumino/widgets" "^1.19.0"
"@jupyterlab/console@^3.1.8":
version "3.1.8"
resolved "https://registry.yarnpkg.com/@jupyterlab/console/-/console-3.1.8.tgz#efa64e994d0128b8a9f8b1234057b9bc2b312046"
@ -3593,7 +3616,7 @@
integrity sha512-6RglhutqrGFMO1MNUXp95RBuYIuc8wTnMAV5MUhLmjTOy78ncwOw7RgeQ/HeymkKXRhZd0s2DNrM1rL7unk3MQ==
"@retrolab/application-extension@file:packages/application-extension":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/apputils" "^3.1.8"
@ -3607,11 +3630,11 @@
"@jupyterlab/settingregistry" "^3.1.8"
"@jupyterlab/translation" "^3.1.8"
"@lumino/widgets" "^1.23.0"
"@retrolab/application" "^0.3.0"
"@retrolab/ui-components" "^0.3.0"
"@retrolab/application" "^0.3.1"
"@retrolab/ui-components" "^0.3.1"
"@retrolab/application@file:packages/application":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/coreutils" "^5.1.8"
@ -3625,8 +3648,16 @@
"@lumino/signaling" "^1.7.0"
"@lumino/widgets" "^1.23.0"
"@retrolab/console-extension@file:packages/console-extension":
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/console" "^3.1.8"
"@jupyterlab/coreutils" "^5.1.8"
"@lumino/algorithm" "^1.6.0"
"@retrolab/docmanager-extension@file:packages/docmanager-extension":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/coreutils" "^5.1.8"
@ -3636,15 +3667,15 @@
"@lumino/algorithm" "^1.6.0"
"@retrolab/help-extension@file:packages/help-extension":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/apputils" "^3.1.8"
"@jupyterlab/mainmenu" "^3.1.8"
"@retrolab/ui-components" "^0.3.0"
"@retrolab/ui-components" "^0.3.1"
"@retrolab/lab-extension@file:packages/lab-extension":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/apputils" "^3.1.8"
@ -3654,10 +3685,10 @@
"@jupyterlab/notebook" "^3.1.8"
"@lumino/commands" "^1.15.0"
"@lumino/disposable" "^1.7.0"
"@retrolab/ui-components" "^0.3.0"
"@retrolab/ui-components" "^0.3.1"
"@retrolab/notebook-extension@file:packages/notebook-extension":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/apputils" "^3.1.8"
@ -3665,10 +3696,10 @@
"@jupyterlab/notebook" "^3.1.8"
"@lumino/polling" "^1.6.0"
"@lumino/widgets" "^1.23.0"
"@retrolab/application" "^0.3.0"
"@retrolab/application" "^0.3.1"
"@retrolab/terminal-extension@file:packages/terminal-extension":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/coreutils" "^5.1.8"
@ -3676,7 +3707,7 @@
"@lumino/algorithm" "^1.6.0"
"@retrolab/tree-extension@file:packages/tree-extension":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/application" "^3.1.8"
"@jupyterlab/apputils" "^3.1.8"
@ -3692,10 +3723,10 @@
"@lumino/algorithm" "^1.6.0"
"@lumino/commands" "^1.15.0"
"@lumino/widgets" "^1.23.0"
"@retrolab/application" "^0.3.0"
"@retrolab/application" "^0.3.1"
"@retrolab/ui-components@file:packages/ui-components":
version "0.3.0"
version "0.3.1"
dependencies:
"@jupyterlab/ui-components" "^3.1.8"
react "^17.0.1"