@@ -9,21 +9,25 @@ import { InterpreterInformation } from '../../pythonEnvironments/info';
99import { sendTelemetryEvent } from '../../telemetry' ;
1010import { EventName } from '../../telemetry/constants' ;
1111import { PythonInterpreterTelemetry } from '../../telemetry/types' ;
12- import { IInterpreterVersionService } from '../contracts' ;
12+ import { IComponentAdapter } from '../contracts' ;
1313import { IPythonPathUpdaterServiceFactory , IPythonPathUpdaterServiceManager } from './types' ;
1414
1515@injectable ( )
1616export 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 : {
0 commit comments