1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
// Copyright (c) Microsoft Corporation. All rights reserved.
2
3
// Licensed under the MIT License.
3
4
4
5
import { Event , Uri } from 'vscode' ;
5
6
import { Resource } from './common/types' ;
7
+ import { Architecture } from './common/utils/platform' ;
6
8
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' ;
9
15
10
16
/*
11
17
* Do not introduce any breaking changes to this API.
@@ -91,21 +97,55 @@ export interface IExtensionApi {
91
97
92
98
export interface EnvironmentDetailsOptions {
93
99
useCache : boolean ;
100
+ // noShell?: boolean; // For execution without shell
94
101
}
95
102
96
103
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 ;
102
142
}
103
143
104
144
export interface EnvironmentsChangedParams {
105
145
/**
106
146
* 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.
109
149
*/
110
150
path ?: string ;
111
151
type : 'add' | 'remove' | 'update' | 'clear-all' ;
@@ -114,8 +154,8 @@ export interface EnvironmentsChangedParams {
114
154
export interface ActiveEnvironmentChangedParams {
115
155
/**
116
156
* 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.
119
159
*/
120
160
path : string ;
121
161
resource ?: Uri ;
@@ -128,33 +168,13 @@ export interface RefreshEnvironmentsOptions {
128
168
export interface IProposedExtensionAPI {
129
169
environment : {
130
170
/**
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.
132
172
*/
133
- readonly onDidChangeExecutionDetails : Event < Uri | undefined > ;
173
+ onDidActiveEnvironmentChanged : Event < ActiveEnvironmentChangedParams > ;
134
174
/**
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.
142
176
*/
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 > ;
158
178
/**
159
179
* Returns the path to the python binary selected by the user or as in the settings.
160
180
* This is just the path to the python binary, this does not provide activation or any
@@ -177,16 +197,6 @@ export interface IProposedExtensionAPI {
177
197
path : string ,
178
198
options ?: EnvironmentDetailsOptions ,
179
199
) : 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 > ;
190
200
/**
191
201
* Sets the active environment path for the python extension for the resource. Configuration target
192
202
* will always be the workspace folder.
@@ -195,34 +205,106 @@ export interface IProposedExtensionAPI {
195
205
* folder.
196
206
*/
197
207
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 > ;
227
249
} ;
228
250
}
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
+ }
0 commit comments