Skip to content

Commit

Permalink
If identifier is not registered, rely on locator for the kind
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Mar 16, 2024
1 parent 3b33eda commit ee57826
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { cloneDeep } from 'lodash';
import { Event, EventEmitter } from 'vscode';
import { identifyEnvironment } from '../../../common/environmentIdentifier';
import { hasIdentifierRegistered, identifyEnvironment } from '../../../common/environmentIdentifier';
import { IEnvironmentInfoService } from '../../info/environmentInfoService';
import { PythonEnvInfo, PythonEnvKind } from '../../info';
import { getEnvPath, setEnvDisplayString } from '../../info/env';
Expand Down Expand Up @@ -156,6 +156,10 @@ async function setKind(env: BasicEnvInfo, environmentKinds: Map<string, PythonEn
const { path } = getEnvPath(env.executablePath, env.envPath);
let kind = environmentKinds.get(path);
if (!kind) {
if (!hasIdentifierRegistered(env.kind)) {
// If identifier is not registered, skip setting env kind.
return;
}
kind = await identifyEnvironment(path);
environmentKinds.set(path, kind);
}
Expand Down
12 changes: 11 additions & 1 deletion src/client/pythonEnvironments/common/environmentIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import {
import { isMicrosoftStoreEnvironment } from './environmentManagers/microsoftStoreEnv';
import { isActiveStateEnvironment } from './environmentManagers/activestate';

const notImplemented = () => Promise.resolve(false);

function getIdentifiers(): Map<PythonEnvKind, (path: string) => Promise<boolean>> {
const notImplemented = () => Promise.resolve(false);
const defaultTrue = () => Promise.resolve(true);
const identifier: Map<PythonEnvKind, (path: string) => Promise<boolean>> = new Map();
Object.values(PythonEnvKind).forEach((k) => {
Expand All @@ -39,6 +40,15 @@ function getIdentifiers(): Map<PythonEnvKind, (path: string) => Promise<boolean>
return identifier;
}

export function hasIdentifierRegistered(kind: PythonEnvKind): boolean {
const identifiers = getIdentifiers();
const identifier = identifiers.get(kind);
if (identifier === notImplemented) {
return false;
}
return true;
}

/**
* Returns environment type.
* @param {string} path : Absolute path to the python interpreter binary or path to environment.
Expand Down

0 comments on commit ee57826

Please sign in to comment.