Skip to content

Commit 6218433

Browse files
IanMatthewHuffIan Huff
andauthored
make raw kernel launch respect launching resource environment (#11463)
Co-authored-by: Ian Huff <[email protected]>
1 parent dd0456c commit 6218433

File tree

8 files changed

+28
-15
lines changed

8 files changed

+28
-15
lines changed

news/2 Fixes/11451.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make raw kernel launch respect launched resource environment.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { promisify } from 'util';
88
import * as uuid from 'uuid/v4';
99
import { IFileSystem } from '../../common/platform/types';
1010
import { IProcessServiceFactory, IPythonExecutionFactory } from '../../common/process/types';
11+
import { Resource } from '../../common/types';
1112
import { captureTelemetry } from '../../telemetry';
1213
import { Telemetry } from '../constants';
1314
import { IJupyterKernelSpec } from '../types';
@@ -29,14 +30,15 @@ export class KernelLauncher implements IKernelLauncher {
2930
) {}
3031

3132
@captureTelemetry(Telemetry.KernelLauncherPerf)
32-
public async launch(kernelSpec: IJupyterKernelSpec): Promise<IKernelProcess> {
33+
public async launch(kernelSpec: IJupyterKernelSpec, resource: Resource): Promise<IKernelProcess> {
3334
const connection = await this.getKernelConnection();
3435
const kernelProcess = new KernelProcess(
3536
this.pythonExecutionFactory,
3637
this.processExecutionFactory,
3738
this.file,
3839
connection,
39-
kernelSpec
40+
kernelSpec,
41+
resource
4042
);
4143
await kernelProcess.launch();
4244
return kernelProcess;

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export class KernelProcess implements IKernelProcess {
5353
private readonly processExecutionFactory: IProcessServiceFactory,
5454
private readonly file: IFileSystem,
5555
private readonly _connection: IKernelConnection,
56-
kernelSpec: IJupyterKernelSpec
56+
kernelSpec: IJupyterKernelSpec,
57+
private readonly resource: Resource
5758
) {
5859
this.originalKernelSpec = kernelSpec;
5960
this._kernelSpec = cloneDeep(kernelSpec);
@@ -148,16 +149,18 @@ export class KernelProcess implements IKernelProcess {
148149

149150
private async launchAsObservable() {
150151
let exeObs: ObservableExecutionResult<string>;
151-
const resource: Resource = undefined;
152152
if (this.isPythonKernel) {
153153
this.pythonKernelLauncher = new PythonKernelLauncherDaemon(this.pythonExecutionFactory);
154-
const { observableResult, daemon } = await this.pythonKernelLauncher.launch(resource, this._kernelSpec);
154+
const { observableResult, daemon } = await this.pythonKernelLauncher.launch(
155+
this.resource,
156+
this._kernelSpec
157+
);
155158
this.kernelDaemon = daemon;
156159
exeObs = observableResult;
157160
} else {
158161
// First part of argument is always the executable.
159162
const executable = this._kernelSpec.argv[0];
160-
const executionService = await this.processExecutionFactory.create(resource);
163+
const executionService = await this.processExecutionFactory.create(this.resource);
161164
exeObs = executionService.execObservable(executable, this._kernelSpec.argv.slice(1), {
162165
env: this._kernelSpec.env
163166
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { SpawnOptions } from 'child_process';
66
import { CancellationToken, Event } from 'vscode';
77
import { InterpreterUri } from '../../common/installer/types';
88
import { ObservableExecutionResult } from '../../common/process/types';
9-
import { IAsyncDisposable, IDisposable } from '../../common/types';
9+
import { IAsyncDisposable, IDisposable, Resource } from '../../common/types';
1010
import { IJupyterKernelSpec } from '../types';
1111

1212
export const IKernelLauncher = Symbol('IKernelLauncher');
1313
export interface IKernelLauncher {
14-
launch(kernelSpec: IJupyterKernelSpec): Promise<IKernelProcess>;
14+
launch(kernelSpec: IJupyterKernelSpec, resource: Resource): Promise<IKernelProcess>;
1515
}
1616

1717
export interface IKernelConnection {

src/client/datascience/raw-kernel/liveshare/hostRawNotebookProvider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ export class HostRawNotebookProvider
101101
? this.progressReporter.createProgressIndicator(localize.DataScience.connectingIPyKernel())
102102
: undefined;
103103

104-
const rawSession = new RawJupyterSession(this.kernelLauncher, this.kernelSelector, this.outputChannel);
104+
const rawSession = new RawJupyterSession(
105+
this.kernelLauncher,
106+
this.kernelSelector,
107+
resource,
108+
this.outputChannel
109+
);
105110
try {
106111
const launchTimeout = this.configService.getSettings().datascience.jupyterLaunchTimeout;
107112

src/client/datascience/raw-kernel/rawJupyterSession.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Slot } from '@phosphor/signaling';
66
import { CancellationToken } from 'vscode-jsonrpc';
77
import { CancellationError, createPromiseFromCancellation } from '../../common/cancellation';
88
import { traceError, traceInfo } from '../../common/logger';
9-
import { IDisposable, IOutputChannel } from '../../common/types';
9+
import { IDisposable, IOutputChannel, Resource } from '../../common/types';
1010
import { waitForPromise } from '../../common/utils/async';
1111
import * as localize from '../../common/utils/localize';
1212
import { noop } from '../../common/utils/misc';
@@ -34,6 +34,7 @@ export class RawJupyterSession extends BaseJupyterSession {
3434
constructor(
3535
private readonly kernelLauncher: IKernelLauncher,
3636
kernelSelector: KernelSelector,
37+
private readonly resource: Resource,
3738
private readonly outputChannel: IOutputChannel
3839
) {
3940
super(kernelSelector);
@@ -180,7 +181,7 @@ export class RawJupyterSession extends BaseJupyterSession {
180181
kernelSpec: IJupyterKernelSpec,
181182
_cancelToken?: CancellationToken
182183
): Promise<RawSession> {
183-
const process = await this.kernelLauncher.launch(kernelSpec);
184+
const process = await this.kernelLauncher.launch(kernelSpec, this.resource);
184185

185186
// Wait for the process to actually be ready to connect to
186187
await process.ready;

src/test/datascience/kernelLauncher.functional.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ suite('DataScience - Kernel Launcher', () => {
5151
// tslint:disable-next-line: no-invalid-this
5252
this.skip();
5353
} else {
54-
const kernel = await kernelLauncher.launch(kernelSpec);
54+
const kernel = await kernelLauncher.launch(kernelSpec, undefined);
5555
const exited = new Promise<boolean>((resolve) => kernel.exited(() => resolve(true)));
5656

5757
assert.isOk<IKernelConnection | undefined>(kernel.connection, 'Connection not found');
@@ -159,7 +159,7 @@ suite('DataScience - Kernel Launcher', () => {
159159
};
160160
kernelFinder.addKernelSpec(pythonInterpreter.path, spec);
161161

162-
const kernel = await kernelLauncher.launch(spec);
162+
const kernel = await kernelLauncher.launch(spec, undefined);
163163
const exited = new Promise<boolean>((resolve) => kernel.exited(() => resolve(true)));
164164

165165
// It should not exit.
@@ -203,7 +203,7 @@ suite('DataScience - Kernel Launcher', () => {
203203
// tslint:disable-next-line: no-invalid-this
204204
this.skip();
205205
} else {
206-
const kernel = await kernelLauncher.launch(kernelSpec);
206+
const kernel = await kernelLauncher.launch(kernelSpec, undefined);
207207

208208
try {
209209
const zmq = await import('zeromq');

src/test/datascience/raw-kernel/rawKernel.functional.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ suite('DataScience raw kernel tests', () => {
9090
ioc.get<IProcessServiceFactory>(IProcessServiceFactory),
9191
ioc.get<IFileSystem>(IFileSystem),
9292
connectionInfo as any,
93-
kernelSpec
93+
kernelSpec,
94+
undefined
9495
);
9596
await kernelProcess.launch();
9697

0 commit comments

Comments
 (0)