@@ -14,6 +14,7 @@ import {
14
14
} from '../../common/process/types' ;
15
15
import { IEnvironmentActivationService } from '../../interpreter/activation/types' ;
16
16
import { IInterpreterService , PythonInterpreter } from '../../interpreter/contracts' ;
17
+ import { JupyterCommands } from '../constants' ;
17
18
import { IJupyterCommand , IJupyterCommandFactory } from '../types' ;
18
19
19
20
// 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 {
64
65
}
65
66
66
67
class InterpreterJupyterCommand implements IJupyterCommand {
67
- private requiredArgs : string [ ] ;
68
- private interpreterPromise : Promise < PythonInterpreter | undefined > ;
68
+ protected interpreterPromise : Promise < PythonInterpreter | undefined > ;
69
69
private pythonLauncher : Promise < IPythonExecutionService > ;
70
70
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 } ) ;
75
74
}
76
75
public interpreter ( ) : Promise < PythonInterpreter | undefined > {
77
76
return this . interpreterPromise ;
@@ -80,18 +79,32 @@ class InterpreterJupyterCommand implements IJupyterCommand {
80
79
public async execObservable ( args : string [ ] , options : SpawnOptions ) : Promise < ObservableExecutionResult < string > > {
81
80
const newOptions = { ...options } ;
82
81
const launcher = await this . pythonLauncher ;
83
- const newArgs = [ ...this . requiredArgs , ...args ] ;
82
+ const newArgs = [ ...this . args , ...args ] ;
84
83
return launcher . execObservable ( newArgs , newOptions ) ;
85
84
}
86
85
87
86
public async exec ( args : string [ ] , options : SpawnOptions ) : Promise < ExecutionResult < string > > {
88
87
const newOptions = { ...options } ;
89
88
const launcher = await this . pythonLauncher ;
90
- const newArgs = [ ...this . requiredArgs , ...args ] ;
89
+ const newArgs = [ ...this . args , ...args ] ;
91
90
return launcher . exec ( newArgs , newOptions ) ;
92
91
}
93
92
}
94
93
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
95
108
@injectable ( )
96
109
export class JupyterCommandFactory implements IJupyterCommandFactory {
97
110
@@ -104,8 +117,11 @@ export class JupyterCommandFactory implements IJupyterCommandFactory {
104
117
105
118
}
106
119
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 ) ;
109
125
}
110
126
111
127
public createProcessCommand ( exe : string , args : string [ ] ) : IJupyterCommand {
0 commit comments