Skip to content

Finalizing design of proposed API for python environments #19524

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
65852fa
Update
Jul 22, 2022
3e509b8
Add API to contribute a new locator
Jul 22, 2022
645873a
Add an API to add a new locator
Aug 9, 2022
19e12ec
Create factory function
Aug 9, 2022
e6fd0e6
Change concept of execution
Aug 9, 2022
8132dca
Temp
Aug 10, 2022
e77e787
Contribute to apis
Aug 10, 2022
0125ac4
es
Aug 10, 2022
3404a15
Rearranging types
Aug 12, 2022
7e6eb78
Handle workspace locator factor
Aug 12, 2022
a9637c2
Attempt to contribute a resolver
Aug 12, 2022
bb92f60
Try to plug in resolver
Aug 12, 2022
78c730b
Add converter for details API
Aug 12, 2022
4ca72e9
Modify types
Aug 12, 2022
cb4cdaf
Add resolver converter
Aug 12, 2022
ec6b6e0
Ensure resolver API isnt passed down to loators
Aug 12, 2022
ef008cd
Add provider converter
Aug 13, 2022
17e50cd
Add metadata converter
Aug 13, 2022
7fdff89
Plug in the resolver api
Aug 13, 2022
c08dff2
Make env types optional
Aug 13, 2022
a6bd637
Move proposed API types to a different file
Aug 16, 2022
df3d795
Change some types
Aug 17, 2022
6fb2a5c
Add support for multiple environment identifiers
Aug 18, 2022
e7a11ba
Add support for multiple resolvers
Aug 19, 2022
452ec5f
Register properly
Aug 19, 2022
727f03b
Also emit extensionId from downstream locators
Aug 19, 2022
78e0936
Add support for multiple kinds
Aug 19, 2022
7d469e3
Allow low level custom locators to contain a single source
Aug 19, 2022
b922c16
Allow low level locators to emit a single kind
Aug 19, 2022
45468f4
Update proposed types
Aug 19, 2022
eddbf5b
Merge branch 'main' of https://github.com/microsoft/vscode-python int…
Sep 2, 2022
6e244f2
Fix errors
Sep 2, 2022
fb65e79
Updates
Sep 3, 2022
062de70
Merge branch 'main' of https://github.com/microsoft/vscode-python int…
Sep 9, 2022
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
138 changes: 2 additions & 136 deletions src/client/apiTypes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-explicit-any */
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { Event, Uri } from 'vscode';
import { Resource } from './common/types';
import { IDataViewerDataProvider, IJupyterUriProvider } from './jupyter/types';
import { EnvPathType, PythonEnvKind } from './pythonEnvironments/base/info';
import { GetRefreshEnvironmentsOptions, ProgressNotificationEvent } from './pythonEnvironments/base/locator';

/*
* Do not introduce any breaking changes to this API.
Expand Down Expand Up @@ -88,137 +88,3 @@ export interface IExtensionApi {
registerRemoteServerProvider(serverProvider: IJupyterUriProvider): void;
};
}

export interface EnvironmentDetailsOptions {
useCache: boolean;
}

export interface EnvironmentDetails {
interpreterPath: string;
envFolderPath?: string;
version: string[];
environmentType: PythonEnvKind[];
metadata: Record<string, unknown>;
}

export interface EnvironmentsChangedParams {
/**
* Path to environment folder or path to interpreter that uniquely identifies an environment.
* Virtual environments lacking an interpreter are identified by environment folder paths,
* whereas other envs can be identified using interpreter path.
*/
path?: string;
type: 'add' | 'remove' | 'update' | 'clear-all';
}

export interface ActiveEnvironmentChangedParams {
/**
* Path to environment folder or path to interpreter that uniquely identifies an environment.
* Virtual environments lacking an interpreter are identified by environment folder paths,
* whereas other envs can be identified using interpreter path.
*/
path: string;
resource?: Uri;
}

export interface IProposedExtensionAPI {
environment: {
/**
* An event that is emitted when execution details (for a resource) change. For instance, when interpreter configuration changes.
*/
readonly onDidChangeExecutionDetails: Event<Uri | undefined>;
/**
* Returns all the details the consumer needs to execute code within the selected environment,
* corresponding to the specified resource taking into account any workspace-specific settings
* for the workspace to which this resource belongs.
* @param {Resource} [resource] A resource for which the setting is asked for.
* * When no resource is provided, the setting scoped to the first workspace folder is returned.
* * If no folder is present, it returns the global setting.
* @returns {({ execCommand: string[] | undefined })}
*/
getExecutionDetails(
resource?: Resource,
): Promise<{
/**
* E.g of execution commands returned could be,
* * `['<path to the interpreter set in settings>']`
* * `['<path to the interpreter selected by the extension when setting is not set>']`
* * `['conda', 'run', 'python']` which is used to run from within Conda environments.
* or something similar for some other Python environments.
*
* @type {(string[] | undefined)} When return value is `undefined`, it means no interpreter is set.
* Otherwise, join the items returned using space to construct the full execution command.
*/
execCommand: string[] | undefined;
}>;
/**
* Returns the path to the python binary selected by the user or as in the settings.
* This is just the path to the python binary, this does not provide activation or any
* other activation command. The `resource` if provided will be used to determine the
* python binary in a multi-root scenario. If resource is `undefined` then the API
* returns what ever is set for the workspace.
* @param resource : Uri of a file or workspace
*/
getActiveEnvironmentPath(resource?: Resource): Promise<EnvPathType | undefined>;
/**
* Returns details for the given interpreter. Details such as absolute interpreter path,
* version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under
* metadata field.
* @param path : Full path to environment folder or interpreter whose details you need.
* @param options : [optional]
* * useCache : When true, cache is checked first for any data, returns even if there
* is partial data.
*/
getEnvironmentDetails(
path: string,
options?: EnvironmentDetailsOptions,
): Promise<EnvironmentDetails | undefined>;
/**
* Returns paths to environments that uniquely identifies an environment found by the extension
* at the time of calling. This API will *not* trigger a refresh. If a refresh is going on it
* will *not* wait for the refresh to finish. This will return what is known so far. To get
* complete list `await` on promise returned by `getRefreshPromise()`.
*
* Virtual environments lacking an interpreter are identified by environment folder paths,
* whereas other envs can be identified using interpreter path.
*/
getEnvironmentPaths(): Promise<EnvPathType[] | undefined>;
/**
* Sets the active environment path for the python extension for the resource. Configuration target
* will always be the workspace folder.
* @param path : Full path to environment folder or interpreter to set.
* @param resource : [optional] Uri of a file ro workspace to scope to a particular workspace
* folder.
*/
setActiveEnvironment(path: string, resource?: Resource): Promise<void>;
/**
* This API will re-trigger environment discovery. Extensions can wait on the returned
* promise to get the updated environment list. If there is a refresh already going on
* then it returns the promise for that refresh.
* @param options : [optional]
* * clearCache : When true, this will clear the cache before environment refresh
* is triggered.
*/
refreshEnvironment(): Promise<EnvPathType[] | undefined>;
/**
* Tracks discovery progress for current list of known environments, i.e when it starts, finishes or any other relevant
* stage. Note the progress for a particular query is currently not tracked or reported, this only indicates progress of
* the entire collection.
*/
readonly onRefreshProgress: Event<ProgressNotificationEvent>;
/**
* Returns a promise for the ongoing refresh. Returns `undefined` if there are no active
* refreshes going on.
*/
getRefreshPromise(options?: GetRefreshEnvironmentsOptions): Promise<void> | undefined;
/**
* This event is triggered when the known environment list changes, like when a environment
* is found, existing environment is removed, or some details changed on an environment.
*/
onDidEnvironmentsChanged: Event<EnvironmentsChangedParams[]>;
/**
* This event is triggered when the active environment changes.
*/
onDidActiveEnvironmentChanged: Event<ActiveEnvironmentChangedParams>;
};
}
3 changes: 2 additions & 1 deletion src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ import { sendErrorTelemetry, sendStartupTelemetry } from './startupTelemetry';
import { IStartupDurations } from './types';
import { runAfterActivation } from './common/utils/runAfterActivation';
import { IInterpreterService } from './interpreter/contracts';
import { IExtensionApi, IProposedExtensionAPI } from './apiTypes';
import { IExtensionApi } from './apiTypes';
import { buildProposedApi } from './proposedApi';
import { WorkspaceService } from './common/application/workspace';
import { disposeAll } from './common/utils/resourceLifecycle';
import { IProposedExtensionAPI } from './proposedApiTypes';

durations.codeLoadingTime = stopWatch.elapsedTime;

Expand Down
6 changes: 3 additions & 3 deletions src/client/interpreter/interpreterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Uri,
} from 'vscode';
import '../common/extensions';
import { IApplicationShell, IDocumentManager } from '../common/application/types';
import { IApplicationShell, IDocumentManager, IWorkspaceService } from '../common/application/types';
import {
IConfigurationService,
IDisposableRegistry,
Expand Down Expand Up @@ -221,8 +221,8 @@ export class InterpreterService implements Disposable, IInterpreterService {
this._pythonPathSetting = pySettings.pythonPath;
this.didChangeInterpreterEmitter.fire();
reportActiveInterpreterChanged({
path: pySettings.pythonPath,
resource,
pathID: pySettings.pythonPath,
resource: this.serviceContainer.get<IWorkspaceService>(IWorkspaceService).getWorkspaceFolder(resource),
});
const interpreterDisplay = this.serviceContainer.get<IInterpreterDisplay>(IInterpreterDisplay);
interpreterDisplay.refresh().catch((ex) => traceError('Python Extension: display.refresh', ex));
Expand Down
16 changes: 8 additions & 8 deletions src/client/proposedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// Licensed under the MIT License.

import { ConfigurationTarget, EventEmitter } from 'vscode';
import {
ActiveEnvironmentChangedParams,
EnvironmentDetails,
EnvironmentDetailsOptions,
EnvironmentsChangedParams,
IProposedExtensionAPI,
} from './apiTypes';
import { arePathsSame } from './common/platform/fs-paths';
import { IInterpreterPathService, Resource } from './common/types';
import { IInterpreterService } from './interpreter/contracts';
import { IServiceContainer } from './ioc/types';
import {
EnvironmentsChangedParams,
ActiveEnvironmentChangedParams,
IProposedExtensionAPI,
EnvironmentDetailsOptions,
EnvironmentDetails,
} from './proposedApiTypes';
import { PythonEnvInfo } from './pythonEnvironments/base/info';
import { getEnvPath } from './pythonEnvironments/base/info/env';
import { GetRefreshEnvironmentsOptions, IDiscoveryAPI } from './pythonEnvironments/base/locator';
Expand All @@ -32,7 +32,7 @@ function getVersionString(env: PythonEnvInfo): string[] {
if (env.version.release) {
ver.push(`${env.version.release}`);
if (env.version.sysVersion) {
ver.push(`${env.version.release}`);
ver.push(`${env.version.sysVersion}`);
}
}
return ver;
Expand Down
Loading