Skip to content

Commit a06f21b

Browse files
authored
Leverage ComponentAdapter.getInterpreterInformation in PythonPathUpdaterService (#15134)
* Fix linting * Use new discovery code, remove bitness from props * Remove pipVersion from PYTHON_INTERPRETER
1 parent 95dffe5 commit a06f21b

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ src/client/interpreter/configuration/interpreterSelector/commands/setInterpreter
340340
src/client/interpreter/configuration/interpreterSelector/commands/resetInterpreter.ts
341341
src/client/interpreter/configuration/interpreterSelector/commands/setShebangInterpreter.ts
342342
src/client/interpreter/configuration/interpreterSelector/interpreterSelector.ts
343-
src/client/interpreter/configuration/pythonPathUpdaterService.ts
344343
src/client/interpreter/configuration/pythonPathUpdaterServiceFactory.ts
345344
src/client/interpreter/configuration/services/globalUpdaterService.ts
346345
src/client/interpreter/configuration/services/workspaceUpdaterService.ts

src/client/interpreter/configuration/pythonPathUpdaterService.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,25 @@ import { InterpreterInformation } from '../../pythonEnvironments/info';
99
import { sendTelemetryEvent } from '../../telemetry';
1010
import { EventName } from '../../telemetry/constants';
1111
import { PythonInterpreterTelemetry } from '../../telemetry/types';
12-
import { IInterpreterVersionService } from '../contracts';
12+
import { IComponentAdapter } from '../contracts';
1313
import { IPythonPathUpdaterServiceFactory, IPythonPathUpdaterServiceManager } from './types';
1414

1515
@injectable()
1616
export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManager {
1717
private readonly pythonPathSettingsUpdaterFactory: IPythonPathUpdaterServiceFactory;
18-
private readonly interpreterVersionService: IInterpreterVersionService;
18+
1919
private readonly executionFactory: IPythonExecutionFactory;
20+
21+
private readonly componentAdapter: IComponentAdapter;
22+
2023
constructor(@inject(IServiceContainer) serviceContainer: IServiceContainer) {
2124
this.pythonPathSettingsUpdaterFactory = serviceContainer.get<IPythonPathUpdaterServiceFactory>(
2225
IPythonPathUpdaterServiceFactory,
2326
);
24-
this.interpreterVersionService = serviceContainer.get<IInterpreterVersionService>(IInterpreterVersionService);
2527
this.executionFactory = serviceContainer.get<IPythonExecutionFactory>(IPythonExecutionFactory);
28+
this.componentAdapter = serviceContainer.get<IComponentAdapter>(IComponentAdapter);
2629
}
30+
2731
public async updatePythonPath(
2832
pythonPath: string | undefined,
2933
configTarget: ConfigurationTarget,
@@ -47,6 +51,7 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
4751
traceError('Python Extension: sendTelemetry', ex),
4852
);
4953
}
54+
5055
private async sendTelemetry(
5156
duration: number,
5257
failed: boolean,
@@ -58,27 +63,26 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
5863
trigger,
5964
};
6065
if (!failed && pythonPath) {
61-
const processService = await this.executionFactory.create({ pythonPath });
62-
const infoPromise = processService
63-
.getInterpreterInformation()
64-
.catch<InterpreterInformation | undefined>(() => undefined);
65-
const pipVersionPromise = this.interpreterVersionService
66-
.getPipVersion(pythonPath)
67-
.then((value) => (value.length === 0 ? undefined : value))
68-
.catch<string>(() => '');
69-
const [info, pipVersion] = await Promise.all([infoPromise, pipVersionPromise]);
70-
if (info) {
71-
telemetryProperties.architecture = info.architecture;
72-
if (info.version) {
66+
// Ask for info using the new discovery code first.
67+
// If it returns undefined, fallback on the old code.
68+
const interpreterInfo = await this.componentAdapter.getInterpreterInformation(pythonPath);
69+
if (interpreterInfo && interpreterInfo.version) {
70+
telemetryProperties.pythonVersion = interpreterInfo.version.raw;
71+
} else {
72+
const processService = await this.executionFactory.create({ pythonPath });
73+
const info = await processService
74+
.getInterpreterInformation()
75+
.catch<InterpreterInformation | undefined>(() => undefined);
76+
77+
if (info && info.version) {
7378
telemetryProperties.pythonVersion = info.version.raw;
7479
}
7580
}
76-
if (pipVersion) {
77-
telemetryProperties.pipVersion = pipVersion;
78-
}
7981
}
82+
8083
sendTelemetryEvent(EventName.PYTHON_INTERPRETER, duration, telemetryProperties);
8184
}
85+
8286
private getPythonUpdaterService(configTarget: ConfigurationTarget, wkspace?: Uri) {
8387
switch (configTarget) {
8488
case ConfigurationTarget.Global: {

src/client/telemetry/index.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { AppinsightsKey, isTestExecution, isUnitTestExecution, PVSC_EXTENSION_ID
1111
import { traceError, traceInfo } from '../common/logger';
1212
import { Telemetry } from '../common/startPage/constants';
1313
import type { TerminalShellType } from '../common/terminal/types';
14-
import { Architecture } from '../common/utils/platform';
1514
import { StopWatch } from '../common/utils/stopWatch';
1615
import { DebugConfigurationType } from '../debugger/extension/types';
1716
import { ConsoleType, TriggerType } from '../debugger/types';
@@ -933,18 +932,6 @@ export interface IEventNamePropertyMapping {
933932
* @type {string}
934933
*/
935934
pythonVersion?: string;
936-
/**
937-
* The version of pip module installed in the python interpreter
938-
*
939-
* @type {string}
940-
*/
941-
pipVersion?: string;
942-
/**
943-
* The bit-ness of the python interpreter represented using architecture.
944-
*
945-
* @type {Architecture}
946-
*/
947-
architecture?: Architecture;
948935
};
949936
[EventName.PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES]: {
950937
/**

0 commit comments

Comments
 (0)