@@ -9,21 +9,25 @@ import { InterpreterInformation } from '../../pythonEnvironments/info';
9
9
import { sendTelemetryEvent } from '../../telemetry' ;
10
10
import { EventName } from '../../telemetry/constants' ;
11
11
import { PythonInterpreterTelemetry } from '../../telemetry/types' ;
12
- import { IInterpreterVersionService } from '../contracts' ;
12
+ import { IComponentAdapter } from '../contracts' ;
13
13
import { IPythonPathUpdaterServiceFactory , IPythonPathUpdaterServiceManager } from './types' ;
14
14
15
15
@injectable ( )
16
16
export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManager {
17
17
private readonly pythonPathSettingsUpdaterFactory : IPythonPathUpdaterServiceFactory ;
18
- private readonly interpreterVersionService : IInterpreterVersionService ;
18
+
19
19
private readonly executionFactory : IPythonExecutionFactory ;
20
+
21
+ private readonly componentAdapter : IComponentAdapter ;
22
+
20
23
constructor ( @inject ( IServiceContainer ) serviceContainer : IServiceContainer ) {
21
24
this . pythonPathSettingsUpdaterFactory = serviceContainer . get < IPythonPathUpdaterServiceFactory > (
22
25
IPythonPathUpdaterServiceFactory ,
23
26
) ;
24
- this . interpreterVersionService = serviceContainer . get < IInterpreterVersionService > ( IInterpreterVersionService ) ;
25
27
this . executionFactory = serviceContainer . get < IPythonExecutionFactory > ( IPythonExecutionFactory ) ;
28
+ this . componentAdapter = serviceContainer . get < IComponentAdapter > ( IComponentAdapter ) ;
26
29
}
30
+
27
31
public async updatePythonPath (
28
32
pythonPath : string | undefined ,
29
33
configTarget : ConfigurationTarget ,
@@ -47,6 +51,7 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
47
51
traceError ( 'Python Extension: sendTelemetry' , ex ) ,
48
52
) ;
49
53
}
54
+
50
55
private async sendTelemetry (
51
56
duration : number ,
52
57
failed : boolean ,
@@ -58,27 +63,26 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage
58
63
trigger,
59
64
} ;
60
65
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 ) {
73
78
telemetryProperties . pythonVersion = info . version . raw ;
74
79
}
75
80
}
76
- if ( pipVersion ) {
77
- telemetryProperties . pipVersion = pipVersion ;
78
- }
79
81
}
82
+
80
83
sendTelemetryEvent ( EventName . PYTHON_INTERPRETER , duration , telemetryProperties ) ;
81
84
}
85
+
82
86
private getPythonUpdaterService ( configTarget : ConfigurationTarget , wkspace ?: Uri ) {
83
87
switch ( configTarget ) {
84
88
case ConfigurationTarget . Global : {
0 commit comments