3
3
// Copyright (c) Microsoft Corporation. All rights reserved.
4
4
// Licensed under the MIT License.
5
5
6
- import { Event , Terminal , Uri } from 'vscode' ;
6
+ import { Disposable , Event , Uri } from 'vscode' ;
7
7
import { Resource } from './common/types' ;
8
8
import { Architecture } from './common/utils/platform' ;
9
9
import { IDataViewerDataProvider , IJupyterUriProvider } from './jupyter/types' ;
@@ -98,65 +98,62 @@ export interface IExtensionApi {
98
98
99
99
export interface EnvironmentDetailsOptions {
100
100
useCache : boolean ;
101
- // noShell?: boolean; // For execution without shell
101
+ /**
102
+ * Return details provided by the specific provider, throws error if provider not found.
103
+ */
104
+ providerId ?: ProviderID ;
102
105
}
103
106
107
+ type VersionInfo = {
108
+ major : number ;
109
+ minor : number ;
110
+ micro : number ;
111
+ releaselevel : 'alpha' | 'beta' | 'candidate' | 'final' ;
112
+ serial : number ;
113
+ } ;
114
+
104
115
export interface EnvironmentDetails {
105
116
executable : {
106
117
path : string ;
107
- // run: string[];
108
- // env?: any;
109
- // shell?: boolean;
110
- // shellCommand?: Record<'cmd' | 'fish' | 'bash' | 'string', { run: string[] }>;
111
- // cwd?: string;
118
+ run : {
119
+ // Functions would only require the arguments. The env provider can internally decide on the commands.
120
+ // Support option of whether to run as a process or VSCode terminal.
121
+ // However note we cannot pass this into the debugger at the moment, as VSCode itself handles execution.
122
+ // Gotta add support in VSCode for that, they already support that for LSP.
123
+ // TODO: Gotta support this for upstream debugger
124
+ exec : Function ;
125
+ shellExec : Function ; // Only for backwards compatibility.
126
+ execObservable : Function ;
127
+ /**
128
+ * Uses a VSCode terminal.
129
+ * */
130
+ terminalExec : ( ) => void ;
131
+ /**
132
+ * Any environment variables that can be used to activate the environment, if supported.
133
+ * If not provided, Python extension itself uses the other execution APIs to calculate it.
134
+ */
135
+ env ?: { [ key : string ] : string | null | undefined } ;
136
+ } ;
112
137
bitness ?: Architecture ;
113
138
sysPrefix : string ;
114
139
} ;
115
- executionAPIs : {
116
- // Functions would only require the arguments. The env provider can internally decide on the commands.
117
- // Support option of whether to run as a process or VSCode terminal.
118
- // However note we cannot pass this into the debugger at the moment, as VSCode itself handles execution.
119
- // Gotta add support in VSCode for that, they already support that for LSP.
120
- // TODO: Gotta support this for upstream debugger
121
- shellExec : Function ;
122
- shellExecObservable : Function ;
123
- exec : Function ;
124
- execObservable : Function ;
125
- } ;
126
- distributor ?: {
127
- // PEP 514 (https://www.python.org/dev/peps/pep-0514/)
128
- name : string ; // Could even be used for Pyenv.
129
- url ?: string ; // 'https://www.python.org';
130
- } ;
131
140
environment ?: {
132
141
type : EnvType ;
133
142
name ?: string ;
134
143
path : string ;
135
144
project ?: string ; // Any specific project environment is created for.
136
145
source : EnvSource [ ] ;
137
- activate : { [ key : string ] : string | null | undefined } ;
138
- } ;
139
- version : {
140
- major : number ;
141
- minor : number ;
142
- micro : number ;
143
- releaselevel : 'alpha' | 'beta' | 'candidate' | 'final' ;
144
- serial : number ;
146
+ } ; ;
147
+ version : VersionInfo & {
145
148
sysVersion ?: string ;
146
- } ;
149
+ } ; ;
147
150
implementation ?: {
148
151
// `sys.implementation`
149
152
name : string ;
150
- version : {
151
- major : number ;
152
- minor : number ;
153
- micro : number ;
154
- releaselevel : 'alpha' | 'beta' | 'candidate' | 'final' ;
153
+ version : VersionInfo & {
155
154
serial : number ;
156
155
} ;
157
156
} ;
158
- // Are the results specific to the environment (variables, working directory, etc.)?
159
- // contextSensitive: boolean;
160
157
}
161
158
162
159
export interface EnvironmentsChangedParams {
@@ -263,17 +260,24 @@ export interface IProposedExtensionAPI {
263
260
registerEnvironmentProvider (
264
261
environmentProvider : IEnvironmentProvider ,
265
262
metadata : EnvironmentProviderMetadata ,
266
- ) : Promise < void > ; // TODO: Disposable??
263
+ ) : Promise < Disposable > ; // TODO: Disposable?? // TODO: Confirm whether this should return a promise ??
267
264
} ;
268
265
}
269
266
267
+ /**
268
+ * Provider is only expected to provide the executable key, so construct a type using `EnvironmentDetails`
269
+ * where `executable` is the only necessary key.
270
+ */
271
+ type EnvironmentDetailsByProvider = Omit < Partial < EnvironmentDetails > , 'executable' > &
272
+ Pick < EnvironmentDetails , 'executable' > ;
273
+
270
274
interface IEnvironmentProvider {
271
- // TODO: createEnv
272
275
createLocator : ILocatorFactory ;
273
- getEnvironmentDetails : ( env : EnvInfo ) => Promise < EnvironmentDetails | undefined > ;
276
+ getEnvironmentDetails : ( env : EnvInfo ) => Promise < EnvironmentDetailsByProvider | undefined > ;
274
277
}
275
278
276
- export type ILocatorFactory = ( root ?: string ) => ILocatorAPI ;
279
+ type isRootBasedLocatorFactory = ( ( root : string ) => ILocatorAPI ) ;
280
+ export type ILocatorFactory = ( ( ) => ILocatorAPI ) | isRootBasedLocatorFactory ;
277
281
278
282
export interface ILocatorAPI {
279
283
iterEnvs ?( ) : IPythonEnvsIterator < EnvInfo > ;
@@ -286,23 +290,40 @@ export type EnvInfo = {
286
290
envPath ?: string ;
287
291
} ;
288
292
293
+ type ProviderID = string ;
294
+
289
295
/**
290
296
* These can be used when querying for a particular env.
291
297
*/
292
298
interface EnvironmentProviderMetadata {
293
- readonly envType : EnvType ;
294
- readonly searchLocation ?: string ;
295
- readonly envSources : EnvSource [ ] ; // Think of whether it should be an array?
299
+ /**
300
+ * Details about the environments the locator provides.
301
+ * Useful when querying for a particular env.
302
+ */
303
+ readonly environments ?: EnvironmentMetaData ;
304
+ /**
305
+ * If locator requires a root to search envs within.
306
+ */
296
307
readonly isRootBasedLocator : boolean ;
308
+ /**
309
+ * An Identifier for the provider.
310
+ */
311
+ readonly providerId : ProviderID ;
297
312
}
298
313
299
- type EnvironmentMetaData = EnvironmentProviderMetadata ;
314
+ interface EnvironmentMetaData {
315
+ readonly envType : EnvType ;
316
+ readonly envSources : EnvSource [ ] ;
317
+ }
300
318
301
319
export interface LocatorEnvsChangedEvent {
302
320
/**
303
321
* Any details known about the environment which can be used for query.
304
322
*/
305
323
env ?: EnvironmentMetaData ;
324
+ /**
325
+ * Details about how the environment was modified.
326
+ **/
306
327
type : EnvChangeType ;
307
328
}
308
329
@@ -326,4 +347,5 @@ export enum KnownEnvSourceTypes {
326
347
VirtualEnv = 'VirtualEnv' ,
327
348
Venv = 'Venv' ,
328
349
VirtualEnvWrapper = 'VirtualEnvWrapper' ,
350
+ Pyenv = 'Pyenv' ,
329
351
}
0 commit comments