Skip to content

Commit 645873a

Browse files
author
Kartik Raj
committed
Add an API to add a new locator
1 parent 3e509b8 commit 645873a

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

src/client/pythonEnvironments/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ export type GetLocatorFunc = () => Promise<IDiscoveryAPI>;
2020
class PythonEnvironments implements IDiscoveryAPI {
2121
private locator!: IDiscoveryAPI;
2222

23+
public addNewLocator = this.locator.addNewLocator;
24+
2325
constructor(
2426
// These are factories for the sub-components the full component is composed of:
2527
private readonly getLocator: GetLocatorFunc,
2628
) {}
2729

2830
public async activate(): Promise<void> {
2931
this.locator = await this.getLocator();
32+
this.addNewLocator = this.locator.addNewLocator;
3033
}
3134

3235
public get onProgress(): Event<ProgressNotificationEvent> {

src/client/pythonEnvironments/base/locator.ts

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,62 @@ import {
1414
PythonEnvsWatcher,
1515
} from './watcher';
1616

17+
export interface ILocatorClass {
18+
new (root?: string): ILocatorAPI;
19+
}
20+
21+
export interface ILocatorAPI {
22+
iterEnvs?(): IPythonEnvsIterator<EnvInfo>;
23+
readonly onChanged?: Event<LocatorEnvsChangedEvent>;
24+
}
25+
26+
export type EnvInfo = {
27+
envSources: EnvSource[];
28+
executablePath: string;
29+
envPath?: string;
30+
};
31+
32+
/**
33+
* These can be used when querying for a particular env.
34+
*/
35+
interface EnvironmentProviderMetadata {
36+
readonly envType: EnvType;
37+
readonly searchLocation?: string;
38+
readonly envSources: EnvSource[];
39+
readonly isRootBasedLocator: boolean;
40+
}
41+
42+
type EnvironmentMetaData = EnvironmentProviderMetadata;
43+
44+
export interface LocatorEnvsChangedEvent {
45+
/**
46+
* Any details known about the environment which can be used for query.
47+
*/
48+
env?: EnvironmentMetaData;
49+
type: EnvChangeType;
50+
}
51+
52+
export type EnvChangeType = 'add' | 'remove' | 'update';
53+
54+
export enum EnvType {
55+
VirtualEnv = 'VirtualEnv',
56+
Conda = 'Conda',
57+
Unknown = 'Unknown',
58+
Global = 'GlobalInterpreter',
59+
}
60+
61+
export enum EnvSource {
62+
Conda = 'Conda',
63+
Pipenv = 'PipEnv',
64+
Poetry = 'Poetry',
65+
VirtualEnv = 'VirtualEnv',
66+
Venv = 'Venv',
67+
VirtualEnvWrapper = 'VirtualEnvWrapper',
68+
WindowsStore = 'WindowsStore',
69+
Pyenv = 'Pyenv',
70+
Custom = 'Custom',
71+
}
72+
1773
/**
1874
* A single update to a previously provided Python env object.
1975
*/
@@ -153,7 +209,9 @@ export type BasicEnvInfo = {
153209
* events emitted via `onChanged` do not need to provide information
154210
* for the specific environments that changed.
155211
*/
156-
export interface ILocator<I = PythonEnvInfo, E = PythonEnvsChangedEvent> extends IPythonEnvsWatcher<E> {
212+
export interface ILocator<I = PythonEnvInfo, E extends BasicPythonEnvsChangedEvent = PythonEnvsChangedEvent>
213+
extends IPythonEnvsWatcher<E>,
214+
IEnvProvider {
157215
/**
158216
* Iterate over the enviroments known tos this locator.
159217
*
@@ -173,6 +231,10 @@ export interface ILocator<I = PythonEnvInfo, E = PythonEnvsChangedEvent> extends
173231
iterEnvs(query?: QueryForEvent<E>): IPythonEnvsIterator<I>;
174232
}
175233

234+
export interface IEnvProvider {
235+
addNewLocator?(LocatorClass: ILocatorClass, isWorkspace: boolean): void;
236+
}
237+
176238
interface IResolver {
177239
/**
178240
* Find as much info about the given Python environment as possible.
@@ -203,7 +265,7 @@ export type TriggerRefreshOptions = {
203265
ifNotTriggerredAlready?: boolean;
204266
};
205267

206-
export interface IDiscoveryAPI {
268+
export interface IDiscoveryAPI extends IEnvProvider {
207269
/**
208270
* Tracks discovery progress for current list of known environments, i.e when it starts, finishes or any other relevant
209271
* stage. Note the progress for a particular query is currently not tracked or reported, this only indicates progress of

src/client/pythonEnvironments/base/locators/composite/envsCollectionService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export class EnvsCollectionService extends PythonEnvsWatcher<PythonEnvCollection
4747
return this.progress.event;
4848
}
4949

50+
public addNewLocator = this.locator.addNewLocator;
51+
5052
public getRefreshPromise(options?: GetRefreshEnvironmentsOptions): Promise<void> | undefined {
5153
const stage = options?.stage ?? ProgressReportStage.discoveryFinished;
5254
return this.progressPromises.get(stage)?.promise;

src/client/pythonEnvironments/base/locators/composite/envsReducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class PythonEnvsReducer implements ILocator<BasicEnvInfo> {
2727
return this.parentLocator.onChanged;
2828
}
2929

30+
public addNewLocator = this.parentLocator.addNewLocator;
31+
3032
constructor(private readonly parentLocator: ILocator<BasicEnvInfo>) {}
3133

3234
public iterEnvs(query?: PythonLocatorQuery): IPythonEnvsIterator<BasicEnvInfo> {

src/client/pythonEnvironments/base/locators/composite/envsResolver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class PythonEnvsResolver implements IResolvingLocator {
3434
return this.parentLocator.onChanged;
3535
}
3636

37+
public addNewLocator = this.parentLocator.addNewLocator;
38+
3739
constructor(
3840
private readonly parentLocator: ILocator<BasicEnvInfo>,
3941
private readonly environmentInfoService: IEnvironmentInfoService,

0 commit comments

Comments
 (0)