Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/client/deprecatedProposedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,23 @@ export function buildDeprecatedProposedApi(
const proposed: DeprecatedProposedAPI = {
environment: {
async getExecutionDetails(resource?: Resource) {
sendApiTelemetry('getExecutionDetails');
sendApiTelemetry('deprecated.getExecutionDetails');
const env = await interpreterService.getActiveInterpreter(resource);
return env ? { execCommand: [env.path] } : { execCommand: undefined };
},
async getActiveEnvironmentPath(resource?: Resource) {
sendApiTelemetry('deprecated.getActiveEnvironmentPath');
const env = await interpreterService.getActiveInterpreter(resource);
if (!env) {
return undefined;
}
return getEnvPath(env.path, env.envPath);
},
async getEnvironmentDetails(
path: string,
options?: EnvironmentDetailsOptions,
): Promise<EnvironmentDetails | undefined> {
sendApiTelemetry('getEnvironmentDetails');
sendApiTelemetry('deprecated.getEnvironmentDetails');
let env: PythonEnvInfo | undefined;
if (options?.useCache) {
env = discoveryApi.getEnvs().find((v) => isEnvSame(path, v));
Expand All @@ -118,38 +126,38 @@ export function buildDeprecatedProposedApi(
};
},
getEnvironmentPaths() {
sendApiTelemetry('getEnvironmentPaths');
sendApiTelemetry('deprecated.getEnvironmentPaths');
const paths = discoveryApi.getEnvs().map((e) => getEnvPath(e.executable.filename, e.location));
return Promise.resolve(paths);
},
setActiveEnvironment(path: string, resource?: Resource): Promise<void> {
sendApiTelemetry('setActiveEnvironment');
sendApiTelemetry('deprecated.setActiveEnvironment');
return interpreterPathService.update(resource, ConfigurationTarget.WorkspaceFolder, path);
},
async refreshEnvironment() {
sendApiTelemetry('refreshEnvironment');
sendApiTelemetry('deprecated.refreshEnvironment');
await discoveryApi.triggerRefresh();
const paths = discoveryApi.getEnvs().map((e) => getEnvPath(e.executable.filename, e.location));
return Promise.resolve(paths);
},
getRefreshPromise(options?: GetRefreshEnvironmentsOptions): Promise<void> | undefined {
sendApiTelemetry('getRefreshPromise');
sendApiTelemetry('deprecated.getRefreshPromise');
return discoveryApi.getRefreshPromise(options);
},
get onDidChangeExecutionDetails() {
sendApiTelemetry('onDidChangeExecutionDetails', false);
sendApiTelemetry('deprecated.onDidChangeExecutionDetails', false);
return interpreterService.onDidChangeInterpreterConfiguration;
},
get onDidEnvironmentsChanged() {
sendApiTelemetry('onDidEnvironmentsChanged', false);
sendApiTelemetry('deprecated.onDidEnvironmentsChanged', false);
return onDidInterpretersChangedEvent.event;
},
get onDidActiveEnvironmentChanged() {
sendApiTelemetry('onDidActiveEnvironmentChanged', false);
sendApiTelemetry('deprecated.onDidActiveEnvironmentChanged', false);
return onDidActiveInterpreterChangedEvent.event;
},
get onRefreshProgress() {
sendApiTelemetry('onRefreshProgress', false);
sendApiTelemetry('deprecated.onRefreshProgress', false);
return discoveryApi.onProgress;
},
},
Expand Down
9 changes: 9 additions & 0 deletions src/client/deprecatedProposedApiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ export interface DeprecatedProposedAPI {
*/
execCommand: string[] | undefined;
}>;
/**
* Returns the path to the python binary selected by the user or as in the settings.
* This is just the path to the python binary, this does not provide activation or any
* other activation command. The `resource` if provided will be used to determine the
* python binary in a multi-root scenario. If resource is `undefined` then the API
* returns what ever is set for the workspace.
* @param resource : Uri of a file or workspace
*/
getActiveEnvironmentPath(resource?: Resource): Promise<EnvPathType | undefined>;
/**
* Returns details for the given interpreter. Details such as absolute interpreter path,
* version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under
Expand Down
17 changes: 7 additions & 10 deletions src/client/proposedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
reportActiveInterpreterChangedDeprecated,
reportInterpretersChanged,
} from './deprecatedProposedApi';
import { DeprecatedProposedAPI } from './deprecatedProposedApiTypes';

type ActiveEnvironmentChangeEvent = {
resource: WorkspaceFolder | undefined;
Expand Down Expand Up @@ -151,18 +152,19 @@ export function buildProposedApi(
);

/**
* @deprecated Will be removed soon. Use {@link ProposedExtensionAPI.environments} instead.
* @deprecated Will be removed soon. Use {@link ProposedExtensionAPI} instead.
*/
let deprecatedEnvironmentsApi;
let deprecatedProposedApi;
try {
deprecatedEnvironmentsApi = { ...buildDeprecatedProposedApi(discoveryApi, serviceContainer).environment };
deprecatedProposedApi = { ...buildDeprecatedProposedApi(discoveryApi, serviceContainer) };
} catch (ex) {
deprecatedEnvironmentsApi = {};
deprecatedProposedApi = {} as DeprecatedProposedAPI;
// Errors out only in case of testing.
// Also, these APIs no longer supported, no need to log error.
}

const proposed: ProposedExtensionAPI = {
const proposed: ProposedExtensionAPI & DeprecatedProposedAPI = {
...deprecatedProposedApi,
environments: {
getActiveEnvironmentPath(resource?: Resource) {
sendApiTelemetry('getActiveEnvironmentPath');
Expand All @@ -172,10 +174,6 @@ export function buildProposedApi(
return {
id,
path,
/**
* @deprecated Only provided for backwards compatibility and will soon be removed.
*/
pathType: 'interpreterPath',
};
},
updateActiveEnvironmentPath(
Expand Down Expand Up @@ -228,7 +226,6 @@ export function buildProposedApi(
return onEnvironmentsChanged.event;
},
},
...deprecatedEnvironmentsApi,
};
return proposed;
}
Expand Down
16 changes: 6 additions & 10 deletions src/test/proposedApi.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { PythonEnvCollectionChangedEvent } from '../client/pythonEnvironments/ba
import { normCasePath } from '../client/common/platform/fs-paths';
import {
ActiveEnvironmentPathChangeEvent,
EnvironmentPath,
EnvironmentsChangeEvent,
ProposedExtensionAPI,
} from '../client/proposedApiTypes';
Expand Down Expand Up @@ -92,11 +91,10 @@ suite('Proposed Extension API', () => {
.setup((c) => c.getSettings(undefined))
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
const actual = proposed.environments.getActiveEnvironmentPath();
assert.deepEqual(actual, ({
assert.deepEqual(actual, {
id: normCasePath(pythonPath),
path: pythonPath,
pathType: 'interpreterPath',
} as unknown) as EnvironmentPath);
});
});

test('getActiveEnvironmentPath: default python', () => {
Expand All @@ -105,11 +103,10 @@ suite('Proposed Extension API', () => {
.setup((c) => c.getSettings(undefined))
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
const actual = proposed.environments.getActiveEnvironmentPath();
assert.deepEqual(actual, ({
assert.deepEqual(actual, {
id: 'DEFAULT_PYTHON',
path: pythonPath,
pathType: 'interpreterPath',
} as unknown) as EnvironmentPath);
});
});

test('getActiveEnvironmentPath: With resource', () => {
Expand All @@ -119,11 +116,10 @@ suite('Proposed Extension API', () => {
.setup((c) => c.getSettings(resource))
.returns(() => (({ pythonPath } as unknown) as IPythonSettings));
const actual = proposed.environments.getActiveEnvironmentPath(resource);
assert.deepEqual(actual, ({
assert.deepEqual(actual, {
id: normCasePath(pythonPath),
path: pythonPath,
pathType: 'interpreterPath',
} as unknown) as EnvironmentPath);
});
});

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