Skip to content

Commit c3c4777

Browse files
IanMatthewHuffIan Huff
andauthored
port the fix and fix up unit tests (microsoft#11330)
Co-authored-by: Ian Huff <ianhuff@Ians-MacBook-Pro.local>
1 parent 48ea303 commit c3c4777

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33
'use strict';
44

5+
import { Kernel } from '@jupyterlab/services';
56
import { inject, injectable, named } from 'inversify';
67
import * as path from 'path';
78
import { InterpreterUri } from '../../common/installer/types';
@@ -15,6 +16,7 @@ import {
1516
KNOWN_PATH_SERVICE,
1617
PythonInterpreter
1718
} from '../../interpreter/contracts';
19+
import { JupyterKernelSpec } from '../jupyter/kernels/jupyterKernelSpec';
1820
import { IJupyterKernelSpec } from '../types';
1921
import { IKernelFinder } from './types';
2022

@@ -173,10 +175,9 @@ export class KernelFinder implements IKernelFinder {
173175
for (let i = 0; i < searchResults.length; i += 1) {
174176
if (searchResults[i].length > 0) {
175177
try {
176-
const kernelSpec: IJupyterKernelSpec = JSON.parse(
177-
await this.file.readFile(path.join(paths[i], searchResults[i][0], 'kernel.json'))
178-
);
179-
kernelSpec.name = searchResults[i][0];
178+
const kernelJsonFile = path.join(paths[i], searchResults[i][0], 'kernel.json');
179+
const kernelJson = JSON.parse(await this.file.readFile(kernelJsonFile));
180+
const kernelSpec: IJupyterKernelSpec = new JupyterKernelSpec(kernelJson, kernelJsonFile);
180181
this.cache.push(kernelSpec);
181182
return kernelSpec;
182183
} catch (e) {
@@ -193,10 +194,10 @@ export class KernelFinder implements IKernelFinder {
193194
this.activeInterpreter = await this.interpreterService.getActiveInterpreter(resource);
194195
}
195196

196-
const defaultSpec = {
197+
const defaultSpec: Kernel.ISpecModel = {
197198
name: `python_defaultSpec_${Date.now()}`,
198199
language: 'python',
199-
path: this.activeInterpreter?.path!,
200+
path: '<path to kernel spec.json>',
200201
display_name: this.activeInterpreter?.displayName ? this.activeInterpreter.displayName : 'Python 3',
201202
metadata: {},
202203
argv: [
@@ -205,11 +206,12 @@ export class KernelFinder implements IKernelFinder {
205206
'ipykernel_launcher',
206207
'-f',
207208
connectionFilePlaceholder
208-
]
209+
],
210+
resources: {}
209211
};
210-
211-
this.cache.push(defaultSpec);
212-
return defaultSpec;
212+
const kernelSpec = new JupyterKernelSpec(defaultSpec);
213+
this.cache.push(kernelSpec);
214+
return kernelSpec;
213215
}
214216

215217
private async readCache(): Promise<IJupyterKernelSpec[]> {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ class KernelProcess implements IKernelProcess {
6767
throw new Error(`Connection file not found in kernelspec json args, ${args.join(' ')}`);
6868
}
6969
args[indexOfConnectionFile] = this.connectionFile.filePath;
70-
args.splice(0, 1);
70+
// First part of argument is always the executable.
71+
const pythonPath = this._kernelSpec.metadata?.interpreter?.path || args[0];
72+
args.shift();
7173

7274
const executionService = await this.executionFactory.create({
7375
resource: undefined,
74-
pythonPath: this._kernelSpec.path
76+
pythonPath
7577
});
7678
const exeObs = executionService.execObservable(args, {});
7779

src/test/datascience/kernelFinder.unit.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict';
44

55
import * as assert from 'assert';
6+
import { expect } from 'chai';
67
import * as typemoq from 'typemoq';
78

89
import { Uri } from 'vscode';
@@ -34,9 +35,8 @@ suite('Kernel Finder', () => {
3435
const kernel: IJupyterKernelSpec = {
3536
name: 'testKernel',
3637
language: 'python',
37-
path: '',
38+
path: '<python path>',
3839
display_name: 'Python 3',
39-
metadata: {},
4040
argv: ['<python path>', '-m', 'ipykernel_launcher', '-f', '<connection_file>']
4141
};
4242

@@ -124,7 +124,7 @@ suite('Kernel Finder', () => {
124124
return Promise.resolve(JSON.stringify(kernel));
125125
});
126126
const spec = await kernelFinder.findKernelSpec(resource, kernelName);
127-
assert.deepEqual(spec, kernel);
127+
expect(spec).to.deep.include(kernel);
128128
fileSystem.reset();
129129
});
130130

@@ -142,7 +142,7 @@ suite('Kernel Finder', () => {
142142
return Promise.resolve(JSON.stringify(kernel));
143143
});
144144
const spec = await kernelFinder.findKernelSpec(activeInterpreter, kernelName);
145-
assert.deepEqual(spec, kernel);
145+
expect(spec).to.deep.include(kernel);
146146
fileSystem.reset();
147147
});
148148

@@ -160,7 +160,7 @@ suite('Kernel Finder', () => {
160160
return Promise.resolve(JSON.stringify(kernel));
161161
});
162162
const spec = await kernelFinder.findKernelSpec(activeInterpreter, kernelName);
163-
assert.deepEqual(spec, kernel);
163+
expect(spec).to.deep.include(kernel);
164164
fileSystem.reset();
165165
});
166166

@@ -209,7 +209,7 @@ suite('Kernel Finder', () => {
209209

210210
// get the same kernel, but from cache
211211
const spec2 = await kernelFinder.findKernelSpec(resource, spec.name);
212-
assert.deepEqual(spec, spec2);
212+
expect(spec).to.deep.include(spec2);
213213

214214
fileSystem.verifyAll();
215215
fileSystem.reset();

0 commit comments

Comments
 (0)