22import * as child_process from 'child_process' ;
33import * as os from 'os' ;
44import * as vscode from 'vscode' ;
5- import { Kernel } from './kernel' ;
6- import { WSKernel } from './ws-kernel' ;
7- import { ZMQKernel } from './zmq-kernel' ;
8- import { launchSpec } from 'spawnteract' ;
9- import { KernelspecMetadata , Kernelspec } from './contracts' ;
10- import { Commands , Documentation } from '../common/constants' ;
11- import { EventEmitter } from 'events' ;
12- import { PythonSettings } from '../common/configSettings' ;
13- import { formatErrorForLogging } from '../common/utils' ;
14- import { JmpModuleLoadError } from '../common/errors' ;
15-
5+ import { Kernel } from './kernel' ;
6+ import { WSKernel } from './ws-kernel' ;
7+ import { ZMQKernel } from './zmq-kernel' ;
8+ import { launchSpec } from 'spawnteract' ;
9+ import { KernelspecMetadata , Kernelspec } from './contracts' ;
10+ import { Commands , Documentation } from '../common/constants' ;
11+ import { EventEmitter } from 'events' ;
12+ import { PythonSettings } from '../common/configSettings' ;
13+ import { formatErrorForLogging } from '../common/utils' ;
14+ import { JmpModuleLoadError } from '../common/errors' ;
15+ import { JupyterClient } from './jupyter_client/jupyterClient' ;
1616// Todo: Refactor the error handling and displaying of messages
1717
1818const pythonSettings = PythonSettings . getInstance ( ) ;
@@ -21,7 +21,7 @@ export class KernelManagerImpl extends EventEmitter {
2121 private _runningKernels : Map < string , Kernel > ;
2222 private _kernelSpecs : { [ key : string ] : Kernelspec } ;
2323 private disposables : vscode . Disposable [ ] ;
24- constructor ( private outputChannel : vscode . OutputChannel ) {
24+ constructor ( private outputChannel : vscode . OutputChannel , private jupyterClient : JupyterClient ) {
2525 super ( ) ;
2626 this . disposables = [ ] ;
2727 this . _runningKernels = new Map < string , Kernel > ( ) ;
@@ -221,29 +221,6 @@ export class KernelManagerImpl extends EventEmitter {
221221 }
222222
223223 public getKernelSpecsFromJupyter ( ) : Promise < any > {
224- const jupyter = 'jupyter kernelspec list --json --log-level=CRITICAL' ;
225- const ipython = 'ipython kernelspec list --json --log-level=CRITICAL' ;
226- return this . getKernelSpecsFrom ( jupyter ) . catch ( jupyterError => {
227- return this . getKernelSpecsFrom ( ipython ) ;
228- } ) ;
229- }
230-
231- public getKernelSpecsFrom ( command : string ) : Promise < any > {
232- const options = {
233- killSignal : 'SIGINT'
234- } ;
235- return new Promise < any > ( ( resolve , reject ) => {
236- return child_process . exec ( command , options , ( err , stdout , stderr ) => {
237- if ( err ) {
238- return reject ( err ) ;
239- }
240- try {
241- const kernelSpecs = JSON . parse ( stdout ) . kernelspecs ;
242- resolve ( kernelSpecs ) ;
243- } catch ( err ) {
244- return reject ( err ) ;
245- }
246- } ) ;
247- } ) ;
224+ return this . jupyterClient . getAllKernelSpecs ( ) ;
248225 }
249226}
0 commit comments