Skip to content

Commit 2465015

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

File tree

6 files changed

+294
-83
lines changed

6 files changed

+294
-83
lines changed

src/client/apiTypes.ts

Lines changed: 156 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,106 @@ 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: ILocatorClass;
260+
getEnvironmentDetails: (env: EnvInfo) => Promise<EnvironmentDetails | undefined>;
261+
}
262+
263+
export interface ILocatorClass {
264+
new (root?: string): ILocatorAPI;
265+
}
266+
267+
export interface ILocatorAPI {
268+
iterEnvs?(): IPythonEnvsIterator<EnvInfo>;
269+
readonly onChanged?: Event<LocatorEnvsChangedEvent>;
270+
}
271+
272+
/**
273+
* These can be used when querying for a particular env.
274+
*/
275+
interface EnvironmentProviderMetadata {
276+
readonly envType: EnvType;
277+
readonly searchLocation?: string;
278+
readonly envSources: EnvSource[];
279+
}
280+
281+
type EnvironmentMetaData = EnvironmentProviderMetadata;
282+
283+
export interface LocatorEnvsChangedEvent {
284+
/**
285+
* Any details known about the environment which can be used for query.
286+
*/
287+
env?: EnvironmentMetaData;
288+
type: EnvChangeType;
289+
}
290+
291+
export type EnvChangeType = 'add' | 'remove' | 'update';
292+
293+
export enum EnvType {
294+
VirtualEnv = 'VirtualEnv',
295+
Conda = 'Conda',
296+
Unknown = 'Unknown',
297+
Global = 'GlobalInterpreter',
298+
}
299+
300+
export enum EnvSource {
301+
Conda = 'Conda',
302+
Pipenv = 'PipEnv',
303+
Poetry = 'Poetry',
304+
VirtualEnv = 'VirtualEnv',
305+
Venv = 'Venv',
306+
VirtualEnvWrapper = 'VirtualEnvWrapper',
307+
WindowsStore = 'WindowsStore',
308+
Pyenv = 'Pyenv',
309+
Custom = 'Custom',
310+
}

src/client/proposedApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function getVersionString(env: PythonEnvInfo): string[] {
3333
if (env.version.release) {
3434
ver.push(`${env.version.release}`);
3535
if (env.version.sysVersion) {
36-
ver.push(`${env.version.release}`);
36+
ver.push(`${env.version.sysVersion}`);
3737
}
3838
}
3939
return ver;

src/client/pythonEnvironments/base/info/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export enum PythonEnvKind {
2929
export interface EnvPathType {
3030
/**
3131
* Path to environment folder or path to interpreter that uniquely identifies an environment.
32-
* Virtual environments lacking an interpreter are identified by environment folder paths,
32+
* Environments lacking an interpreter are identified by environment folder paths,
3333
* whereas other envs can be identified using interpreter path.
3434
*/
3535
path: string;

src/client/pythonEnvironments/base/locator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ export type BasicEnvInfo = {
153153
* events emitted via `onChanged` do not need to provide information
154154
* for the specific environments that changed.
155155
*/
156-
export interface ILocator<I = PythonEnvInfo, E extends BasicPythonEnvsChangedEvent = PythonEnvsChangedEvent>
157-
extends IPythonEnvsWatcher<E> {
156+
export interface ILocator<I = PythonEnvInfo, E = PythonEnvsChangedEvent> extends IPythonEnvsWatcher<E> {
158157
/**
159158
* Iterate over the enviroments known tos this locator.
160159
*

0 commit comments

Comments
 (0)