Skip to content

Commit 3404a15

Browse files
author
Kartik Raj
committed
Rearranging types
1 parent 0125ac4 commit 3404a15

File tree

1 file changed

+69
-47
lines changed

1 file changed

+69
-47
lines changed

src/client/apiTypes.ts

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright (c) Microsoft Corporation. All rights reserved.
44
// Licensed under the MIT License.
55

6-
import { Event, Terminal, Uri } from 'vscode';
6+
import { Disposable, Event, Uri } from 'vscode';
77
import { Resource } from './common/types';
88
import { Architecture } from './common/utils/platform';
99
import { IDataViewerDataProvider, IJupyterUriProvider } from './jupyter/types';
@@ -98,65 +98,62 @@ export interface IExtensionApi {
9898

9999
export interface EnvironmentDetailsOptions {
100100
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;
102105
}
103106

107+
type VersionInfo = {
108+
major: number;
109+
minor: number;
110+
micro: number;
111+
releaselevel: 'alpha' | 'beta' | 'candidate' | 'final';
112+
serial: number;
113+
};
114+
104115
export interface EnvironmentDetails {
105116
executable: {
106117
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+
};
112137
bitness?: Architecture;
113138
sysPrefix: string;
114139
};
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-
};
131140
environment?: {
132141
type: EnvType;
133142
name?: string;
134143
path: string;
135144
project?: string; // Any specific project environment is created for.
136145
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 & {
145148
sysVersion?: string;
146-
};
149+
};;
147150
implementation?: {
148151
// `sys.implementation`
149152
name: string;
150-
version: {
151-
major: number;
152-
minor: number;
153-
micro: number;
154-
releaselevel: 'alpha' | 'beta' | 'candidate' | 'final';
153+
version: VersionInfo & {
155154
serial: number;
156155
};
157156
};
158-
// Are the results specific to the environment (variables, working directory, etc.)?
159-
// contextSensitive: boolean;
160157
}
161158

162159
export interface EnvironmentsChangedParams {
@@ -263,17 +260,24 @@ export interface IProposedExtensionAPI {
263260
registerEnvironmentProvider(
264261
environmentProvider: IEnvironmentProvider,
265262
metadata: EnvironmentProviderMetadata,
266-
): Promise<void>; // TODO: Disposable??
263+
): Promise<Disposable>; // TODO: Disposable?? // TODO: Confirm whether this should return a promise??
267264
};
268265
}
269266

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+
270274
interface IEnvironmentProvider {
271-
// TODO: createEnv
272275
createLocator: ILocatorFactory;
273-
getEnvironmentDetails: (env: EnvInfo) => Promise<EnvironmentDetails | undefined>;
276+
getEnvironmentDetails: (env: EnvInfo) => Promise<EnvironmentDetailsByProvider | undefined>;
274277
}
275278

276-
export type ILocatorFactory = (root?: string) => ILocatorAPI;
279+
type isRootBasedLocatorFactory = ((root: string) => ILocatorAPI);
280+
export type ILocatorFactory = (() => ILocatorAPI) | isRootBasedLocatorFactory;
277281

278282
export interface ILocatorAPI {
279283
iterEnvs?(): IPythonEnvsIterator<EnvInfo>;
@@ -286,23 +290,40 @@ export type EnvInfo = {
286290
envPath?: string;
287291
};
288292

293+
type ProviderID = string;
294+
289295
/**
290296
* These can be used when querying for a particular env.
291297
*/
292298
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+
*/
296307
readonly isRootBasedLocator: boolean;
308+
/**
309+
* An Identifier for the provider.
310+
*/
311+
readonly providerId: ProviderID;
297312
}
298313

299-
type EnvironmentMetaData = EnvironmentProviderMetadata;
314+
interface EnvironmentMetaData {
315+
readonly envType: EnvType;
316+
readonly envSources: EnvSource[];
317+
}
300318

301319
export interface LocatorEnvsChangedEvent {
302320
/**
303321
* Any details known about the environment which can be used for query.
304322
*/
305323
env?: EnvironmentMetaData;
324+
/**
325+
* Details about how the environment was modified.
326+
**/
306327
type: EnvChangeType;
307328
}
308329

@@ -326,4 +347,5 @@ export enum KnownEnvSourceTypes {
326347
VirtualEnv = 'VirtualEnv',
327348
Venv = 'Venv',
328349
VirtualEnvWrapper = 'VirtualEnvWrapper',
350+
Pyenv = 'Pyenv',
329351
}

0 commit comments

Comments
 (0)