4
4
import { injectable } from 'inversify' ;
5
5
import { createDeferred , Deferred } from '../../common/utils/async' ;
6
6
import { createWorkerPool , IWorkerPool , QueuePosition } from '../../common/utils/workerPool' ;
7
- import { PythonEnvInfo } from '../base/info' ;
8
- import { getInterpreterInfo } from '../base/info/interpreter' ;
7
+ import { getInterpreterInfo , InterpreterInformation } from '../base/info/interpreter' ;
9
8
import { shellExecute } from '../common/externalDependencies' ;
10
9
import { buildPythonExecInfo } from '../exec' ;
11
10
@@ -17,26 +16,17 @@ export enum EnvironmentInfoServiceQueuePriority {
17
16
export const IEnvironmentInfoService = Symbol ( 'IEnvironmentInfoService' ) ;
18
17
export interface IEnvironmentInfoService {
19
18
getEnvironmentInfo (
20
- environment : PythonEnvInfo ,
19
+ interpreterPath : string ,
21
20
priority ?: EnvironmentInfoServiceQueuePriority
22
- ) : Promise < PythonEnvInfo | undefined > ;
21
+ ) : Promise < InterpreterInformation | undefined > ;
23
22
}
24
23
25
- async function buildEnvironmentInfo ( environment : PythonEnvInfo ) : Promise < PythonEnvInfo | undefined > {
26
- const interpreterInfo = await getInterpreterInfo (
27
- buildPythonExecInfo ( environment . executable . filename ) ,
28
- shellExecute ,
29
- ) ;
24
+ async function buildEnvironmentInfo ( interpreterPath : string ) : Promise < InterpreterInformation | undefined > {
25
+ const interpreterInfo = await getInterpreterInfo ( buildPythonExecInfo ( interpreterPath ) , shellExecute ) ;
30
26
if ( interpreterInfo === undefined || interpreterInfo . version === undefined ) {
31
27
return undefined ;
32
28
}
33
- // Deep copy into a new object
34
- const resolvedEnv = JSON . parse ( JSON . stringify ( environment ) ) as PythonEnvInfo ;
35
- resolvedEnv . version = interpreterInfo . version ;
36
- resolvedEnv . executable . filename = interpreterInfo . executable . filename ;
37
- resolvedEnv . executable . sysPrefix = interpreterInfo . executable . sysPrefix ;
38
- resolvedEnv . arch = interpreterInfo . arch ;
39
- return resolvedEnv ;
29
+ return interpreterInfo ;
40
30
}
41
31
42
32
@injectable ( )
@@ -45,29 +35,31 @@ export class EnvironmentInfoService implements IEnvironmentInfoService {
45
35
// path again and again in a given session. This information will likely not change in a given
46
36
// session. There are definitely cases where this will change. But a simple reload should address
47
37
// those.
48
- private readonly cache : Map < string , Deferred < PythonEnvInfo > > = new Map < string , Deferred < PythonEnvInfo > > ( ) ;
38
+ private readonly cache : Map < string , Deferred < InterpreterInformation > > = new Map <
39
+ string ,
40
+ Deferred < InterpreterInformation >
41
+ > ( ) ;
49
42
50
- private readonly workerPool : IWorkerPool < PythonEnvInfo , PythonEnvInfo | undefined > ;
43
+ private readonly workerPool : IWorkerPool < string , InterpreterInformation | undefined > ;
51
44
52
45
public constructor ( ) {
53
- this . workerPool = createWorkerPool < PythonEnvInfo , PythonEnvInfo | undefined > ( buildEnvironmentInfo ) ;
46
+ this . workerPool = createWorkerPool < string , InterpreterInformation | undefined > ( buildEnvironmentInfo ) ;
54
47
}
55
48
56
49
public async getEnvironmentInfo (
57
- environment : PythonEnvInfo ,
50
+ interpreterPath : string ,
58
51
priority ?: EnvironmentInfoServiceQueuePriority ,
59
- ) : Promise < PythonEnvInfo | undefined > {
60
- const interpreterPath = environment . executable . filename ;
52
+ ) : Promise < InterpreterInformation | undefined > {
61
53
const result = this . cache . get ( interpreterPath ) ;
62
54
if ( result !== undefined ) {
63
55
// Another call for this environment has already been made, return its result
64
56
return result . promise ;
65
57
}
66
- const deferred = createDeferred < PythonEnvInfo > ( ) ;
58
+ const deferred = createDeferred < InterpreterInformation > ( ) ;
67
59
this . cache . set ( interpreterPath , deferred ) ;
68
60
return ( priority === EnvironmentInfoServiceQueuePriority . High
69
- ? this . workerPool . addToQueue ( environment , QueuePosition . Front )
70
- : this . workerPool . addToQueue ( environment , QueuePosition . Back )
61
+ ? this . workerPool . addToQueue ( interpreterPath , QueuePosition . Front )
62
+ : this . workerPool . addToQueue ( interpreterPath , QueuePosition . Back )
71
63
) . then ( ( r ) => {
72
64
if ( r !== undefined ) {
73
65
deferred . resolve ( r ) ;
0 commit comments