@@ -19,7 +19,11 @@ import {
19
19
import { PythonEnvsChangedEvent } from '../../watcher' ;
20
20
import { resolveBasicEnv } from './resolverUtils' ;
21
21
import { traceVerbose } from '../../../../logging' ;
22
- import { isExecutableOrEnvPath } from '../../../common/commonUtils' ;
22
+ import {
23
+ getEnvironmentDirFromPath ,
24
+ getInterpreterPathFromDir ,
25
+ isExecutableOrEnvPath ,
26
+ } from '../../../common/commonUtils' ;
23
27
24
28
/**
25
29
* Calls environment info service which runs `interpreterInfo.py` script on environments received
@@ -36,16 +40,9 @@ export class PythonEnvsResolver implements IResolvingLocator {
36
40
) { }
37
41
38
42
public async resolveEnv ( path : string ) : Promise < PythonEnvInfo | undefined > {
43
+ const [ executablePath , envPath ] = await getExecutablePathAndEnvPath ( path ) ;
44
+ path = executablePath . length ? executablePath : envPath ;
39
45
const kind = await identifyEnvironment ( path ) ;
40
- let envPath : string ;
41
- let executablePath : string ;
42
- if ( await isExecutableOrEnvPath ( path ) ) {
43
- executablePath = path ;
44
- envPath = '' ;
45
- } else {
46
- executablePath = '' ;
47
- envPath = path ;
48
- }
49
46
const environment = await resolveBasicEnv ( { kind, executablePath, envPath } ) ;
50
47
const info = await this . environmentInfoService . getEnvironmentInfo ( environment ) ;
51
48
if ( ! info ) {
@@ -160,3 +157,17 @@ function getResolvedEnv(interpreterInfo: InterpreterInformation, environment: Py
160
157
setEnvDisplayString ( resolvedEnv ) ;
161
158
return resolvedEnv ;
162
159
}
160
+
161
+ async function getExecutablePathAndEnvPath ( path : string ) {
162
+ let executablePath : string ;
163
+ let envPath : string ;
164
+ const isPathAnExecutable = await isExecutableOrEnvPath ( path ) ;
165
+ if ( isPathAnExecutable ) {
166
+ executablePath = path ;
167
+ envPath = getEnvironmentDirFromPath ( path ) ;
168
+ } else {
169
+ executablePath = ( await getInterpreterPathFromDir ( path ) ) ?? '' ;
170
+ envPath = path ;
171
+ }
172
+ return [ executablePath , envPath ] ;
173
+ }
0 commit comments