Skip to content

Commit af28a9a

Browse files
author
Kartik Raj
committed
Update
1 parent 512e471 commit af28a9a

File tree

4 files changed

+285
-84
lines changed

4 files changed

+285
-84
lines changed

src/client/apiTypes.ts

Lines changed: 150 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
// Copyright (c) Microsoft Corporation. All rights reserved.
23
// Licensed under the MIT License.
34

45
import { Event, Uri } from 'vscode';
56
import { Resource } from './common/types';
7+
import { Architecture } from './common/utils/platform';
68
import { IDataViewerDataProvider, IJupyterUriProvider } from './jupyter/types';
7-
import { EnvPathType, PythonEnvKind } from './pythonEnvironments/base/info';
8-
import { GetRefreshEnvironmentsOptions, ProgressNotificationEvent } from './pythonEnvironments/base/locator';
9+
import { EnvPathType } from './pythonEnvironments/base/info';
10+
import {
11+
GetRefreshEnvironmentsOptions,
12+
IPythonEnvsIterator,
13+
ProgressNotificationEvent,
14+
} from './pythonEnvironments/base/locator';
915

1016
/*
1117
* Do not introduce any breaking changes to this API.
@@ -91,21 +97,55 @@ export interface IExtensionApi {
9197

9298
export interface EnvironmentDetailsOptions {
9399
useCache: boolean;
100+
// noShell?: boolean; // For execution without shell
94101
}
95102

96103
export interface EnvironmentDetails {
97-
interpreterPath: string;
98-
envFolderPath?: string;
99-
version: string[];
100-
environmentType: PythonEnvKind[];
101-
metadata: Record<string, unknown>;
104+
executable: {
105+
path: string;
106+
run: string[];
107+
env?: any;
108+
shell?: boolean;
109+
shellCommand?: Record<'cmd' | 'fish' | 'bash' | 'string', { run: string[] }>;
110+
bitness?: Architecture;
111+
cwd?: string;
112+
sysPrefix: string;
113+
};
114+
environment?: {
115+
type: EnvType;
116+
name?: string;
117+
path: string;
118+
project?: string; // Any specific project environment is created for.
119+
};
120+
version: {
121+
major: number;
122+
minor: number;
123+
micro: number;
124+
releaselevel: 'alpha' | 'beta' | 'candidate' | 'final';
125+
serial: number;
126+
sysVersion?: string;
127+
};
128+
implementation?: {
129+
// `sys.implementation`
130+
name: string;
131+
version: {
132+
major: number;
133+
minor: number;
134+
micro: number;
135+
releaselevel: 'alpha' | 'beta' | 'candidate' | 'final';
136+
serial: number;
137+
};
138+
};
139+
environmentSource: EnvSource[];
140+
// Are the results specific to the environment (variables, working directory, etc.)?
141+
contextSensitive: boolean;
102142
}
103143

104144
export interface EnvironmentsChangedParams {
105145
/**
106146
* Path to environment folder or path to interpreter that uniquely identifies an environment.
107-
* Virtual environments lacking an interpreter are identified by environment folder paths,
108-
* whereas other envs can be identified using interpreter path.
147+
* Environments lacking an interpreter are identified by environment folder paths,
148+
* whereas other envs can be identified using executable path.
109149
*/
110150
path?: string;
111151
type: 'add' | 'remove' | 'update' | 'clear-all';
@@ -114,8 +154,8 @@ export interface EnvironmentsChangedParams {
114154
export interface ActiveEnvironmentChangedParams {
115155
/**
116156
* Path to environment folder or path to interpreter that uniquely identifies an environment.
117-
* Virtual environments lacking an interpreter are identified by environment folder paths,
118-
* whereas other envs can be identified using interpreter path.
157+
* Environments lacking an interpreter are identified by environment folder paths,
158+
* whereas other envs can be identified using executable path.
119159
*/
120160
path: string;
121161
resource?: Uri;
@@ -128,33 +168,13 @@ export interface RefreshEnvironmentsOptions {
128168
export interface IProposedExtensionAPI {
129169
environment: {
130170
/**
131-
* An event that is emitted when execution details (for a resource) change. For instance, when interpreter configuration changes.
171+
* This event is triggered when the active environment changes.
132172
*/
133-
readonly onDidChangeExecutionDetails: Event<Uri | undefined>;
173+
onDidActiveEnvironmentChanged: Event<ActiveEnvironmentChangedParams>;
134174
/**
135-
* Returns all the details the consumer needs to execute code within the selected environment,
136-
* corresponding to the specified resource taking into account any workspace-specific settings
137-
* for the workspace to which this resource belongs.
138-
* @param {Resource} [resource] A resource for which the setting is asked for.
139-
* * When no resource is provided, the setting scoped to the first workspace folder is returned.
140-
* * If no folder is present, it returns the global setting.
141-
* @returns {({ execCommand: string[] | undefined })}
175+
* An event that is emitted when execution details (for a resource) change. For instance, when interpreter configuration changes.
142176
*/
143-
getExecutionDetails(
144-
resource?: Resource,
145-
): Promise<{
146-
/**
147-
* E.g of execution commands returned could be,
148-
* * `['<path to the interpreter set in settings>']`
149-
* * `['<path to the interpreter selected by the extension when setting is not set>']`
150-
* * `['conda', 'run', 'python']` which is used to run from within Conda environments.
151-
* or something similar for some other Python environments.
152-
*
153-
* @type {(string[] | undefined)} When return value is `undefined`, it means no interpreter is set.
154-
* Otherwise, join the items returned using space to construct the full execution command.
155-
*/
156-
execCommand: string[] | undefined;
157-
}>;
177+
readonly onDidChangeExecutionDetails: Event<Uri | undefined>;
158178
/**
159179
* Returns the path to the python binary selected by the user or as in the settings.
160180
* This is just the path to the python binary, this does not provide activation or any
@@ -177,16 +197,6 @@ export interface IProposedExtensionAPI {
177197
path: string,
178198
options?: EnvironmentDetailsOptions,
179199
): Promise<EnvironmentDetails | undefined>;
180-
/**
181-
* Returns paths to environments that uniquely identifies an environment found by the extension
182-
* at the time of calling. This API will *not* trigger a refresh. If a refresh is going on it
183-
* will *not* wait for the refresh to finish. This will return what is known so far. To get
184-
* complete list `await` on promise returned by `getRefreshPromise()`.
185-
*
186-
* Virtual environments lacking an interpreter are identified by environment folder paths,
187-
* whereas other envs can be identified using interpreter path.
188-
*/
189-
getEnvironmentPaths(): Promise<EnvPathType[] | undefined>;
190200
/**
191201
* Sets the active environment path for the python extension for the resource. Configuration target
192202
* will always be the workspace folder.
@@ -195,34 +205,100 @@ export interface IProposedExtensionAPI {
195205
* folder.
196206
*/
197207
setActiveEnvironment(path: string, resource?: Resource): Promise<void>;
198-
/**
199-
* This API will re-trigger environment discovery. Extensions can wait on the returned
200-
* promise to get the updated environment list. If there is a refresh already going on
201-
* then it returns the promise for that refresh.
202-
* @param options : [optional]
203-
* * clearCache : When true, this will clear the cache before environment refresh
204-
* is triggered.
205-
*/
206-
refreshEnvironment(options?: RefreshEnvironmentsOptions): Promise<EnvPathType[] | undefined>;
207-
/**
208-
* Tracks discovery progress for current list of known environments, i.e when it starts, finishes or any other relevant
209-
* stage. Note the progress for a particular query is currently not tracked or reported, this only indicates progress of
210-
* the entire collection.
211-
*/
212-
readonly onRefreshProgress: Event<ProgressNotificationEvent>;
213-
/**
214-
* Returns a promise for the ongoing refresh. Returns `undefined` if there are no active
215-
* refreshes going on.
216-
*/
217-
getRefreshPromise(options?: GetRefreshEnvironmentsOptions): Promise<void> | undefined;
218-
/**
219-
* This event is triggered when the known environment list changes, like when a environment
220-
* is found, existing environment is removed, or some details changed on an environment.
221-
*/
222-
onDidEnvironmentsChanged: Event<EnvironmentsChangedParams[]>;
223-
/**
224-
* This event is triggered when the active environment changes.
225-
*/
226-
onDidActiveEnvironmentChanged: Event<ActiveEnvironmentChangedParams>;
208+
locator: {
209+
/**
210+
* Returns paths to environments that uniquely identifies an environment found by the extension
211+
* at the time of calling. This API will *not* trigger a refresh. If a refresh is going on it
212+
* will *not* wait for the refresh to finish. This will return what is known so far. To get
213+
* complete list `await` on promise returned by `getRefreshPromise()`.
214+
*
215+
* Environments lacking an interpreter are identified by environment folder paths,
216+
* whereas other envs can be identified using executable path.
217+
*/
218+
getEnvironmentPaths(): Promise<EnvPathType[] | undefined>;
219+
/**
220+
* This event is triggered when the known environment list changes, like when a environment
221+
* is found, existing environment is removed, or some details changed on an environment.
222+
*/
223+
onDidEnvironmentsChanged: Event<EnvironmentsChangedParams[]>;
224+
/**
225+
* This API will re-trigger environment discovery. Extensions can wait on the returned
226+
* promise to get the updated environment list. If there is a refresh already going on
227+
* then it returns the promise for that refresh.
228+
* @param options : [optional]
229+
* * clearCache : When true, this will clear the cache before environment refresh
230+
* is triggered.
231+
*/
232+
refreshEnvironment(options?: RefreshEnvironmentsOptions): Promise<EnvPathType[] | undefined>;
233+
/**
234+
* Returns a promise for the ongoing refresh. Returns `undefined` if there are no active
235+
* refreshes going on.
236+
*/
237+
getRefreshPromise(options?: GetRefreshEnvironmentsOptions): Promise<void> | undefined;
238+
/**
239+
* Tracks discovery progress for current list of known environments, i.e when it starts, finishes or any other relevant
240+
* stage. Note the progress for a particular query is currently not tracked or reported, this only indicates progress of
241+
* the entire collection.
242+
*/
243+
readonly onRefreshProgress: Event<ProgressNotificationEvent>;
244+
};
245+
registerEnvironmentProvider(
246+
environmentProvider: IEnvironmentProvider,
247+
metadata: EnvironmentProviderMetadata,
248+
): Promise<void>;
227249
};
228250
}
251+
252+
export type EnvInfo = {
253+
envSources: EnvSource;
254+
executablePath: string;
255+
envPath?: string;
256+
};
257+
258+
interface IEnvironmentProvider {
259+
locator: ILocatorAPI;
260+
getEnvironmentDetails: (env: EnvInfo) => Promise<EnvironmentDetails | undefined>;
261+
}
262+
263+
export interface ILocatorAPI {
264+
iterEnvs?(): IPythonEnvsIterator<EnvInfo>;
265+
readonly onChanged?: Event<LocatorEnvsChangedEvent>;
266+
}
267+
268+
/**
269+
* These can be used when querying for a particular env.
270+
*/
271+
interface EnvironmentProviderMetadata {
272+
readonly envType: EnvType;
273+
readonly searchLocation?: string;
274+
readonly envSources: EnvSource[];
275+
}
276+
277+
export interface LocatorEnvsChangedEvent {
278+
/**
279+
* Any details known about the environment which can be used for query.
280+
*/
281+
env?: EnvironmentProviderMetadata;
282+
type: EnvChangeType;
283+
}
284+
285+
export type EnvChangeType = 'add' | 'remove' | 'update';
286+
287+
export enum EnvType {
288+
VirtualEnv = 'VirtualEnv',
289+
Conda = 'Conda',
290+
Unknown = 'Unknown',
291+
Global = 'GlobalInterpreter',
292+
}
293+
294+
export enum EnvSource {
295+
Conda = 'Conda',
296+
Pipenv = 'PipEnv',
297+
Poetry = 'Poetry',
298+
VirtualEnv = 'VirtualEnv',
299+
Venv = 'Venv',
300+
VirtualEnvWrapper = 'VirtualEnvWrapper',
301+
WindowsStore = 'WindowsStore',
302+
Pyenv = 'Pyenv',
303+
Custom = 'Custom',
304+
}

0 commit comments

Comments
 (0)