Skip to content

Commit 47b722a

Browse files
authored
Add ability to pass interpreter into kernel launcher (#11482)
Allow passing interpreter information into kernel launcher, if not passed, then spin up current interpreter as the kernel.
1 parent 223fd77 commit 47b722a

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/client/datascience/kernel-launcher/kernelLauncher.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as uuid from 'uuid/v4';
99
import { IFileSystem } from '../../common/platform/types';
1010
import { IProcessServiceFactory, IPythonExecutionFactory } from '../../common/process/types';
1111
import { Resource } from '../../common/types';
12+
import { PythonInterpreter } from '../../interpreter/contracts';
1213
import { captureTelemetry } from '../../telemetry';
1314
import { Telemetry } from '../constants';
1415
import { IJupyterKernelSpec } from '../types';
@@ -30,15 +31,20 @@ export class KernelLauncher implements IKernelLauncher {
3031
) {}
3132

3233
@captureTelemetry(Telemetry.KernelLauncherPerf)
33-
public async launch(kernelSpec: IJupyterKernelSpec, resource: Resource): Promise<IKernelProcess> {
34+
public async launch(
35+
kernelSpec: IJupyterKernelSpec,
36+
resource: Resource,
37+
interpreter?: PythonInterpreter
38+
): Promise<IKernelProcess> {
3439
const connection = await this.getKernelConnection();
3540
const kernelProcess = new KernelProcess(
3641
this.pythonExecutionFactory,
3742
this.processExecutionFactory,
3843
this.file,
3944
connection,
4045
kernelSpec,
41-
resource
46+
resource,
47+
interpreter
4248
);
4349
await kernelProcess.launch();
4450
return kernelProcess;

src/client/datascience/kernel-launcher/kernelLauncherDaemon.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { IDisposable } from 'monaco-editor';
99
import { IPythonExecutionFactory, ObservableExecutionResult } from '../../common/process/types';
1010
import { Resource } from '../../common/types';
1111
import { noop } from '../../common/utils/misc';
12+
import { PythonInterpreter } from '../../interpreter/contracts';
1213
import { KernelLauncherDaemonModule } from '../constants';
1314
import { IJupyterKernelSpec } from '../types';
1415
import { PythonKernelDaemon } from './kernelDaemon';
@@ -25,12 +26,12 @@ export class PythonKernelLauncherDaemon implements IDisposable {
2526
constructor(@inject(IPythonExecutionFactory) private readonly pythonExecutionFactory: IPythonExecutionFactory) {}
2627
public async launch(
2728
resource: Resource,
28-
kernelSpec: IJupyterKernelSpec
29+
kernelSpec: IJupyterKernelSpec,
30+
interpreter?: PythonInterpreter
2931
): Promise<{ observableResult: ObservableExecutionResult<string>; daemon: IPythonKernelDaemon }> {
30-
const pythonPath = kernelSpec.argv[0];
3132
const daemon = await this.pythonExecutionFactory.createDaemon<IPythonKernelDaemon>({
3233
daemonModule: KernelLauncherDaemonModule,
33-
pythonPath: pythonPath,
34+
pythonPath: interpreter?.path,
3435
daemonClass: PythonKernelDaemon,
3536
dedicated: true,
3637
resource

src/client/datascience/kernel-launcher/kernelProcess.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { IFileSystem, TemporaryFile } from '../../common/platform/types';
1010
import { IProcessServiceFactory, IPythonExecutionFactory, ObservableExecutionResult } from '../../common/process/types';
1111
import { Resource } from '../../common/types';
1212
import { noop, swallowExceptions } from '../../common/utils/misc';
13+
import { PythonInterpreter } from '../../interpreter/contracts';
1314
import { IJupyterKernelSpec } from '../types';
1415
import { findIndexOfConnectionFile } from './kernelFinder';
1516
import { PythonKernelLauncherDaemon } from './kernelLauncherDaemon';
@@ -48,7 +49,8 @@ export class KernelProcess implements IKernelProcess {
4849
private readonly file: IFileSystem,
4950
private readonly _connection: IKernelConnection,
5051
kernelSpec: IJupyterKernelSpec,
51-
private readonly resource: Resource
52+
private readonly resource: Resource,
53+
private readonly interpreter?: PythonInterpreter
5254
) {
5355
this.originalKernelSpec = kernelSpec;
5456
this._kernelSpec = cloneDeep(kernelSpec);
@@ -131,7 +133,8 @@ export class KernelProcess implements IKernelProcess {
131133
this.pythonKernelLauncher = new PythonKernelLauncherDaemon(this.pythonExecutionFactory);
132134
const { observableResult, daemon } = await this.pythonKernelLauncher.launch(
133135
this.resource,
134-
this._kernelSpec
136+
this._kernelSpec,
137+
this.interpreter
135138
);
136139
this.kernelDaemon = daemon;
137140
exeObs = observableResult;

src/client/datascience/kernel-launcher/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import { CancellationToken, Event } from 'vscode';
77
import { InterpreterUri } from '../../common/installer/types';
88
import { ObservableExecutionResult } from '../../common/process/types';
99
import { IAsyncDisposable, IDisposable, Resource } from '../../common/types';
10+
import { PythonInterpreter } from '../../interpreter/contracts';
1011
import { IJupyterKernelSpec } from '../types';
1112

1213
export const IKernelLauncher = Symbol('IKernelLauncher');
1314
export interface IKernelLauncher {
14-
launch(kernelSpec: IJupyterKernelSpec, resource: Resource): Promise<IKernelProcess>;
15+
launch(
16+
kernelSpec: IJupyterKernelSpec,
17+
resource: Resource,
18+
interpreter?: PythonInterpreter
19+
): Promise<IKernelProcess>;
1520
}
1621

1722
export interface IKernelConnection {

0 commit comments

Comments
 (0)