Skip to content

Commit

Permalink
Merge onto latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
Queuecumber committed Jul 25, 2019
2 parents 5a80a37 + 3435924 commit ed8bea1
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 235 deletions.
5 changes: 4 additions & 1 deletion packages/running-extension/package.json
Expand Up @@ -36,7 +36,10 @@
},
"dependencies": {
"@jupyterlab/application": "^1.0.1",
"@jupyterlab/running": "^1.0.1"
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/running": "^1.0.1",
"@jupyterlab/services": "^4.0.1",
"@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 });
} else {
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"
}
]
}
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.1",
"@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

0 comments on commit ed8bea1

Please sign in to comment.