Skip to content

Commit 4396943

Browse files
author
Kartik Raj
committed
Rename EnvironmentId to EnvironmentPath
1 parent 0f04578 commit 4396943

5 files changed

+47
-47
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: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
@@ -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<ActiveEnvironmentIdChangeEvent>;
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 ActiveEnvironmentIdChangeEvent = 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: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ 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,
3131
ActiveEnvironmentIdChangeEvent,
3232
EnvironmentsChangeEvent,
33+
ProposedExtensionAPI,
3334
} from '../client/proposedApiTypes';
34-
import { normCasePath } from '../client/common/platform/fs-paths';
3535

3636
suite('Proposed Extension API', () => {
3737
let serviceContainer: typemoq.IMock<IServiceContainer>;
@@ -75,7 +75,7 @@ suite('Proposed Extension API', () => {
7575

7676
test('Provide an event to track when active environment details change', async () => {
7777
const events: ActiveEnvironmentIdChangeEvent[] = [];
78-
proposed.environment.onDidChangeActiveEnvironmentId((e) => {
78+
proposed.environment.onDidChangeActiveEnvironmentPath((e) => {
7979
events.push(e);
8080
});
8181
reportActiveInterpreterChanged({ path: 'path/to/environment', resource: undefined });
@@ -85,31 +85,31 @@ suite('Proposed Extension API', () => {
8585
]);
8686
});
8787

88-
test('getActiveEnvironmentId: No resource', () => {
88+
test('getActiveEnvironmentPath: No resource', () => {
8989
const pythonPath = 'this/is/a/test/path';
9090
configService
9191
.setup((c) => c.getSettings(undefined))
9292
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
93-
const actual = proposed.environment.getActiveEnvironmentId();
93+
const actual = proposed.environment.getActiveEnvironmentPath();
9494
assert.deepEqual(actual, { id: normCasePath(pythonPath), path: pythonPath });
9595
});
9696

97-
test('getActiveEnvironmentId: default python', () => {
97+
test('getActiveEnvironmentPath: default python', () => {
9898
const pythonPath = 'python';
9999
configService
100100
.setup((c) => c.getSettings(undefined))
101101
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
102-
const actual = proposed.environment.getActiveEnvironmentId();
102+
const actual = proposed.environment.getActiveEnvironmentPath();
103103
assert.deepEqual(actual, { id: 'DEFAULT_PYTHON', path: pythonPath });
104104
});
105105

106-
test('getActiveEnvironmentId: With resource', () => {
106+
test('getActiveEnvironmentPath: With resource', () => {
107107
const pythonPath = 'this/is/a/test/path';
108108
const resource = Uri.file(__filename);
109109
configService
110110
.setup((c) => c.getSettings(resource))
111111
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
112-
const actual = proposed.environment.getActiveEnvironmentId(resource);
112+
const actual = proposed.environment.getActiveEnvironmentPath(resource);
113113
assert.deepEqual(actual, { id: normCasePath(pythonPath), path: pythonPath });
114114
});
115115

@@ -317,44 +317,44 @@ suite('Proposed Extension API', () => {
317317
assert.deepEqual(eventValues, expectedEvents);
318318
});
319319

320-
test('updateActiveEnvironmentId: no resource', async () => {
320+
test('updateActiveEnvironmentPath: no resource', async () => {
321321
interpreterPathService
322322
.setup((i) => i.update(undefined, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
323323
.returns(() => Promise.resolve())
324324
.verifiable(typemoq.Times.once());
325325

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

328328
interpreterPathService.verifyAll();
329329
});
330330

331-
test('updateActiveEnvironmentId: passed as Environment', async () => {
331+
test('updateActiveEnvironmentPath: passed as Environment', async () => {
332332
interpreterPathService
333333
.setup((i) => i.update(undefined, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
334334
.returns(() => Promise.resolve())
335335
.verifiable(typemoq.Times.once());
336336

337-
await proposed.environment.updateActiveEnvironmentId({
337+
await proposed.environment.updateActiveEnvironmentPath({
338338
id: normCasePath('this/is/a/test/python/path'),
339339
path: 'this/is/a/test/python/path',
340340
});
341341

342342
interpreterPathService.verifyAll();
343343
});
344344

345-
test('updateActiveEnvironmentId: with uri', async () => {
345+
test('updateActiveEnvironmentPath: with uri', async () => {
346346
const uri = Uri.parse('a');
347347
interpreterPathService
348348
.setup((i) => i.update(uri, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
349349
.returns(() => Promise.resolve())
350350
.verifiable(typemoq.Times.once());
351351

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

354354
interpreterPathService.verifyAll();
355355
});
356356

357-
test('updateActiveEnvironmentId: with workspace folder', async () => {
357+
test('updateActiveEnvironmentPath: with workspace folder', async () => {
358358
const uri = Uri.parse('a');
359359
interpreterPathService
360360
.setup((i) => i.update(uri, ConfigurationTarget.WorkspaceFolder, 'this/is/a/test/python/path'))
@@ -366,7 +366,7 @@ suite('Proposed Extension API', () => {
366366
index: 0,
367367
};
368368

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

371371
interpreterPathService.verifyAll();
372372
});

0 commit comments

Comments
 (0)