Skip to content

If type identifier for an environment is not registered, infer type from locator #23083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/client/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export type KnownEnvironmentTools =
| 'Venv'
| 'VirtualEnvWrapper'
| 'Pyenv'
| 'Hatch'
| 'Unknown';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/client/environmentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ function convertKind(kind: PythonEnvKind): EnvironmentTools | undefined {
return 'Pipenv';
case PythonEnvKind.Poetry:
return 'Poetry';
case PythonEnvKind.Hatch:
return 'Hatch';
case PythonEnvKind.VirtualEnvWrapper:
return 'VirtualEnvWrapper';
case PythonEnvKind.VirtualEnv:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ function getPrioritizedEnvironmentType(): EnvironmentType[] {
EnvironmentType.Poetry,
EnvironmentType.Pipenv,
EnvironmentType.VirtualEnvWrapper,
EnvironmentType.Hatch,
EnvironmentType.Venv,
EnvironmentType.VirtualEnv,
EnvironmentType.ActiveState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export namespace EnvGroups {
export const Pyenv = 'Pyenv';
export const Venv = 'Venv';
export const Poetry = 'Poetry';
export const Hatch = 'Hatch';
export const VirtualEnvWrapper = 'VirtualEnvWrapper';
export const ActiveState = 'ActiveState';
export const Recommended = Common.recommended;
Expand Down
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 { isIdentifierRegistered, 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 (!isIdentifierRegistered(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 isIdentifierRegistered(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
5 changes: 5 additions & 0 deletions src/client/pythonEnvironments/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export enum EnvironmentType {
Venv = 'Venv',
MicrosoftStore = 'MicrosoftStore',
Poetry = 'Poetry',
Hatch = 'Hatch',
VirtualEnvWrapper = 'VirtualEnvWrapper',
ActiveState = 'ActiveState',
Global = 'Global',
Expand All @@ -28,6 +29,7 @@ export enum EnvironmentType {
export const virtualEnvTypes = [
EnvironmentType.Poetry,
EnvironmentType.Pipenv,
EnvironmentType.Hatch,
EnvironmentType.Venv,
EnvironmentType.VirtualEnvWrapper,
EnvironmentType.Conda,
Expand Down Expand Up @@ -115,6 +117,9 @@ export function getEnvironmentTypeName(environmentType: EnvironmentType): string
case EnvironmentType.Poetry: {
return 'Poetry';
}
case EnvironmentType.Hatch: {
return 'Hatch';
}
case EnvironmentType.VirtualEnvWrapper: {
return 'virtualenvwrapper';
}
Expand Down
1 change: 1 addition & 0 deletions src/client/pythonEnvironments/legacyIOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const convertedKinds = new Map(
[PythonEnvKind.VirtualEnv]: EnvironmentType.VirtualEnv,
[PythonEnvKind.Pipenv]: EnvironmentType.Pipenv,
[PythonEnvKind.Poetry]: EnvironmentType.Poetry,
[PythonEnvKind.Hatch]: EnvironmentType.Hatch,
[PythonEnvKind.Venv]: EnvironmentType.Venv,
[PythonEnvKind.VirtualEnvWrapper]: EnvironmentType.VirtualEnvWrapper,
[PythonEnvKind.ActiveState]: EnvironmentType.ActiveState,
Expand Down