-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Extension api for DataScience #13923
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// tslint:disable-next-line: no-single-line-block-comment | ||
/* eslint-disable comma-dangle */ | ||
// tslint:disable-next-line: no-single-line-block-comment | ||
/* eslint-disable implicit-arrow-linebreak */ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { CancellationToken, Event, Uri } from 'vscode'; | ||
import { InterpreterUri } from '../../common/installer/types'; | ||
import { IExtensions, IInstaller, InstallerResponse, Product, Resource } from '../../common/types'; | ||
import { IEnvironmentActivationService } from '../../interpreter/activation/types'; | ||
import { IInterpreterQuickPickItem, IInterpreterSelector } from '../../interpreter/configuration/types'; | ||
import { IInterpreterService } from '../../interpreter/contracts'; | ||
import { IWindowsStoreInterpreter } from '../../interpreter/locators/types'; | ||
import { WindowsStoreInterpreter } from '../../pythonEnvironments/discovery/locators/services/windowsStoreInterpreter'; | ||
import { PythonEnvironment } from '../../pythonEnvironments/info'; | ||
|
||
type PythonApiForJupyterExtension = { | ||
/** | ||
* IInterpreterService | ||
*/ | ||
onDidChangeInterpreter: Event<void>; | ||
/** | ||
* IInterpreterService | ||
*/ | ||
getInterpreters(resource?: Uri): Promise<PythonEnvironment[]>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We rely on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kinda looks like a rename might be nice here (Interpreter !== Environment) but for now seems better to stay matched up with how the core team has it. |
||
/** | ||
* IInterpreterService | ||
*/ | ||
getActiveInterpreter(resource?: Uri): Promise<PythonEnvironment | undefined>; | ||
/** | ||
* IInterpreterService | ||
*/ | ||
getInterpreterDetails(pythonPath: string, resource?: Uri): Promise<undefined | PythonEnvironment>; | ||
|
||
/** | ||
* IEnvironmentActivationService | ||
*/ | ||
getActivatedEnvironmentVariables( | ||
resource: Resource, | ||
interpreter?: PythonEnvironment, | ||
allowExceptions?: boolean | ||
): Promise<NodeJS.ProcessEnv | undefined>; | ||
isWindowsStoreInterpreter(pythonPath: string): Promise<boolean>; | ||
/** | ||
* IWindowsStoreInterpreter | ||
*/ | ||
getSuggestions(resource: Resource): Promise<IInterpreterQuickPickItem[]>; | ||
/** | ||
* IInstaller | ||
*/ | ||
install(product: Product, resource?: InterpreterUri, cancel?: CancellationToken): Promise<InstallerResponse>; | ||
}; | ||
|
||
type JupyterExtensionApi = { | ||
registerPythonApi(interpreterService: PythonApiForJupyterExtension): void; | ||
}; | ||
|
||
@injectable() | ||
export class JupyterExtensionIntegration { | ||
constructor( | ||
@inject(IExtensions) private readonly extensions: IExtensions, | ||
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService, | ||
@inject(IInterpreterSelector) private readonly interpreterSelector: IInterpreterSelector, | ||
@inject(WindowsStoreInterpreter) private readonly windowsStoreInterpreter: IWindowsStoreInterpreter, | ||
@inject(IInstaller) private readonly installer: IInstaller, | ||
@inject(IEnvironmentActivationService) private readonly envActivation: IEnvironmentActivationService | ||
) {} | ||
|
||
public async integrateWithJupyterExtension(): Promise<void> { | ||
const jupyterExtension = this.extensions.getExtension<JupyterExtensionApi>('ms-ai-tools.jupyter'); | ||
if (!jupyterExtension) { | ||
return; | ||
} | ||
await jupyterExtension.activate(); | ||
if (!jupyterExtension.isActive) { | ||
return; | ||
} | ||
const jupyterExtensionApi = jupyterExtension.exports; | ||
jupyterExtensionApi.registerPythonApi({ | ||
onDidChangeInterpreter: this.interpreterService.onDidChangeInterpreter, | ||
getActiveInterpreter: async (resource?: Uri) => this.interpreterService.getActiveInterpreter(resource), | ||
getInterpreterDetails: async (pythonPath: string) => | ||
this.interpreterService.getInterpreterDetails(pythonPath), | ||
getInterpreters: async (resource: Uri | undefined) => this.interpreterService.getInterpreters(resource), | ||
getActivatedEnvironmentVariables: async ( | ||
resource: Resource, | ||
interpreter?: PythonEnvironment, | ||
allowExceptions?: boolean | ||
) => this.envActivation.getActivatedEnvironmentVariables(resource, interpreter, allowExceptions), | ||
isWindowsStoreInterpreter: async (pythonPath: string): Promise<boolean> => | ||
karrtikr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath), | ||
getSuggestions: async (resource: Resource): Promise<IInterpreterQuickPickItem[]> => | ||
this.interpreterSelector.getSuggestions(resource), | ||
install: async ( | ||
product: Product, | ||
resource?: InterpreterUri, | ||
cancel?: CancellationToken | ||
): Promise<InstallerResponse> => this.installer.install(product, resource, cancel) | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment indicates where we (DS) pulled these methods from.
Gives you an indication of our depdencies.