@@ -14,6 +14,7 @@ import {
1414} from '../../common/process/types' ;
1515import { IEnvironmentActivationService } from '../../interpreter/activation/types' ;
1616import { IInterpreterService , PythonInterpreter } from '../../interpreter/contracts' ;
17+ import { JupyterCommands } from '../constants' ;
1718import { IJupyterCommand , IJupyterCommandFactory } from '../types' ;
1819
1920// JupyterCommand objects represent some process that can be launched that should be guaranteed to work because it
@@ -64,14 +65,12 @@ class ProcessJupyterCommand implements IJupyterCommand {
6465}
6566
6667class InterpreterJupyterCommand implements IJupyterCommand {
67- private requiredArgs : string [ ] ;
68- private interpreterPromise : Promise < PythonInterpreter | undefined > ;
68+ protected interpreterPromise : Promise < PythonInterpreter | undefined > ;
6969 private pythonLauncher : Promise < IPythonExecutionService > ;
7070
71- constructor ( args : string [ ] , pythonExecutionFactory : IPythonExecutionFactory , interpreter : PythonInterpreter ) {
72- this . requiredArgs = args ;
73- this . interpreterPromise = Promise . resolve ( interpreter ) ;
74- this . pythonLauncher = pythonExecutionFactory . createActivatedEnvironment ( { resource : undefined , interpreter, allowEnvironmentFetchExceptions : true } ) ;
71+ constructor ( protected readonly moduleName : string , protected args : string [ ] , pythonExecutionFactory : IPythonExecutionFactory , private readonly _interpreter : PythonInterpreter ) {
72+ this . interpreterPromise = Promise . resolve ( this . _interpreter ) ;
73+ this . pythonLauncher = pythonExecutionFactory . createActivatedEnvironment ( { resource : undefined , interpreter : _interpreter , allowEnvironmentFetchExceptions : true } ) ;
7574 }
7675 public interpreter ( ) : Promise < PythonInterpreter | undefined > {
7776 return this . interpreterPromise ;
@@ -80,18 +79,32 @@ class InterpreterJupyterCommand implements IJupyterCommand {
8079 public async execObservable ( args : string [ ] , options : SpawnOptions ) : Promise < ObservableExecutionResult < string > > {
8180 const newOptions = { ...options } ;
8281 const launcher = await this . pythonLauncher ;
83- const newArgs = [ ...this . requiredArgs , ...args ] ;
82+ const newArgs = [ ...this . args , ...args ] ;
8483 return launcher . execObservable ( newArgs , newOptions ) ;
8584 }
8685
8786 public async exec ( args : string [ ] , options : SpawnOptions ) : Promise < ExecutionResult < string > > {
8887 const newOptions = { ...options } ;
8988 const launcher = await this . pythonLauncher ;
90- const newArgs = [ ...this . requiredArgs , ...args ] ;
89+ const newArgs = [ ...this . args , ...args ] ;
9190 return launcher . exec ( newArgs , newOptions ) ;
9291 }
9392}
9493
94+ /**
95+ * This class is used to launch the notebook.
96+ * I.e. anything to do with the command `python -m jupyter notebook` or `python -m notebook`.
97+ *
98+ * @class InterpreterJupyterNotebookCommand
99+ * @implements {IJupyterCommand}
100+ */
101+ class InterpreterJupyterNotebookCommand extends InterpreterJupyterCommand {
102+ constructor ( moduleName : string , args : string [ ] , pythonExecutionFactory : IPythonExecutionFactory , interpreter : PythonInterpreter ) {
103+ super ( moduleName , args , pythonExecutionFactory , interpreter ) ;
104+ }
105+ }
106+
107+ // tslint:disable-next-line: max-classes-per-file
95108@injectable ( )
96109export class JupyterCommandFactory implements IJupyterCommandFactory {
97110
@@ -104,8 +117,11 @@ export class JupyterCommandFactory implements IJupyterCommandFactory {
104117
105118 }
106119
107- public createInterpreterCommand ( args : string [ ] , interpreter : PythonInterpreter ) : IJupyterCommand {
108- return new InterpreterJupyterCommand ( args , this . executionFactory , interpreter ) ;
120+ public createInterpreterCommand ( command : JupyterCommands , moduleName : string , args : string [ ] , interpreter : PythonInterpreter ) : IJupyterCommand {
121+ if ( command === JupyterCommands . NotebookCommand ) {
122+ return new InterpreterJupyterNotebookCommand ( moduleName , args , this . executionFactory , interpreter ) ;
123+ }
124+ return new InterpreterJupyterCommand ( moduleName , args , this . executionFactory , interpreter ) ;
109125 }
110126
111127 public createProcessCommand ( exe : string , args : string [ ] ) : IJupyterCommand {
0 commit comments