|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +/* eslint-disable @typescript-eslint/ban-types */ |
| 5 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
| 6 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 7 | +// Licensed under the MIT License. |
| 8 | + |
| 9 | +import { Event, Uri } from 'vscode'; |
| 10 | + |
| 11 | +// https://github.com/microsoft/vscode-python/wiki/Proposed-Environment-APIs |
| 12 | + |
| 13 | +export interface IProposedExtensionAPI { |
| 14 | + environment: { |
| 15 | + /** |
| 16 | + * This event is triggered when the active environment changes. |
| 17 | + */ |
| 18 | + onDidActiveEnvironmentChanged: Event<ActiveEnvironmentChangedParams>; |
| 19 | + /** |
| 20 | + * Returns the path to the python binary selected by the user or as in the settings. |
| 21 | + * This is just the path to the python binary, this does not provide activation or any |
| 22 | + * other activation command. The `resource` if provided will be used to determine the |
| 23 | + * python binary in a multi-root scenario. If resource is `undefined` then the API |
| 24 | + * returns what ever is set for the workspace. |
| 25 | + * @param resource : Uri of a file or workspace |
| 26 | + */ |
| 27 | + getActiveEnvironmentPath(resource?: Resource): Promise<EnvPathType | undefined>; |
| 28 | + /** |
| 29 | + * Returns details for the given interpreter. Details such as absolute interpreter path, |
| 30 | + * version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under |
| 31 | + * metadata field. |
| 32 | + * @param path : Full path to environment folder or interpreter whose details you need. |
| 33 | + * @param options : [optional] |
| 34 | + * * useCache : When true, cache is checked first for any data, returns even if there |
| 35 | + * is partial data. |
| 36 | + */ |
| 37 | + getEnvironmentDetails( |
| 38 | + path: string, |
| 39 | + options?: EnvironmentDetailsOptions, |
| 40 | + ): Promise<EnvironmentDetails | undefined>; |
| 41 | + /** |
| 42 | + * Sets the active environment path for the python extension for the resource. Configuration target |
| 43 | + * will always be the workspace folder. |
| 44 | + * @param path : Full path to environment folder or interpreter to set. |
| 45 | + * @param resource : [optional] Uri of a file ro workspace to scope to a particular workspace |
| 46 | + * folder. |
| 47 | + */ |
| 48 | + setActiveEnvironment(path: string, resource?: Resource): Promise<void>; |
| 49 | + locator: { |
| 50 | + /** |
| 51 | + * Returns paths to environments that uniquely identifies an environment found by the extension |
| 52 | + * at the time of calling. This API will *not* trigger a refresh. If a refresh is going on it |
| 53 | + * will *not* wait for the refresh to finish. This will return what is known so far. To get |
| 54 | + * complete list `await` on promise returned by `getRefreshPromise()`. |
| 55 | + * |
| 56 | + * Environments lacking an interpreter are identified by environment folder paths, |
| 57 | + * whereas other envs can be identified using executable path. |
| 58 | + */ |
| 59 | + getEnvironmentPaths(): Promise<EnvPathType[] | undefined>; |
| 60 | + /** |
| 61 | + * This event is triggered when the known environment list changes, like when a environment |
| 62 | + * is found, existing environment is removed, or some details changed on an environment. |
| 63 | + */ |
| 64 | + onDidEnvironmentsChanged: Event<EnvironmentsChangedParams[]>; |
| 65 | + /** |
| 66 | + * This API will re-trigger environment discovery. Extensions can wait on the returned |
| 67 | + * promise to get the updated environment list. If there is a refresh already going on |
| 68 | + * then it returns the promise for that refresh. |
| 69 | + * @param options : [optional] |
| 70 | + * * clearCache : When true, this will clear the cache before environment refresh |
| 71 | + * is triggered. |
| 72 | + */ |
| 73 | + refreshEnvironments(options?: RefreshEnvironmentsOptions): Promise<EnvPathType[] | undefined>; |
| 74 | + /** |
| 75 | + * Returns a promise for the ongoing refresh. Returns `undefined` if there are no active |
| 76 | + * refreshes going on. |
| 77 | + */ |
| 78 | + getRefreshPromise(options?: GetRefreshEnvironmentsOptions): Promise<void> | undefined; |
| 79 | + /** |
| 80 | + * Tracks discovery progress for current list of known environments, i.e when it starts, finishes or any other relevant |
| 81 | + * stage. Note the progress for a particular query is currently not tracked or reported, this only indicates progress of |
| 82 | + * the entire collection. |
| 83 | + */ |
| 84 | + readonly onRefreshProgress: Event<ProgressNotificationEvent>; |
| 85 | + }; |
| 86 | + }; |
| 87 | +} |
| 88 | + |
| 89 | +export enum Architecture { |
| 90 | + Unknown = 1, |
| 91 | + x86 = 2, |
| 92 | + x64 = 3, |
| 93 | +} |
| 94 | + |
| 95 | +export type EnvSource = KnownEnvSourceTypes | string; |
| 96 | + |
| 97 | +export enum KnownEnvSourceTypes { |
| 98 | + Conda = 'Conda', |
| 99 | + Pipenv = 'PipEnv', |
| 100 | + Poetry = 'Poetry', |
| 101 | + VirtualEnv = 'VirtualEnv', |
| 102 | + Venv = 'Venv', |
| 103 | + VirtualEnvWrapper = 'VirtualEnvWrapper', |
| 104 | + Pyenv = 'Pyenv', |
| 105 | +} |
| 106 | + |
| 107 | +export type EnvType = KnownEnvTypes | string; |
| 108 | + |
| 109 | +export enum KnownEnvTypes { |
| 110 | + VirtualEnv = 'VirtualEnv', |
| 111 | + Conda = 'Conda', |
| 112 | + Unknown = 'Unknown', |
| 113 | + Global = 'Global', |
| 114 | +} |
| 115 | + |
| 116 | +export type BasicVersionInfo = { |
| 117 | + major: number; |
| 118 | + minor: number; |
| 119 | + micro: number; |
| 120 | +}; |
| 121 | + |
| 122 | +/** |
| 123 | + * The possible Python release levels. |
| 124 | + */ |
| 125 | +export enum PythonReleaseLevel { |
| 126 | + Alpha = 'alpha', |
| 127 | + Beta = 'beta', |
| 128 | + Candidate = 'candidate', |
| 129 | + Final = 'final', |
| 130 | +} |
| 131 | + |
| 132 | +/** |
| 133 | + * Release information for a Python version. |
| 134 | + */ |
| 135 | +export type PythonVersionRelease = { |
| 136 | + level: PythonReleaseLevel; |
| 137 | + serial: number; |
| 138 | +}; |
| 139 | + |
| 140 | +export type StandardVersionInfo = BasicVersionInfo & { |
| 141 | + release?: PythonVersionRelease; |
| 142 | +}; |
| 143 | + |
| 144 | +export interface EnvironmentDetails { |
| 145 | + executable: { |
| 146 | + path: string; |
| 147 | + bitness?: Architecture; |
| 148 | + sysPrefix: string; |
| 149 | + // To be added later: |
| 150 | + // run: { |
| 151 | + // exec: Function; |
| 152 | + // shellExec: Function; |
| 153 | + // execObservable: Function; |
| 154 | + // terminalExec: () => void; |
| 155 | + // env?: { [key: string]: string | null | undefined }; |
| 156 | + // }; |
| 157 | + }; |
| 158 | + environment?: { |
| 159 | + type: EnvType; |
| 160 | + name?: string; |
| 161 | + path: string; |
| 162 | + project?: string; // Any specific project environment is created for. |
| 163 | + source: EnvSource[]; |
| 164 | + }; |
| 165 | + version: StandardVersionInfo & { |
| 166 | + sysVersion?: string; |
| 167 | + }; |
| 168 | + implementation?: { |
| 169 | + // `sys.implementation` |
| 170 | + name: string; |
| 171 | + version: StandardVersionInfo; |
| 172 | + }; |
| 173 | +} |
| 174 | + |
| 175 | +export interface EnvironmentDetailsOptions { |
| 176 | + useCache: boolean; |
| 177 | +} |
| 178 | + |
| 179 | +export interface GetRefreshEnvironmentsOptions { |
| 180 | + /** |
| 181 | + * Get refresh promise which resolves once the following stage has been reached for the list of known environments. |
| 182 | + */ |
| 183 | + stage?: ProgressReportStage; |
| 184 | +} |
| 185 | + |
| 186 | +export enum ProgressReportStage { |
| 187 | + discoveryStarted = 'discoveryStarted', |
| 188 | + allPathsDiscovered = 'allPathsDiscovered', |
| 189 | + discoveryFinished = 'discoveryFinished', |
| 190 | +} |
| 191 | + |
| 192 | +export type ProgressNotificationEvent = { |
| 193 | + stage: ProgressReportStage; |
| 194 | +}; |
| 195 | + |
| 196 | +export type Resource = Uri | undefined; |
| 197 | + |
| 198 | +/** |
| 199 | + * Path to environment folder or path to interpreter that uniquely identifies an environment. |
| 200 | + * Environments lacking an interpreter are identified by environment folder paths, |
| 201 | + * whereas other envs can be identified using interpreter path. |
| 202 | + */ |
| 203 | +export type UniquePathType = string; |
| 204 | + |
| 205 | +export interface EnvPathType { |
| 206 | + path: UniquePathType; |
| 207 | + pathType: 'envFolderPath' | 'interpreterPath'; |
| 208 | +} |
| 209 | + |
| 210 | +export interface EnvironmentsChangedParams { |
| 211 | + path?: UniquePathType; |
| 212 | + type: 'add' | 'remove' | 'update' | 'clear-all'; |
| 213 | +} |
| 214 | + |
| 215 | +export interface ActiveEnvironmentChangedParams { |
| 216 | + path: UniquePathType; |
| 217 | + resource?: Uri; |
| 218 | +} |
| 219 | + |
| 220 | +export interface RefreshEnvironmentsOptions { |
| 221 | + clearCache?: boolean; |
| 222 | +} |
0 commit comments