Skip to content

Commit 787fa5a

Browse files
author
Kartik Raj
authored
Improve discovery resolving API (#18729)
* Improve discovery resolving API * Improve public api doc * Fix tests
1 parent f1d0509 commit 787fa5a

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

src/client/apiTypes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export interface IProposedExtensionAPI {
139139
* Returns details for the given interpreter. Details such as absolute interpreter path,
140140
* version, type (conda, pyenv, etc). Metadata such as `sysPrefix` can be found under
141141
* metadata field.
142-
* @param path : Path to environment folder or path to interpreter whose details you need.
142+
* @param path : Full path to environment folder or interpreter whose details you need.
143143
* @param options : [optional]
144144
* * useCache : When true, cache is checked first for any data, returns even if there
145145
* is partial data.
@@ -159,9 +159,9 @@ export interface IProposedExtensionAPI {
159159
*/
160160
getEnvironmentPaths(): Promise<EnvPathType[] | undefined>;
161161
/**
162-
* Sets the active environment path for the python extension. Configuration target will
163-
* always be the workspace folder.
164-
* @param path : Interpreter path to set for a given workspace.
162+
* Sets the active environment path for the python extension for the resource. Configuration target
163+
* will always be the workspace folder.
164+
* @param path : Full path to environment folder or interpreter to set.
165165
* @param resource : [optional] Uri of a file ro workspace to scope to a particular workspace
166166
* folder.
167167
*/
@@ -171,7 +171,7 @@ export interface IProposedExtensionAPI {
171171
* promise to get the updated environment list. If there is a refresh already going on
172172
* then it returns the promise for that refresh.
173173
* @param options : [optional]
174-
* * clearCache : When true, this will clear the cache before interpreter refresh
174+
* * clearCache : When true, this will clear the cache before environment refresh
175175
* is triggered.
176176
*/
177177
refreshEnvironment(options?: RefreshEnvironmentsOptions): Promise<EnvPathType[] | undefined>;

src/client/interpreter/configuration/pythonPathUpdaterService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { inject, injectable } from 'inversify';
22
import * as path from 'path';
33
import { ConfigurationTarget, Uri, window } from 'vscode';
44
import { StopWatch } from '../../common/utils/stopWatch';
5+
import { SystemVariables } from '../../common/variables/systemVariables';
56
import { traceError } from '../../logging';
67
import { sendTelemetryEvent } from '../../telemetry';
78
import { EventName } from '../../telemetry/constants';
@@ -36,7 +37,7 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
3637
traceError(reason);
3738
}
3839
// do not wait for this to complete
39-
this.sendTelemetry(stopWatch.elapsedTime, failed, trigger, pythonPath).catch((ex) =>
40+
this.sendTelemetry(stopWatch.elapsedTime, failed, trigger, pythonPath, wkspace).catch((ex) =>
4041
traceError('Python Extension: sendTelemetry', ex),
4142
);
4243
}
@@ -46,13 +47,15 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
4647
failed: boolean,
4748
trigger: 'ui' | 'shebang' | 'load',
4849
pythonPath: string | undefined,
50+
wkspace?: Uri,
4951
) {
5052
const telemetryProperties: PythonInterpreterTelemetry = {
5153
failed,
5254
trigger,
5355
};
5456
if (!failed && pythonPath) {
55-
const interpreterInfo = await this.pyenvs.getInterpreterInformation(pythonPath);
57+
const systemVariables = new SystemVariables(undefined, wkspace?.fsPath);
58+
const interpreterInfo = await this.pyenvs.getInterpreterInformation(systemVariables.resolveAny(pythonPath));
5659
if (interpreterInfo) {
5760
telemetryProperties.pythonVersion = interpreterInfo.version?.raw;
5861
}

src/client/interpreter/display/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingle
127127
} else {
128128
this.statusBar.tooltip = '';
129129
this.statusBar.color = '';
130-
this.statusBar.text = '$(alert) Select Python Interpreter';
130+
this.statusBar.text = `$(alert) ${InterpreterQuickPickList.browsePath.openButtonLabel()}`;
131131
this.currentlySelectedInterpreterDisplay = undefined;
132132
}
133133
} else if (this.languageStatus) {

src/client/pythonEnvironments/base/locator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export interface IDiscoveryAPI {
196196
* Find as much info about the given Python environment as possible.
197197
* If path passed is invalid, then `undefined` is returned.
198198
*
199-
* @param path - Python executable path or environment path to resolve more information about
199+
* @param path - Full path of Python executable or environment folder to resolve more information about
200200
*/
201201
resolveEnv(path: string): Promise<PythonEnvInfo | undefined>;
202202
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export class EnvsCollectionService extends PythonEnvsWatcher<PythonEnvCollection
6666
if (cachedEnv) {
6767
return cachedEnv;
6868
}
69-
const resolved = await this.locator.resolveEnv(path);
69+
const resolved = await this.locator.resolveEnv(path).catch((ex) => {
70+
traceError(`Failed to resolve ${path}`, ex);
71+
return undefined;
72+
});
7073
if (resolved) {
7174
this.cache.addEnv(resolved, true);
7275
}

src/client/pythonEnvironments/common/environmentIdentifier.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
import { traceWarn } from '../../logging';
45
import { PythonEnvKind } from '../base/info';
56
import { getPrioritizedEnvKinds } from '../base/info/envKind';
67
import { isCondaEnvironment } from './environmentManagers/conda';
@@ -46,7 +47,13 @@ export async function identifyEnvironment(path: string): Promise<PythonEnvKind>
4647
const prioritizedEnvTypes = getPrioritizedEnvKinds();
4748
for (const e of prioritizedEnvTypes) {
4849
const identifier = identifiers.get(e);
49-
if (identifier && (await identifier(path))) {
50+
if (
51+
identifier &&
52+
(await identifier(path).catch((ex) => {
53+
traceWarn(`Identifier for ${e} failed to identify ${path}`, ex);
54+
return false;
55+
}))
56+
) {
5057
return e;
5158
}
5259
}

src/test/interpreters/display.unit.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ suite('Interpreters Display', () => {
273273
} else {
274274
statusBar.verify((s) => (s.color = TypeMoq.It.isValue('')), TypeMoq.Times.once());
275275
statusBar.verify(
276-
(s) => (s.text = TypeMoq.It.isValue('$(alert) Select Python Interpreter')),
276+
(s) =>
277+
(s.text = TypeMoq.It.isValue(
278+
`$(alert) ${InterpreterQuickPickList.browsePath.openButtonLabel()}`,
279+
)),
277280
TypeMoq.Times.once(),
278281
);
279282
}

0 commit comments

Comments
 (0)