Skip to content

Commit b8fd21c

Browse files
author
David Kutugata
authored
use only resource on kernel launcher (#11339)
* remove the comment to disable tslint and instead use ignoreErrors * kernel launcher no longer accepts a python interpreter, only a resource uri * fix functional tests
1 parent 02533df commit b8fd21c

File tree

3 files changed

+8
-45
lines changed

3 files changed

+8
-45
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import { Kernel } from '@jupyterlab/services';
66
import { inject, injectable, named } from 'inversify';
77
import * as path from 'path';
8-
import { InterpreterUri } from '../../common/installer/types';
98
import { traceError, traceInfo } from '../../common/logger';
109
import { IFileSystem, IPlatformService } from '../../common/platform/types';
1110
import { IExtensionContext, IPathUtils, Resource } from '../../common/types';
12-
import { isResource } from '../../common/utils/misc';
1311
import {
1412
IInterpreterLocatorService,
1513
IInterpreterService,
@@ -54,11 +52,9 @@ export class KernelFinder implements IKernelFinder {
5452
@inject(IExtensionContext) private readonly context: IExtensionContext
5553
) {}
5654

57-
public async findKernelSpec(interpreterUri: InterpreterUri, kernelName?: string): Promise<IJupyterKernelSpec> {
55+
public async findKernelSpec(resource: Resource, kernelName?: string): Promise<IJupyterKernelSpec> {
5856
this.cache = await this.readCache();
5957
let foundKernel: IJupyterKernelSpec | undefined;
60-
const resource = isResource(interpreterUri) ? interpreterUri : undefined;
61-
const notebookInterpreter = isResource(interpreterUri) ? undefined : interpreterUri;
6258

6359
if (kernelName) {
6460
let kernelSpec = this.cache.find((ks) => ks.name === kernelName);
@@ -67,13 +63,10 @@ export class KernelFinder implements IKernelFinder {
6763
return kernelSpec;
6864
}
6965

70-
if (!notebookInterpreter) {
71-
kernelSpec = await this.getKernelSpecFromActiveInterpreter(resource, kernelName);
72-
}
66+
kernelSpec = await this.getKernelSpecFromActiveInterpreter(resource, kernelName);
7367

7468
if (kernelSpec) {
75-
// tslint:disable-next-line: no-floating-promises
76-
this.writeCache(this.cache);
69+
this.writeCache(this.cache).ignoreErrors();
7770
return kernelSpec;
7871
}
7972

@@ -94,8 +87,7 @@ export class KernelFinder implements IKernelFinder {
9487
foundKernel = await this.getDefaultKernelSpec(resource);
9588
}
9689

97-
// tslint:disable-next-line: no-floating-promises
98-
this.writeCache(this.cache);
90+
this.writeCache(this.cache).ignoreErrors();
9991
return foundKernel;
10092
}
10193

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import * as portfinder from 'portfinder';
88
import { promisify } from 'util';
99
import * as uuid from 'uuid/v4';
1010
import { Event, EventEmitter } from 'vscode';
11-
import { InterpreterUri } from '../../common/installer/types';
1211
import { traceInfo, traceWarning } from '../../common/logger';
1312
import { IFileSystem, TemporaryFile } from '../../common/platform/types';
1413
import { IPythonExecutionFactory } from '../../common/process/types';
14+
import { Resource } from '../../common/types';
1515
import { createDeferred, Deferred } from '../../common/utils/async';
1616
import * as localize from '../../common/utils/localize';
1717
import { noop } from '../../common/utils/misc';
@@ -136,14 +136,11 @@ export class KernelLauncher implements IKernelLauncher {
136136
@inject(IFileSystem) private file: IFileSystem
137137
) {}
138138

139-
public async launch(
140-
interpreterUri: InterpreterUri,
141-
kernelName?: string | IJupyterKernelSpec
142-
): Promise<IKernelProcess> {
139+
public async launch(resource: Resource, kernelName?: string | IJupyterKernelSpec): Promise<IKernelProcess> {
143140
let kernelSpec: IJupyterKernelSpec;
144141
if (!kernelName || typeof kernelName === 'string') {
145142
// string or undefined
146-
kernelSpec = await this.kernelFinder.findKernelSpec(interpreterUri, kernelName);
143+
kernelSpec = await this.kernelFinder.findKernelSpec(resource, kernelName);
147144
} else {
148145
// IJupyterKernelSpec
149146
kernelSpec = kernelName;

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,6 @@ suite('DataScience - Kernel Launcher', () => {
6969
}
7070
}).timeout(10_000);
7171

72-
test('Launch from PythonInterpreter', async function () {
73-
if (!process.env.VSCODE_PYTHON_ROLLING) {
74-
// tslint:disable-next-line: no-invalid-this
75-
this.skip();
76-
} else {
77-
const kernel = await kernelLauncher.launch(pythonInterpreter, kernelName);
78-
const exited = new Promise<boolean>((resolve) => kernel.exited(() => resolve(true)));
79-
80-
// It should not exit.
81-
assert.isRejected(
82-
waitForCondition(() => exited, 5_000, 'Timeout'),
83-
'Timeout'
84-
);
85-
86-
assert.isOk<IKernelConnection | undefined>(kernel.connection, 'Connection not found');
87-
88-
// Upon disposing, we should get an exit event within 100ms or less.
89-
// If this happens, then we know a process existed.
90-
kernel.dispose();
91-
assert.isRejected(
92-
waitForCondition(() => exited, 100, 'Timeout'),
93-
'Timeout'
94-
);
95-
}
96-
});
97-
9872
function createExecutionMessage(code: string, sessionId: string): KernelMessage.IExecuteRequestMsg {
9973
return {
10074
channel: 'shell',
@@ -182,7 +156,7 @@ suite('DataScience - Kernel Launcher', () => {
182156
};
183157
kernelFinder.addKernelSpec(pythonInterpreter.path, spec);
184158

185-
const kernel = await kernelLauncher.launch(pythonInterpreter, kernelName);
159+
const kernel = await kernelLauncher.launch(resource, kernelName);
186160
const exited = new Promise<boolean>((resolve) => kernel.exited(() => resolve(true)));
187161

188162
// It should not exit.

0 commit comments

Comments
 (0)