Skip to content

Commit

Permalink
Merge pull request #6895 from Queuecumber/master
Browse files Browse the repository at this point in the history
Running Sidebar Extension API
  • Loading branch information
jasongrout committed Sep 16, 2019
2 parents 15d0c23 + 38efb83 commit 37984a7
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 239 deletions.
17 changes: 17 additions & 0 deletions jupyterlab/staging/yarn.lock
Expand Up @@ -1605,6 +1605,11 @@ ansi-regex@^2.0.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
integrity sha1-w7M6te42DYbg5ijwRorn7yfWVN8=

ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=

ansi-regex@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
Expand Down Expand Up @@ -5273,6 +5278,11 @@ safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, s
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==

safe-buffer@~5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.0.tgz#b74daec49b1148f88c64b68d49b1e815c1f2f519"
integrity sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==

safe-regex@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/safe-regex/-/safe-regex-1.1.0.tgz#40a3669f3b077d1e943d44629e157dd48023bf2e"
Expand Down Expand Up @@ -5652,6 +5662,13 @@ strip-ansi@^3.0.0, strip-ansi@^3.0.1:
dependencies:
ansi-regex "^2.0.0"

strip-ansi@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8=
dependencies:
ansi-regex "^3.0.0"

strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
Expand Down
5 changes: 4 additions & 1 deletion packages/running-extension/package.json
Expand Up @@ -36,7 +36,10 @@
},
"dependencies": {
"@jupyterlab/application": "^1.2.0-alpha.0",
"@jupyterlab/running": "^1.2.0-alpha.0"
"@jupyterlab/coreutils": "^3.2.0-alpha.0",
"@jupyterlab/running": "^1.2.0-alpha.0",
"@jupyterlab/services": "^4.2.0-alpha.0",
"@phosphor/algorithm": "^1.2.0"
},
"devDependencies": {
"rimraf": "~2.6.2",
Expand Down
115 changes: 98 additions & 17 deletions packages/running-extension/src/index.ts
Expand Up @@ -6,15 +6,39 @@ import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import {
IRunningSessions,
IRunningSessionManagers,
RunningSessionManagers,
RunningSessions
} from '@jupyterlab/running';

import { Session } from '@jupyterlab/services';
import { PathExt } from '@jupyterlab/coreutils';
import { toArray } from '@phosphor/algorithm';

/**
* The class name added to a notebook icon.
*/
const NOTEBOOK_ICON_CLASS = 'jp-mod-notebook';

/**
* The class name added to a console icon.
*/
const CONSOLE_ICON_CLASS = 'jp-mod-console';

import { RunningSessions } from '@jupyterlab/running';
/**
* The class name added to a file icon.
*/
const FILE_ICON_CLASS = 'jp-mod-file';

/**
* The default running sessions extension.
*/
const plugin: JupyterFrontEndPlugin<void> = {
const plugin: JupyterFrontEndPlugin<IRunningSessionManagers> = {
activate,
id: '@jupyterlab/running-extension:plugin',
provides: IRunningSessionManagers,
optional: [ILayoutRestorer],
autoStart: true
};
Expand All @@ -30,8 +54,9 @@ export default plugin;
function activate(
app: JupyterFrontEnd,
restorer: ILayoutRestorer | null
): void {
let running = new RunningSessions({ manager: app.serviceManager });
): IRunningSessionManagers {
let runningSessionManagers = new RunningSessionManagers();
let running = new RunningSessions(runningSessionManagers);
running.id = 'jp-running-sessions';
running.title.iconClass = 'jp-RunningIcon jp-SideBar-tabIcon';
running.title.caption = 'Running Terminals and Kernels';
Expand All @@ -42,21 +67,77 @@ function activate(
if (restorer) {
restorer.add(running, 'running-sessions');
}
addKernelRunningSessionManager(runningSessionManagers, app);
// Rank has been chosen somewhat arbitrarily to give priority to the running
// sessions widget in the sidebar.
app.shell.add(running, 'left', { rank: 200 });

running.sessionOpenRequested.connect((sender, model) => {
let path = model.path;
if (model.type.toLowerCase() === 'console') {
void app.commands.execute('console:open', { path });
} else {
void app.commands.execute('docmanager:open', { path });
}
});
return runningSessionManagers;
}

running.terminalOpenRequested.connect((sender, model) => {
void app.commands.execute('terminal:open', { name: model.name });
/**
* Add the running kernel manager (notebooks & consoles) to the running panel.
*/
function addKernelRunningSessionManager(
managers: IRunningSessionManagers,
app: JupyterFrontEnd
) {
let manager = app.serviceManager.sessions;
function filterSessions(m: Session.IModel) {
return !!(
(m.name || PathExt.basename(m.path)).indexOf('.') !== -1 || m.name
);
}

managers.add({
name: 'Kernel',
running: () => {
return toArray(manager.running())
.filter(filterSessions)
.map(model => new RunningKernel(model));
},
shutdownAll: () => manager.shutdownAll(),
refreshRunning: () => manager.refreshRunning(),
runningChanged: manager.runningChanged
});

// Rank has been chosen somewhat arbitrarily to give priority to the running
// sessions widget in the sidebar.
app.shell.add(running, 'left', { rank: 200 });
class RunningKernel implements IRunningSessions.IRunningItem {
constructor(model: Session.IModel) {
this._model = model;
}
open() {
let { path, type } = this._model;
if (type.toLowerCase() === 'console') {
void app.commands.execute('console:open', { path });
} else {
void app.commands.execute('docmanager:open', { path });
}
}
shutdown() {
return manager.shutdown(this._model.id);
}
iconClass() {
let { name, path, type } = this._model;
if ((name || PathExt.basename(path)).indexOf('.ipynb') !== -1) {
return NOTEBOOK_ICON_CLASS;
} else if (type.toLowerCase() === 'console') {
return CONSOLE_ICON_CLASS;
}
return FILE_ICON_CLASS;
}
label() {
return this._model.name || PathExt.basename(this._model.path);
}
labelTitle() {
let { kernel, path } = this._model;
let kernelName = kernel.name;
if (manager.specs) {
const spec = manager.specs.kernelspecs[kernelName];
kernelName = spec ? spec.display_name : 'unknown';
}
return `Path: ${path}\nKernel: ${kernelName}`;
}

private _model: Session.IModel;
}
}
6 changes: 6 additions & 0 deletions packages/running-extension/tsconfig.json
Expand Up @@ -9,8 +9,14 @@
{
"path": "../application"
},
{
"path": "../coreutils"
},
{
"path": "../running"
},
{
"path": "../services"
}
]
}
5 changes: 2 additions & 3 deletions packages/running/package.json
Expand Up @@ -36,9 +36,8 @@
},
"dependencies": {
"@jupyterlab/apputils": "^1.2.0-alpha.0",
"@jupyterlab/coreutils": "^3.2.0-alpha.0",
"@jupyterlab/services": "^4.2.0-alpha.0",
"@phosphor/algorithm": "^1.2.0",
"@phosphor/coreutils": "^1.3.1",
"@phosphor/disposable": "^1.3.0",
"@phosphor/signaling": "^1.3.0",
"react": "~16.8.4"
},
Expand Down

0 comments on commit 37984a7

Please sign in to comment.