Skip to content

Commit 6c317df

Browse files
author
Kartik Raj
authored
Fix deprecated API bug (#19944)
1 parent 90fb214 commit 6c317df

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

src/client/deprecatedProposedApi.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,23 @@ export function buildDeprecatedProposedApi(
8686
const proposed: DeprecatedProposedAPI = {
8787
environment: {
8888
async getExecutionDetails(resource?: Resource) {
89-
sendApiTelemetry('getExecutionDetails');
89+
sendApiTelemetry('deprecated.getExecutionDetails');
9090
const env = await interpreterService.getActiveInterpreter(resource);
9191
return env ? { execCommand: [env.path] } : { execCommand: undefined };
9292
},
93+
async getActiveEnvironmentPath(resource?: Resource) {
94+
sendApiTelemetry('deprecated.getActiveEnvironmentPath');
95+
const env = await interpreterService.getActiveInterpreter(resource);
96+
if (!env) {
97+
return undefined;
98+
}
99+
return getEnvPath(env.path, env.envPath);
100+
},
93101
async getEnvironmentDetails(
94102
path: string,
95103
options?: EnvironmentDetailsOptions,
96104
): Promise<EnvironmentDetails | undefined> {
97-
sendApiTelemetry('getEnvironmentDetails');
105+
sendApiTelemetry('deprecated.getEnvironmentDetails');
98106
let env: PythonEnvInfo | undefined;
99107
if (options?.useCache) {
100108
env = discoveryApi.getEnvs().find((v) => isEnvSame(path, v));
@@ -118,38 +126,38 @@ export function buildDeprecatedProposedApi(
118126
};
119127
},
120128
getEnvironmentPaths() {
121-
sendApiTelemetry('getEnvironmentPaths');
129+
sendApiTelemetry('deprecated.getEnvironmentPaths');
122130
const paths = discoveryApi.getEnvs().map((e) => getEnvPath(e.executable.filename, e.location));
123131
return Promise.resolve(paths);
124132
},
125133
setActiveEnvironment(path: string, resource?: Resource): Promise<void> {
126-
sendApiTelemetry('setActiveEnvironment');
134+
sendApiTelemetry('deprecated.setActiveEnvironment');
127135
return interpreterPathService.update(resource, ConfigurationTarget.WorkspaceFolder, path);
128136
},
129137
async refreshEnvironment() {
130-
sendApiTelemetry('refreshEnvironment');
138+
sendApiTelemetry('deprecated.refreshEnvironment');
131139
await discoveryApi.triggerRefresh();
132140
const paths = discoveryApi.getEnvs().map((e) => getEnvPath(e.executable.filename, e.location));
133141
return Promise.resolve(paths);
134142
},
135143
getRefreshPromise(options?: GetRefreshEnvironmentsOptions): Promise<void> | undefined {
136-
sendApiTelemetry('getRefreshPromise');
144+
sendApiTelemetry('deprecated.getRefreshPromise');
137145
return discoveryApi.getRefreshPromise(options);
138146
},
139147
get onDidChangeExecutionDetails() {
140-
sendApiTelemetry('onDidChangeExecutionDetails', false);
148+
sendApiTelemetry('deprecated.onDidChangeExecutionDetails', false);
141149
return interpreterService.onDidChangeInterpreterConfiguration;
142150
},
143151
get onDidEnvironmentsChanged() {
144-
sendApiTelemetry('onDidEnvironmentsChanged', false);
152+
sendApiTelemetry('deprecated.onDidEnvironmentsChanged', false);
145153
return onDidInterpretersChangedEvent.event;
146154
},
147155
get onDidActiveEnvironmentChanged() {
148-
sendApiTelemetry('onDidActiveEnvironmentChanged', false);
156+
sendApiTelemetry('deprecated.onDidActiveEnvironmentChanged', false);
149157
return onDidActiveInterpreterChangedEvent.event;
150158
},
151159
get onRefreshProgress() {
152-
sendApiTelemetry('onRefreshProgress', false);
160+
sendApiTelemetry('deprecated.onRefreshProgress', false);
153161
return discoveryApi.onProgress;
154162
},
155163
},

src/client/deprecatedProposedApiTypes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ export interface DeprecatedProposedAPI {
7474
*/
7575
execCommand: string[] | undefined;
7676
}>;
77+
/**
78+
* Returns the path to the python binary selected by the user or as in the settings.
79+
* This is just the path to the python binary, this does not provide activation or any
80+
* other activation command. The `resource` if provided will be used to determine the
81+
* python binary in a multi-root scenario. If resource is `undefined` then the API
82+
* returns what ever is set for the workspace.
83+
* @param resource : Uri of a file or workspace
84+
*/
85+
getActiveEnvironmentPath(resource?: Resource): Promise<EnvPathType | undefined>;
7786
/**
7887
* Returns details for the given interpreter. Details such as absolute interpreter path,
7988
* version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under

src/client/proposedApi.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
reportActiveInterpreterChangedDeprecated,
3333
reportInterpretersChanged,
3434
} from './deprecatedProposedApi';
35+
import { DeprecatedProposedAPI } from './deprecatedProposedApiTypes';
3536

3637
type ActiveEnvironmentChangeEvent = {
3738
resource: WorkspaceFolder | undefined;
@@ -151,18 +152,19 @@ export function buildProposedApi(
151152
);
152153

153154
/**
154-
* @deprecated Will be removed soon. Use {@link ProposedExtensionAPI.environments} instead.
155+
* @deprecated Will be removed soon. Use {@link ProposedExtensionAPI} instead.
155156
*/
156-
let deprecatedEnvironmentsApi;
157+
let deprecatedProposedApi;
157158
try {
158-
deprecatedEnvironmentsApi = { ...buildDeprecatedProposedApi(discoveryApi, serviceContainer).environment };
159+
deprecatedProposedApi = { ...buildDeprecatedProposedApi(discoveryApi, serviceContainer) };
159160
} catch (ex) {
160-
deprecatedEnvironmentsApi = {};
161+
deprecatedProposedApi = {} as DeprecatedProposedAPI;
161162
// Errors out only in case of testing.
162163
// Also, these APIs no longer supported, no need to log error.
163164
}
164165

165-
const proposed: ProposedExtensionAPI = {
166+
const proposed: ProposedExtensionAPI & DeprecatedProposedAPI = {
167+
...deprecatedProposedApi,
166168
environments: {
167169
getActiveEnvironmentPath(resource?: Resource) {
168170
sendApiTelemetry('getActiveEnvironmentPath');
@@ -172,10 +174,6 @@ export function buildProposedApi(
172174
return {
173175
id,
174176
path,
175-
/**
176-
* @deprecated Only provided for backwards compatibility and will soon be removed.
177-
*/
178-
pathType: 'interpreterPath',
179177
};
180178
},
181179
updateActiveEnvironmentPath(
@@ -228,7 +226,6 @@ export function buildProposedApi(
228226
return onEnvironmentsChanged.event;
229227
},
230228
},
231-
...deprecatedEnvironmentsApi,
232229
};
233230
return proposed;
234231
}

src/test/proposedApi.unit.test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { PythonEnvCollectionChangedEvent } from '../client/pythonEnvironments/ba
2929
import { normCasePath } from '../client/common/platform/fs-paths';
3030
import {
3131
ActiveEnvironmentPathChangeEvent,
32-
EnvironmentPath,
3332
EnvironmentsChangeEvent,
3433
ProposedExtensionAPI,
3534
} from '../client/proposedApiTypes';
@@ -92,11 +91,10 @@ suite('Proposed Extension API', () => {
9291
.setup((c) => c.getSettings(undefined))
9392
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
9493
const actual = proposed.environments.getActiveEnvironmentPath();
95-
assert.deepEqual(actual, ({
94+
assert.deepEqual(actual, {
9695
id: normCasePath(pythonPath),
9796
path: pythonPath,
98-
pathType: 'interpreterPath',
99-
} as unknown) as EnvironmentPath);
97+
});
10098
});
10199

102100
test('getActiveEnvironmentPath: default python', () => {
@@ -105,11 +103,10 @@ suite('Proposed Extension API', () => {
105103
.setup((c) => c.getSettings(undefined))
106104
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
107105
const actual = proposed.environments.getActiveEnvironmentPath();
108-
assert.deepEqual(actual, ({
106+
assert.deepEqual(actual, {
109107
id: 'DEFAULT_PYTHON',
110108
path: pythonPath,
111-
pathType: 'interpreterPath',
112-
} as unknown) as EnvironmentPath);
109+
});
113110
});
114111

115112
test('getActiveEnvironmentPath: With resource', () => {
@@ -119,11 +116,10 @@ suite('Proposed Extension API', () => {
119116
.setup((c) => c.getSettings(resource))
120117
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
121118
const actual = proposed.environments.getActiveEnvironmentPath(resource);
122-
assert.deepEqual(actual, ({
119+
assert.deepEqual(actual, {
123120
id: normCasePath(pythonPath),
124121
path: pythonPath,
125-
pathType: 'interpreterPath',
126-
} as unknown) as EnvironmentPath);
122+
});
127123
});
128124

129125
test('resolveEnvironment: invalid environment (when passed as string)', async () => {

0 commit comments

Comments
 (0)