Skip to content

Commit ee4daca

Browse files
author
Kartik Raj
committed
Handle resolving environment path
1 parent e49371e commit ee4daca

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/client/pythonEnvironments/base/locators/composite/envsResolver.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import {
1919
import { PythonEnvsChangedEvent } from '../../watcher';
2020
import { resolveBasicEnv } from './resolverUtils';
2121
import { traceVerbose } from '../../../../logging';
22-
import { isExecutableOrEnvPath } from '../../../common/commonUtils';
22+
import {
23+
getEnvironmentDirFromPath,
24+
getInterpreterPathFromDir,
25+
isExecutableOrEnvPath,
26+
} from '../../../common/commonUtils';
2327

2428
/**
2529
* Calls environment info service which runs `interpreterInfo.py` script on environments received
@@ -36,16 +40,9 @@ export class PythonEnvsResolver implements IResolvingLocator {
3640
) {}
3741

3842
public async resolveEnv(path: string): Promise<PythonEnvInfo | undefined> {
43+
const [executablePath, envPath] = await getExecutablePathAndEnvPath(path);
44+
path = executablePath.length ? executablePath : envPath;
3945
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-
}
4946
const environment = await resolveBasicEnv({ kind, executablePath, envPath });
5047
const info = await this.environmentInfoService.getEnvironmentInfo(environment);
5148
if (!info) {
@@ -160,3 +157,17 @@ function getResolvedEnv(interpreterInfo: InterpreterInformation, environment: Py
160157
setEnvDisplayString(resolvedEnv);
161158
return resolvedEnv;
162159
}
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+
}

src/client/pythonEnvironments/common/environmentIdentifier.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ function getIdentifiers(): Map<PythonEnvKind, (path: string) => Promise<boolean>
3838

3939
/**
4040
* Returns environment type.
41-
* @param {string} interpreterPath : Absolute path to the python interpreter binary.
41+
* @param {string} path : Absolute path to the python interpreter binary or path to environment.
4242
* @returns {PythonEnvKind}
4343
*/
44-
export async function identifyEnvironment(interpreterPath: string): Promise<PythonEnvKind> {
44+
export async function identifyEnvironment(path: string): Promise<PythonEnvKind> {
4545
const identifiers = getIdentifiers();
4646
const prioritizedEnvTypes = getPrioritizedEnvKinds();
4747
for (const e of prioritizedEnvTypes) {
4848
const identifier = identifiers.get(e);
49-
if (identifier && (await identifier(interpreterPath))) {
49+
if (identifier && (await identifier(path))) {
5050
return e;
5151
}
5252
}

0 commit comments

Comments
 (0)