Skip to content

Commit

Permalink
WIP support custom jupyter notebook command
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstphrchvz committed Jul 18, 2018
1 parent be71800 commit d0d3702
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@
"default": "${workspaceRoot}",
"title": "Startup directory for Jupyter Notebook"
},
"jupyter.notebook.startupJupyterCommand": {
"type": "string",
"default": "jupyter",
"title": "Startup command for Jupyter Notebook"
},
"jupyter.notebook.startupSubcommand": {
"type": "string",
"default": "notebook",
"title": "Startup subcommand for Jupyter Notebook"
},
"jupyter.notebook.startupArgs": {
"type": "array",
"description": "'jupyter notebook' command line arguments. Each argument is a separate item in the array. For a full list type 'jupyter notebook --help' in a terminal window.",
Expand Down
10 changes: 6 additions & 4 deletions src/jupyterServices/notebook/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export class NotebookFactory extends EventEmitter {
this.notebookOutputChannel.clear();
this.emit('onShutdown');
}
private startJupyterNotebookInTerminal(startupFolder: string, args: string[]) {
private startJupyterNotebookInTerminal(jupyterCommand: string, subcommand: string, startupFolder: string, args: string[]) {
this.notebookOutputChannel.appendLine('Starting Jupyter Notebook');
this.notebookOutputChannel.appendLine('jupyter ' + ['notebook'].concat(args).join(' '));
this.notebookOutputChannel.appendLine(jupyterCommand + [subcommand].concat(args).join(' '));

return spanwPythonFile('jupyter', ['notebook'].concat(args), startupFolder)
return spanwPythonFile(jupyterCommand, [subcommand].concat(args), startupFolder)
.then(proc => {
this.proc = proc;
this.proc.stderr.on('data', data => {
Expand All @@ -76,6 +76,8 @@ export class NotebookFactory extends EventEmitter {
let jupyterSettings = workspace.getConfiguration('jupyter');
let startupFolder = sysVars.resolve(jupyterSettings.get('notebook.startupFolder', workspace.rootPath || __dirname));

let jupyterCommand = jupyterSettings.get('notebook.startupJupyterCommand', 'jupyter');
let subcommand = jupyterSettings.get('notebook.startupSubcommand', 'notebook');
let args = jupyterSettings.get('notebook.startupArgs', [] as string[]);
args = args.map(arg => sysVars.resolve(arg));
if (this.proc) {
Expand All @@ -100,7 +102,7 @@ export class NotebookFactory extends EventEmitter {

getAvailablePort(protocol, ip, port)
.catch(() => Promise.resolve(port))
.then(nextAvailablePort => this.startJupyterNotebookInTerminal(startupFolder, args).then(() => nextAvailablePort))
.then(nextAvailablePort => this.startJupyterNotebookInTerminal(jupyterCommand, subcommand, startupFolder, args).then(() => nextAvailablePort))
.then(nextAvailablePort => {
url = `${protocol}://${ip}:${nextAvailablePort}`;
return tcpPortUsed.waitUntilUsed(nextAvailablePort, retryIntervalMs, timeoutMs);
Expand Down

0 comments on commit d0d3702

Please sign in to comment.