Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Sidebar Extension API #6895

Merged
merged 18 commits into from Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/running-extension/package.json
Expand Up @@ -36,7 +36,10 @@
},
"dependencies": {
"@jupyterlab/application": "^1.0.2",
"@jupyterlab/running": "^1.0.2"
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/running": "^1.0.2",
"@jupyterlab/services": "^4.0.2",
"@phosphor/algorithm": "^1.1.3"
},
"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') {
app.commands.execute('console:open', { path });
vidartf marked this conversation as resolved.
Show resolved Hide resolved
} else {
app.commands.execute('docmanager:open', { path });
vidartf marked this conversation as resolved.
Show resolved Hide resolved
}
}
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"
}
]
}
2 changes: 2 additions & 0 deletions packages/running/package.json
Expand Up @@ -39,6 +39,8 @@
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/services": "^4.0.2",
"@phosphor/algorithm": "^1.1.3",
"@phosphor/coreutils": "^1.3.1",
"@phosphor/disposable": "^1.2.0",
"@phosphor/signaling": "^1.2.3",
"react": "~16.8.4"
},
Expand Down