Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel pickers4 local kernel spec finder #14100

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions src/kernels/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,7 @@ export async function createInterpreterKernelSpec(
interpreter?: PythonEnvironment,
rootKernelFilePath?: Uri
): Promise<IJupyterKernelSpec> {
return createInterpreterKernelSpecWithName(
await getInterpreterKernelSpecName(interpreter),
interpreter,
rootKernelFilePath
);
}

/**
* Create a default kernelspec with the given display name.
*/
export function createInterpreterKernelSpecWithName(
name: string,
interpreter?: PythonEnvironment,
rootKernelFilePath?: Uri
): IJupyterKernelSpec {
const name = await getInterpreterKernelSpecName(interpreter);
const interpreterMetadata = interpreter
? {
path: getFilePath(interpreter.uri)
Expand All @@ -89,10 +75,9 @@ export function createInterpreterKernelSpecWithName(
};

// Generate spec file path if we know where kernel files will go
const specFile =
rootKernelFilePath && defaultSpec.name
? uriPath.joinPath(rootKernelFilePath, defaultSpec.name, 'kernel.json')
: undefined;
const specFile = rootKernelFilePath
? uriPath.joinPath(rootKernelFilePath, name, 'kernel.json')
: undefined;

return new JupyterKernelSpec(
defaultSpec,
Expand Down
2 changes: 1 addition & 1 deletion src/kernels/internalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export enum ContributedKernelFinderKind {
}

export interface IContributedKernelFinder<T extends KernelConnectionMetadata = KernelConnectionMetadata> {
status: 'discovering' | 'idle';
readonly status: 'discovering' | 'idle';
onDidChangeStatus: Event<void>;
/**
* Last error thrown when listing the kernels.
Expand Down
26 changes: 18 additions & 8 deletions src/kernels/jupyter/finder/remoteKernelFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {
removed?: { id: string }[];
}>();
onDidChangeKernels = this._onDidChangeKernels.event;
private readonly _onDidChange = new EventEmitter<void>();
onDidChange = this._onDidChange.event;

private readonly disposables: IDisposable[] = [];

Expand All @@ -87,6 +89,20 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {

private readonly cacheKey: string;
private readonly cacheFile: Uri;

/**
*
* Remote kernel finder is resource agnostic.
*/
public get kernels(): RemoteKernelConnectionMetadata[] {
return this.cache;
}
get items(): RemoteKernelConnectionMetadata[] {
return this.kernels;
}
get title(): string {
return this.displayName;
}
constructor(
readonly id: string,
readonly displayName: string,
Expand All @@ -106,7 +122,9 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {
// Unlike the Local kernel finder universal remote kernel finders will be added on the fly
this.disposables.push(kernelFinder.registerKernelFinder(this));

this._onDidChangeKernels.event(() => this._onDidChange.fire(), this, this.disposables);
this.disposables.push(this._onDidChangeKernels);
this.disposables.push(this._onDidChange);
this.disposables.push(this._onDidChangeStatus);
this.disposables.push(this.promiseMonitor);
}
Expand Down Expand Up @@ -246,14 +264,6 @@ export class RemoteKernelFinder implements IRemoteKernelFinder, IDisposable {
await promise;
}

/**
*
* Remote kernel finder is resource agnostic.
*/
public get kernels(): RemoteKernelConnectionMetadata[] {
return this.cache;
}

private async getRemoteConnectionInfo(displayProgress: boolean = true): Promise<IJupyterConnection | undefined> {
const disposables: IDisposable[] = [];
if (displayProgress) {
Expand Down
17 changes: 15 additions & 2 deletions src/kernels/jupyter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ import {
IKernelSocket,
KernelActionSource,
LiveRemoteKernelConnectionMetadata,
RemoteKernelConnectionMetadata
RemoteKernelConnectionMetadata,
PythonKernelConnectionMetadata,
LocalKernelSpecConnectionMetadata
} from '../types';
import { ClassType } from '../../platform/ioc/types';
import { ContributedKernelFinderKind, IContributedKernelFinder } from '../internalTypes';
import { IJupyterServerUri, IJupyterUriProvider, JupyterServerCollection } from '../../api';
import { Environment } from '../../platform/api/pythonApiTypes';
import { IQuickPickItemProvider } from '../../platform/common/providerBasedQuickPick';

export type JupyterServerInfo = {
base_url: string;
Expand Down Expand Up @@ -290,11 +294,20 @@ export interface IJupyterRemoteCachedKernelValidator {
isValid(kernel: LiveRemoteKernelConnectionMetadata): Promise<boolean>;
}

export interface IRemoteKernelFinder extends IContributedKernelFinder<RemoteKernelConnectionMetadata> {
export interface IRemoteKernelFinder
extends IContributedKernelFinder<RemoteKernelConnectionMetadata>,
IQuickPickItemProvider<RemoteKernelConnectionMetadata> {
kind: ContributedKernelFinderKind.Remote;
serverProviderHandle: JupyterServerProviderHandle;
}

export const IPythonKernelFinder = Symbol('IPythonKernelFinder');
export interface IPythonKernelFinder extends IContributedKernelFinder<PythonKernelConnectionMetadata> {
getOrCreateKernelConnection(env: Environment): Promise<PythonKernelConnectionMetadata>;
}
export const ILocalNonPythonKernelSpecFinder = Symbol('ILocalNonPythonKernelSpecFinder');
export interface ILocalNonPythonKernelSpecFinder extends IContributedKernelFinder<LocalKernelSpecConnectionMetadata> {}

export const IJupyterServerProviderRegistry = Symbol('IJupyterServerProviderRegistry');
export interface IJupyterServerProviderRegistry {
onDidChangeProviders: Event<void>;
Expand Down
Loading