Skip to content

Commit 32b688e

Browse files
author
Kartik Raj
authored
Rename EnvironmentId to EnvironmentPath (#19887)
1 parent 0f04578 commit 32b688e

5 files changed

+67
-54
lines changed

src/client/deprecatedProposedApi.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ export function buildDeprecatedProposedApi(
8585
const env = await interpreterService.getActiveInterpreter(resource);
8686
return env ? { execCommand: [env.path] } : { execCommand: undefined };
8787
},
88-
async getActiveEnvironmentPath(resource?: Resource) {
89-
sendApiTelemetry('getActiveEnvironmentPath');
90-
const env = await interpreterService.getActiveInterpreter(resource);
91-
if (!env) {
92-
return undefined;
93-
}
94-
return getEnvPath(env.path, env.envPath);
95-
},
9688
async getEnvironmentDetails(
9789
path: string,
9890
options?: EnvironmentDetailsOptions,

src/client/deprecatedProposedApiTypes.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ export interface DeprecatedProposedAPI {
7474
*/
7575
execCommand: string[] | undefined;
7676
}>;
77-
/**
78-
* @deprecated Use {@link getActiveEnvironmentId} instead. This will soon be removed.
79-
*/
80-
getActiveEnvironmentPath(resource?: Resource): Promise<EnvPathType | undefined>;
8177
/**
8278
* Returns details for the given interpreter. Details such as absolute interpreter path,
8379
* version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under
@@ -135,7 +131,7 @@ export interface DeprecatedProposedAPI {
135131
*/
136132
onDidEnvironmentsChanged: Event<EnvironmentsChangedParams[]>;
137133
/**
138-
* @deprecated Use {@link ProposedExtensionAPI.environment} `onDidChangeActiveEnvironmentId` instead. This will soon be removed.
134+
* @deprecated Use {@link ProposedExtensionAPI.environment} `onDidChangeActiveEnvironmentPath` instead. This will soon be removed.
139135
*/
140136
onDidActiveEnvironmentChanged: Event<ActiveEnvironmentChangedParams>;
141137
};

src/client/proposedApi.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IConfigurationService, IDisposableRegistry, IExtensions, IInterpreterPa
88
import { Architecture } from './common/utils/platform';
99
import { IServiceContainer } from './ioc/types';
1010
import {
11-
ActiveEnvironmentIdChangeEvent,
11+
ActiveEnvironmentPathChangeEvent,
1212
Environment,
1313
EnvironmentsChangeEvent,
1414
ProposedExtensionAPI,
@@ -17,7 +17,7 @@ import {
1717
Resource,
1818
EnvironmentType,
1919
EnvironmentTools,
20-
EnvironmentId,
20+
EnvironmentPath,
2121
} from './proposedApiTypes';
2222
import { PythonEnvInfo, PythonEnvKind, PythonEnvType } from './pythonEnvironments/base/info';
2323
import { getEnvPath } from './pythonEnvironments/base/info/env';
@@ -38,7 +38,7 @@ type ActiveEnvironmentChangeEvent = {
3838
path: string;
3939
};
4040

41-
const onDidActiveInterpreterChangedEvent = new EventEmitter<ActiveEnvironmentIdChangeEvent>();
41+
const onDidActiveInterpreterChangedEvent = new EventEmitter<ActiveEnvironmentPathChangeEvent>();
4242
export function reportActiveInterpreterChanged(e: ActiveEnvironmentChangeEvent): void {
4343
onDidActiveInterpreterChangedEvent.fire({ id: getEnvID(e.path), path: e.path, resource: e.resource });
4444
reportActiveInterpreterChangedDeprecated({ path: e.path, resource: e.resource?.uri });
@@ -164,24 +164,34 @@ export function buildProposedApi(
164164

165165
const proposed: ProposedExtensionAPI = {
166166
environment: {
167-
getActiveEnvironmentId(resource?: Resource) {
168-
sendApiTelemetry('getActiveEnvironmentId');
167+
getActiveEnvironmentPath(resource?: Resource) {
168+
sendApiTelemetry('getActiveEnvironmentPath');
169169
resource = resource && 'uri' in resource ? resource.uri : resource;
170170
const path = configService.getSettings(resource).pythonPath;
171171
const id = path === 'python' ? 'DEFAULT_PYTHON' : getEnvID(path);
172-
return { id, path };
172+
return {
173+
id,
174+
path,
175+
/**
176+
* @deprecated Only provided for backwards compatibility and will soon be removed.
177+
*/
178+
pathType: 'interpreterPath',
179+
};
173180
},
174-
updateActiveEnvironmentId(env: Environment | EnvironmentId | string, resource?: Resource): Promise<void> {
175-
sendApiTelemetry('updateActiveEnvironmentId');
181+
updateActiveEnvironmentPath(
182+
env: Environment | EnvironmentPath | string,
183+
resource?: Resource,
184+
): Promise<void> {
185+
sendApiTelemetry('updateActiveEnvironmentPath');
176186
const path = typeof env !== 'string' ? env.path : env;
177187
resource = resource && 'uri' in resource ? resource.uri : resource;
178188
return interpreterPathService.update(resource, ConfigurationTarget.WorkspaceFolder, path);
179189
},
180-
get onDidChangeActiveEnvironmentId() {
181-
sendApiTelemetry('onDidChangeActiveEnvironmentId');
190+
get onDidChangeActiveEnvironmentPath() {
191+
sendApiTelemetry('onDidChangeActiveEnvironmentPath');
182192
return onDidActiveInterpreterChangedEvent.event;
183193
},
184-
resolveEnvironment: async (env: Environment | EnvironmentId | string) => {
194+
resolveEnvironment: async (env: Environment | EnvironmentPath | string) => {
185195
let path = typeof env !== 'string' ? env.path : env;
186196
if (pathUtils.basename(path) === path) {
187197
// Value can be `python`, `python3`, `python3.9` etc.

src/client/proposedApiTypes.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ export interface ProposedExtensionAPI {
1212
* @param resource : Uri of a file or workspace folder. This is used to determine the env in a multi-root
1313
* scenario. If `undefined`, then the API returns what ever is set for the workspace.
1414
*/
15-
getActiveEnvironmentId(resource?: Resource): EnvironmentId;
15+
getActiveEnvironmentPath(resource?: Resource): EnvironmentPath;
1616
/**
1717
* Sets the active environment path for the python extension for the resource. Configuration target will always
1818
* be the workspace folder.
1919
* @param environment : Full path to environment folder or python executable for the environment. Can also pass
2020
* the environment itself.
2121
* @param resource : [optional] File or workspace to scope to a particular workspace folder.
2222
*/
23-
updateActiveEnvironmentId(
24-
environment: Environment | EnvironmentId | string,
23+
updateActiveEnvironmentPath(
24+
environment: string | EnvironmentPath | Environment,
2525
resource?: Resource,
2626
): Promise<void>;
2727
/**
2828
* This event is triggered when the active environment setting changes.
2929
*/
30-
readonly onDidChangeActiveEnvironmentId: Event<ActiveEnvironmentIdChangeEvent>;
30+
readonly onDidChangeActiveEnvironmentPath: Event<ActiveEnvironmentPathChangeEvent>;
3131
/**
3232
* Carries environments found by the extension at the time of fetching the property. Note this may not
3333
* contain all environments in the system as a refresh might be going on.
@@ -55,7 +55,9 @@ export interface ProposedExtensionAPI {
5555
* @param environment : Full path to environment folder or python executable for the environment. Can also pass
5656
* the environment id or the environment itself.
5757
*/
58-
resolveEnvironment(environment: Environment | EnvironmentId | string): Promise<ResolvedEnvironment | undefined>;
58+
resolveEnvironment(
59+
environment: Environment | EnvironmentPath | string,
60+
): Promise<ResolvedEnvironment | undefined>;
5961
};
6062
}
6163

@@ -70,7 +72,7 @@ export type RefreshOptions = {
7072
/**
7173
* Details about the environment. Note the environment folder, type and name never changes over time.
7274
*/
73-
export type Environment = EnvironmentId & {
75+
export type Environment = EnvironmentPath & {
7476
/**
7577
* Carries details about python executable.
7678
*/
@@ -175,7 +177,7 @@ export type EnvironmentsChangeEvent = {
175177
readonly type: 'add' | 'remove' | 'update';
176178
};
177179

178-
export type ActiveEnvironmentIdChangeEvent = EnvironmentId & {
180+
export type ActiveEnvironmentPathChangeEvent = EnvironmentPath & {
179181
/**
180182
* Workspace folder the environment changed for.
181183
*/
@@ -187,7 +189,7 @@ export type ActiveEnvironmentIdChangeEvent = EnvironmentId & {
187189
*/
188190
export type Resource = Uri | WorkspaceFolder;
189191

190-
export type EnvironmentId = {
192+
export type EnvironmentPath = {
191193
/**
192194
* The ID of the environment.
193195
*/

src/test/proposedApi.unit.test.ts

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ import { sleep } from './core';
2626
import { PythonEnvKind, PythonEnvSource } from '../client/pythonEnvironments/base/info';
2727
import { Architecture } from '../client/common/utils/platform';
2828
import { PythonEnvCollectionChangedEvent } from '../client/pythonEnvironments/base/watcher';
29+
import { normCasePath } from '../client/common/platform/fs-paths';
2930
import {
30-
ProposedExtensionAPI,
31-
ActiveEnvironmentIdChangeEvent,
31+
ActiveEnvironmentPathChangeEvent,
32+
EnvironmentPath,
3233
EnvironmentsChangeEvent,
34+
ProposedExtensionAPI,
3335
} from '../client/proposedApiTypes';
34-
import { normCasePath } from '../client/common/platform/fs-paths';
3536

3637
suite('Proposed Extension API', () => {
3738
let serviceContainer: typemoq.IMock<IServiceContainer>;
@@ -74,8 +75,8 @@ suite('Proposed Extension API', () => {
7475
});
7576

7677
test('Provide an event to track when active environment details change', async () => {
77-
const events: ActiveEnvironmentIdChangeEvent[] = [];
78-
proposed.environment.onDidChangeActiveEnvironmentId((e) => {
78+
const events: ActiveEnvironmentPathChangeEvent[] = [];
79+
proposed.environment.onDidChangeActiveEnvironmentPath((e) => {
7980
events.push(e);
8081
});
8182
reportActiveInterpreterChanged({ path: 'path/to/environment', resource: undefined });
@@ -85,32 +86,44 @@ suite('Proposed Extension API', () => {
8586
]);
8687
});
8788

88-
test('getActiveEnvironmentId: No resource', () => {
89+
test('getActiveEnvironmentPath: No resource', () => {
8990
const pythonPath = 'this/is/a/test/path';
9091
configService
9192
.setup((c) => c.getSettings(undefined))
9293
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
93-
const actual = proposed.environment.getActiveEnvironmentId();
94-
assert.deepEqual(actual, { id: normCasePath(pythonPath), path: pythonPath });
94+
const actual = proposed.environment.getActiveEnvironmentPath();
95+
assert.deepEqual(actual, ({
96+
id: normCasePath(pythonPath),
97+
path: pythonPath,
98+
pathType: 'interpreterPath',
99+
} as unknown) as EnvironmentPath);
95100
});
96101

97-
test('getActiveEnvironmentId: default python', () => {
102+
test('getActiveEnvironmentPath: default python', () => {
98103
const pythonPath = 'python';
99104
configService
100105
.setup((c) => c.getSettings(undefined))
101106
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
102-
const actual = proposed.environment.getActiveEnvironmentId();
103-
assert.deepEqual(actual, { id: 'DEFAULT_PYTHON', path: pythonPath });
107+
const actual = proposed.environment.getActiveEnvironmentPath();
108+
assert.deepEqual(actual, ({
109+
id: 'DEFAULT_PYTHON',
110+
path: pythonPath,
111+
pathType: 'interpreterPath',
112+
} as unknown) as EnvironmentPath);
104113
});
105114

106-
test('getActiveEnvironmentId: With resource', () => {
115+
test('getActiveEnvironmentPath: With resource', () => {
107116
const pythonPath = 'this/is/a/test/path';
108117
const resource = Uri.file(__filename);
109118
configService
110119
.setup((c) => c.getSettings(resource))
111120
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
112-
const actual = proposed.environment.getActiveEnvironmentId(resource);
113-
assert.deepEqual(actual, { id: normCasePath(pythonPath), path: pythonPath });
121+
const actual = proposed.environment.getActiveEnvironmentPath(resource);
122+
assert.deepEqual(actual, ({
123+
id: normCasePath(pythonPath),
124+
path: pythonPath,
125+
pathType: 'interpreterPath',
126+
} as unknown) as EnvironmentPath);
114127
});
115128

116129
test('resolveEnvironment: invalid environment (when passed as string)', async () => {
@@ -317,44 +330,44 @@ suite('Proposed Extension API', () => {
317330
assert.deepEqual(eventValues, expectedEvents);
318331
});
319332

320-
test('updateActiveEnvironmentId: no resource', async () => {
333+
test('updateActiveEnvironmentPath: no resource', async () => {
321334
interpreterPathService
322335
.setup((i) => i.update(undefined, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
323336
.returns(() => Promise.resolve())
324337
.verifiable(typemoq.Times.once());
325338

326-
await proposed.environment.updateActiveEnvironmentId('this/is/a/test/python/path');
339+
await proposed.environment.updateActiveEnvironmentPath('this/is/a/test/python/path');
327340

328341
interpreterPathService.verifyAll();
329342
});
330343

331-
test('updateActiveEnvironmentId: passed as Environment', async () => {
344+
test('updateActiveEnvironmentPath: passed as Environment', async () => {
332345
interpreterPathService
333346
.setup((i) => i.update(undefined, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
334347
.returns(() => Promise.resolve())
335348
.verifiable(typemoq.Times.once());
336349

337-
await proposed.environment.updateActiveEnvironmentId({
350+
await proposed.environment.updateActiveEnvironmentPath({
338351
id: normCasePath('this/is/a/test/python/path'),
339352
path: 'this/is/a/test/python/path',
340353
});
341354

342355
interpreterPathService.verifyAll();
343356
});
344357

345-
test('updateActiveEnvironmentId: with uri', async () => {
358+
test('updateActiveEnvironmentPath: with uri', async () => {
346359
const uri = Uri.parse('a');
347360
interpreterPathService
348361
.setup((i) => i.update(uri, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
349362
.returns(() => Promise.resolve())
350363
.verifiable(typemoq.Times.once());
351364

352-
await proposed.environment.updateActiveEnvironmentId('this/is/a/test/python/path', uri);
365+
await proposed.environment.updateActiveEnvironmentPath('this/is/a/test/python/path', uri);
353366

354367
interpreterPathService.verifyAll();
355368
});
356369

357-
test('updateActiveEnvironmentId: with workspace folder', async () => {
370+
test('updateActiveEnvironmentPath: with workspace folder', async () => {
358371
const uri = Uri.parse('a');
359372
interpreterPathService
360373
.setup((i) => i.update(uri, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
@@ -366,7 +379,7 @@ suite('Proposed Extension API', () => {
366379
index: 0,
367380
};
368381

369-
await proposed.environment.updateActiveEnvironmentId('this/is/a/test/python/path', workspace);
382+
await proposed.environment.updateActiveEnvironmentPath('this/is/a/test/python/path', workspace);
370383

371384
interpreterPathService.verifyAll();
372385
});

0 commit comments

Comments
 (0)