Skip to content

Commit c08dff2

Browse files
author
Kartik Raj
committed
Make env types optional
1 parent 7fdff89 commit c08dff2

File tree

5 files changed

+18
-165
lines changed

5 files changed

+18
-165
lines changed

src/client/apiTypes.ts

Lines changed: 11 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
import { Disposable, Event, Uri } from 'vscode';
77
import { Resource } from './common/types';
8-
import { Architecture } from './common/utils/platform';
98
import { IDataViewerDataProvider, IJupyterUriProvider } from './jupyter/types';
109
import { EnvPathType } from './pythonEnvironments/base/info';
1110
import {
11+
EnvironmentDetails,
12+
EnvironmentDetailsOptions,
13+
EnvironmentProviderMetadata,
1214
GetRefreshEnvironmentsOptions,
13-
IPythonEnvsIterator,
15+
IEnvironmentProvider,
1416
ProgressNotificationEvent,
1517
} from './pythonEnvironments/base/locator';
1618

@@ -96,152 +98,6 @@ export interface IExtensionApi {
9698
};
9799
}
98100

99-
export interface EnvironmentDetailsOptions {
100-
useCache: boolean;
101-
/**
102-
* Return details provided by the specific provider, throws error if provider not found.
103-
*/
104-
providerId?: ProviderID;
105-
}
106-
107-
type VersionInfo = {
108-
major: number;
109-
minor: number;
110-
micro: number;
111-
releaselevel: 'alpha' | 'beta' | 'candidate' | 'final';
112-
serial: number;
113-
};
114-
115-
export interface EnvironmentDetails {
116-
executable: {
117-
path: string;
118-
bitness?: Architecture;
119-
sysPrefix: string;
120-
};
121-
environment?: {
122-
type: EnvType;
123-
name?: string;
124-
path: string;
125-
project?: string; // Any specific project environment is created for.
126-
source: EnvSource[];
127-
};
128-
version: VersionInfo & {
129-
sysVersion?: string;
130-
};
131-
implementation?: {
132-
// `sys.implementation`
133-
name: string;
134-
version: VersionInfo & {
135-
serial: number;
136-
};
137-
};
138-
}
139-
140-
/**
141-
* Provider is only required to provide the `executable` key, rest are optional. So construct a type using
142-
* `EnvironmentDetails` where `executable` is the only required key.
143-
*/
144-
type EnvironmentDetailsByProvider = Partial<EnvironmentDetails> & Pick<EnvironmentDetails, 'executable'>;
145-
146-
interface IEnvironmentProvider extends ILocatorFactoryAPI, IResolverAPI {}
147-
148-
interface ILocatorFactoryAPI {
149-
/**
150-
* Factory function calling which create the locator.
151-
*/
152-
createLocator: ILocatorFactory;
153-
}
154-
155-
interface IResolverAPI {
156-
/**
157-
* Returns true if provided environment is recognized by the provider.
158-
*/
159-
canIdentifyEnvironment: (env: BaseEnvInfo) => Promise<boolean>;
160-
/**
161-
* This is only called if this provider can identify the environment.
162-
* Returns details or `undefined` if it was found if env is invalid.
163-
*/
164-
getEnvironmentDetails: (env: BaseEnvInfo) => Promise<EnvironmentDetailsByProvider | undefined>;
165-
}
166-
167-
export type ILocatorFactory = IWorkspaceLocatorFactory | INonWorkspaceLocatorFactory;
168-
export type INonWorkspaceLocatorFactory = () => ILocatorAPI;
169-
export type IWorkspaceLocatorFactory = (root: string) => ILocatorAPI;
170-
171-
export interface ILocatorAPI {
172-
iterEnvs?(): IPythonEnvsIterator<EnvInfo>;
173-
readonly onChanged?: Event<LocatorEnvsChangedEvent>;
174-
}
175-
176-
export type EnvInfo = BaseEnvInfo & {
177-
envSources: EnvSource[];
178-
};
179-
180-
export type BaseEnvInfo = {
181-
executablePath: string;
182-
envPath?: string;
183-
};
184-
185-
type ProviderID = string;
186-
187-
/**
188-
* These can be used when querying for a particular env.
189-
*/
190-
interface EnvironmentProviderMetadata {
191-
/**
192-
* Details about the environments the locator provides.
193-
* Useful when querying for a particular env.
194-
*/
195-
readonly environments?: EnvironmentMetaData;
196-
/**
197-
* If locator requires a workspace root to search envs within.
198-
*/
199-
readonly isWorkspaceBasedLocator: boolean;
200-
/**
201-
* An Identifier for the provider.
202-
*/
203-
readonly providerId: ProviderID;
204-
}
205-
206-
interface EnvironmentMetaData {
207-
readonly envType: EnvType;
208-
readonly envSources: EnvSource[];
209-
}
210-
211-
export interface LocatorEnvsChangedEvent {
212-
/**
213-
* Any details known about the environment which can be used for query.
214-
*/
215-
env?: EnvironmentMetaData;
216-
/**
217-
* Details about how the environment was modified.
218-
* */
219-
type: EnvChangeType;
220-
}
221-
222-
export type EnvChangeType = 'add' | 'remove' | 'update';
223-
224-
export type EnvType = KnownEnvTypes | string;
225-
226-
export enum KnownEnvTypes {
227-
VirtualEnv = 'VirtualEnv',
228-
Conda = 'Conda',
229-
Unknown = 'Unknown',
230-
Global = 'Global',
231-
}
232-
233-
export type EnvSource = KnownEnvSourceTypes | string;
234-
235-
export enum KnownEnvSourceTypes {
236-
Conda = 'Conda',
237-
Pipenv = 'PipEnv',
238-
Poetry = 'Poetry',
239-
VirtualEnv = 'VirtualEnv',
240-
Venv = 'Venv',
241-
VirtualEnvWrapper = 'VirtualEnvWrapper',
242-
Pyenv = 'Pyenv',
243-
}
244-
245101
export interface EnvironmentsChangedParams {
246102
/**
247103
* Path to environment folder or path to interpreter that uniquely identifies an environment.
@@ -272,10 +128,6 @@ export interface IProposedExtensionAPI {
272128
* This event is triggered when the active environment changes.
273129
*/
274130
onDidActiveEnvironmentChanged: Event<ActiveEnvironmentChangedParams>;
275-
/**
276-
* An event that is emitted when execution details (for a resource) change. For instance, when interpreter configuration changes.
277-
*/
278-
readonly onDidChangeExecutionDetails: Event<Uri | undefined>;
279131
/**
280132
* Returns the path to the python binary selected by the user or as in the settings.
281133
* This is just the path to the python binary, this does not provide activation or any
@@ -330,7 +182,7 @@ export interface IProposedExtensionAPI {
330182
* * clearCache : When true, this will clear the cache before environment refresh
331183
* is triggered.
332184
*/
333-
refreshEnvironment(options?: RefreshEnvironmentsOptions): Promise<EnvPathType[] | undefined>;
185+
refreshEnvironments(options?: RefreshEnvironmentsOptions): Promise<EnvPathType[] | undefined>;
334186
/**
335187
* Returns a promise for the ongoing refresh. Returns `undefined` if there are no active
336188
* refreshes going on.
@@ -343,9 +195,11 @@ export interface IProposedExtensionAPI {
343195
*/
344196
readonly onRefreshProgress: Event<ProgressNotificationEvent>;
345197
};
346-
registerEnvironmentProvider(
347-
environmentProvider: IEnvironmentProvider,
348-
metadata: EnvironmentProviderMetadata,
349-
): Promise<Disposable>; // TODO: Disposable?? // TODO: Confirm whether this should return a promise??
198+
// registerEnvironmentProvider(
199+
// environmentProvider: IEnvironmentProvider,
200+
// metadata: EnvironmentProviderMetadata,
201+
// ): Promise<Disposable>;
202+
// TODO: Confirm whether this should return a promise??
203+
// For eg. If we also initialize a refresh a background.
350204
};
351205
}

src/client/proposedApi.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import { ConfigurationTarget, EventEmitter } from 'vscode';
55
import {
66
ActiveEnvironmentChangedParams,
7-
EnvironmentDetails,
8-
EnvironmentDetailsOptions,
97
EnvironmentsChangedParams,
108
IProposedExtensionAPI,
119
RefreshEnvironmentsOptions,

src/client/pythonEnvironments/base/locator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ export interface EnvironmentProviderMetadata {
126126
}
127127

128128
interface InternalEnvironmentMetaData {
129-
readonly envType: EnvType;
130129
readonly envKinds: PythonEnvKind[];
131130
}
132131

@@ -147,7 +146,7 @@ export interface InternalEnvironmentProviderMetadata {
147146

148147
interface EnvironmentMetaData {
149148
readonly envType: EnvType;
150-
readonly envSources: EnvSource[];
149+
readonly envSources?: EnvSource[];
151150
}
152151

153152
export interface LocatorEnvsChangedEvent {

src/client/pythonEnvironments/base/locators/wrappers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
// eslint-disable-next-line max-classes-per-file
55
import { Uri } from 'vscode';
6-
import { ILocatorFactory } from '../../../apiTypes';
76
import { IDisposable } from '../../../common/types';
87
import { iterEmpty } from '../../../common/utils/async';
98
import { getURIFilter } from '../../../common/utils/misc';
@@ -18,6 +17,7 @@ import {
1817
PythonLocatorQuery,
1918
IWorkspaceLocatorFactory,
2019
ILocatorRegister,
20+
ILocatorFactory,
2121
} from '../locator';
2222
import { combineIterators, Locators } from '../locators';
2323
import { LazyResourceBasedLocator } from './common/resourceBasedLocator';

src/client/pythonEnvironments/converter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
import { EventEmitter, Event } from 'vscode';
5-
import { EnvChangeType, ILocatorAPI, LocatorEnvsChangedEvent, EnvInfo } from '../apiTypes';
65
import { FileChangeType } from '../common/platform/fileSystemWatcher';
76
import { traceVerbose } from '../logging';
87
import { PythonEnvInfo, PythonEnvKind } from './base/info';
@@ -23,6 +22,10 @@ import {
2322
IEnvironmentProvider,
2423
EnvironmentProviderMetadata,
2524
InternalEnvironmentProviderMetadata,
25+
EnvChangeType,
26+
EnvInfo,
27+
ILocatorAPI,
28+
LocatorEnvsChangedEvent,
2629
} from './base/locator';
2730
import { PythonEnvsChangedEvent } from './base/watcher';
2831

@@ -37,8 +40,7 @@ export function convertProviderMetaData(proposed: EnvironmentProviderMetadata):
3740
return {
3841
providerId: proposed.providerId,
3942
environments: {
40-
envKinds: proposed.environments.envSources.map((e) => convertKind(e)),
41-
envType: proposed.environments.envType,
43+
envKinds: proposed.environments.envSources?.map((e) => convertKind(e)) ?? [PythonEnvKind.Unknown],
4244
},
4345
};
4446
}

0 commit comments

Comments
 (0)