Skip to content
Merged
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
1 change: 1 addition & 0 deletions news/1 Enhancements/17452.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added non-blocking discovery APIs for Jupyter.
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
resource: Resource,
): Promise<QuickPickType[]> {
const updatedItems = [...items.values()];
const env = event.old ?? event.update;
const env = event.old ?? event.new;
let envIndex = -1;
if (env) {
envIndex = updatedItems.findIndex(
(item) => isInterpreterQuickPickItem(item) && arePathsSame(item.interpreter.path, env.path),
);
}
if (event.update) {
if (event.new) {
const newSuggestion: QuickPickType = this.interpreterSelector.suggestionToQuickPickItem(
event.update,
event.new,
resource,
);
if (envIndex === -1) {
Expand All @@ -228,7 +228,7 @@ export class SetInterpreterCommand extends BaseInterpreterSelectorCommand {
updatedItems[envIndex] = newSuggestion;
}
}
if (envIndex !== -1 && event.update === undefined) {
if (envIndex !== -1 && event.new === undefined) {
updatedItems.splice(envIndex, 1);
}
await this.setRecommendedItem(updatedItems, resource);
Expand Down
3 changes: 2 additions & 1 deletion src/client/interpreter/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type PythonEnvironmentsChangedEvent = {
type?: FileChangeType;
resource?: Uri;
old?: PythonEnvironment;
update?: PythonEnvironment | undefined;
new?: PythonEnvironment | undefined;
};

export const IComponentAdapter = Symbol('IComponentAdapter');
Expand Down Expand Up @@ -110,6 +110,7 @@ export interface ICondaLocatorService {

export const IInterpreterService = Symbol('IInterpreterService');
export interface IInterpreterService {
readonly onRefreshStart: Event<void>;
triggerRefresh(query?: PythonLocatorQuery): Promise<void>;
readonly refreshPromise: Promise<void> | undefined;
readonly onDidChangeInterpreters: Event<PythonEnvironmentsChangedEvent>;
Expand Down
4 changes: 4 additions & 0 deletions src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ export class InterpreterService implements Disposable, IInterpreterService {
});
}

public get onRefreshStart(): Event<void> {
return this.pyenvs.onRefreshStart;
}

public triggerRefresh(query?: PythonLocatorQuery): Promise<void> {
return inDiscoveryExperimentSync(this.experimentService)
? this.pyenvs.triggerRefresh(query)
Expand Down
29 changes: 29 additions & 0 deletions src/client/jupyter/jupyterIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
IInterpreterDisplay,
IInterpreterService,
IInterpreterStatusbarVisibilityFilter,
PythonEnvironmentsChangedEvent,
} from '../interpreter/contracts';
import { PythonEnvironment } from '../pythonEnvironments/info';
import { IDataViewerDataProvider, IJupyterUriProvider } from './types';
Expand Down Expand Up @@ -72,6 +73,19 @@ type PythonApiForJupyterExtension = {
/**
* IInterpreterService
*/
readonly refreshPromise: Promise<void> | undefined;
/**
* IInterpreterService
*/
readonly onDidChangeInterpreters: Event<PythonEnvironmentsChangedEvent>;
/**
* Equivalent to getInterpreters() in IInterpreterService
*/
getKnownInterpreters(resource?: Uri): PythonEnvironment[];
/**
* @deprecated Use `getKnownInterpreters`, `onDidChangeInterpreters`, and `refreshPromise` instead.
* Equivalent to getAllInterpreters() in IInterpreterService
*/
getInterpreters(resource?: Uri): Promise<PythonEnvironment[]>;
/**
* IInterpreterService
Expand All @@ -91,6 +105,11 @@ type PythonApiForJupyterExtension = {
allowExceptions?: boolean,
): Promise<NodeJS.ProcessEnv | undefined>;
isWindowsStoreInterpreter(pythonPath: string): Promise<boolean>;
suggestionToQuickPickItem(suggestion: PythonEnvironment, workspaceUri?: Uri | undefined): IInterpreterQuickPickItem;
getKnownSuggestions(resource: Resource): Promise<IInterpreterQuickPickItem[]>;
/**
* @deprecated Use `getKnownSuggestions` and `suggestionToQuickPickItem` instead.
*/
getSuggestions(resource: Resource): Promise<IInterpreterQuickPickItem[]>;
/**
* IInstaller
Expand Down Expand Up @@ -170,6 +189,9 @@ export class JupyterExtensionIntegration {
getActiveInterpreter: async (resource?: Uri) => this.interpreterService.getActiveInterpreter(resource),
getInterpreterDetails: async (pythonPath: string) =>
this.interpreterService.getInterpreterDetails(pythonPath),
refreshPromise: this.interpreterService.refreshPromise,
onDidChangeInterpreters: this.interpreterService.onDidChangeInterpreters,
getKnownInterpreters: (resource: Uri | undefined) => this.pyenvs.getInterpreters(resource),
getInterpreters: async (resource: Uri | undefined) => this.interpreterService.getAllInterpreters(resource),
getActivatedEnvironmentVariables: async (
resource: Resource,
Expand All @@ -184,6 +206,13 @@ export class JupyterExtensionIntegration {
},
getSuggestions: async (resource: Resource): Promise<IInterpreterQuickPickItem[]> =>
this.interpreterSelector.getAllSuggestions(resource),
getKnownSuggestions: async (resource: Resource): Promise<IInterpreterQuickPickItem[]> =>
this.interpreterSelector.getSuggestions(resource),
suggestionToQuickPickItem: (
suggestion: PythonEnvironment,
workspaceUri?: Uri | undefined,
): IInterpreterQuickPickItem =>
this.interpreterSelector.suggestionToQuickPickItem(suggestion, workspaceUri),
install: async (
product: JupyterProductToInstall,
resource?: InterpreterUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
const invalidIndexes = areEnvsValid.map((isValid, index) => (isValid ? -1 : index)).filter((i) => i !== -1);
invalidIndexes.forEach((index) => {
const env = this.envs.splice(index, 1)[0];
// Ensure we fire events for any envs removed from collection.
this.fire({ old: env, update: undefined });
this.fire({ old: env, new: undefined });
});
}

Expand All @@ -94,7 +93,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
const found = this.envs.find((e) => areSameEnv(e, env));
if (!found) {
this.envs.push(env);
this.fire({ update: env });
this.fire({ new: env });
}
}

Expand All @@ -106,7 +105,7 @@ export class PythonEnvInfoCache extends PythonEnvsWatcher<PythonEnvCollectionCha
} else {
this.envs[index] = newValue;
}
this.fire({ old: oldValue, update: newValue });
this.fire({ old: oldValue, new: newValue });
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/pythonEnvironments/base/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type PythonEnvCollectionChangedEvent = BasicPythonEnvCollectionChangedEve

export type BasicPythonEnvCollectionChangedEvent = {
old?: PythonEnvInfo;
update?: PythonEnvInfo | undefined;
new?: PythonEnvInfo | undefined;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions src/client/pythonEnvironments/legacyIOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ComponentAdapter implements IComponentAdapter {
this.api.onChanged((event) => {
this.changed.fire({
type: event.type,
update: event.update ? convertEnvInfo(event.update) : undefined,
new: event.new ? convertEnvInfo(event.new) : undefined,
old: event.old ? convertEnvInfo(event.old) : undefined,
resource: event.searchLocation,
});
Expand Down Expand Up @@ -276,8 +276,8 @@ class ComponentAdapter implements IComponentAdapter {
const onAddedToCollection = createDeferred();
// Watch for collection changed events.
this.api.onChanged(async (e: PythonEnvCollectionChangedEvent) => {
if (e.update) {
if (await filter(convertEnvInfo(e.update))) {
if (e.new) {
if (await filter(convertEnvInfo(e.new))) {
onAddedToCollection.resolve();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ suite('Set Interpreter Command', () => {

const changeEvent: PythonEnvironmentsChangedEvent = {
old: item.interpreter,
update: refreshedItem.interpreter,
new: refreshedItem.interpreter,
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await onChangedCallback!(changeEvent, quickPick as any); // Invoke callback, meaning that the items are supposed to change.
Expand Down