forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockKernelFinder.ts
More file actions
34 lines (28 loc) · 1.29 KB
/
mockKernelFinder.ts
File metadata and controls
34 lines (28 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import type { nbformat } from '@jupyterlab/coreutils';
import { InterpreterUri } from '../../client/common/installer/types';
import { IKernelFinder } from '../../client/datascience/kernel-launcher/types';
import { IJupyterKernelSpec } from '../../client/datascience/types';
export class MockKernelFinder implements IKernelFinder {
private dummySpecs = new Map<string, IJupyterKernelSpec>();
constructor(private readonly realFinder: IKernelFinder) {}
public async findKernelSpec(
interpreterUri: InterpreterUri,
kernelSpecMetadata?: nbformat.IKernelspecMetadata
): Promise<IJupyterKernelSpec | undefined> {
const spec = interpreterUri?.path
? this.dummySpecs.get(interpreterUri.path)
: this.dummySpecs.get((interpreterUri || '').toString());
if (spec) {
return spec;
}
return this.realFinder.findKernelSpec(interpreterUri, kernelSpecMetadata);
}
public async listKernelSpecs(): Promise<IJupyterKernelSpec[]> {
throw new Error('Not yet implemented');
}
public addKernelSpec(pythonPathOrResource: string, spec: IJupyterKernelSpec) {
this.dummySpecs.set(pythonPathOrResource, spec);
}
}