Skip to content

Commit 6b377d9

Browse files
Kartik Rajwesm
Kartik Raj
authored andcommitted
If type identifier for an environment is not registered, infer type from locator (microsoft/vscode-python#23083)
For microsoft/vscode-python#22810 ...so in case of Hatch, as an [explicit Hatch identifier is not available](microsoft/vscode-python#22779 (comment)), we infer an environment is Hatch if we get it from the Hatch locator: microsoft/vscode-python#22779.
1 parent f76905d commit 6b377d9

File tree

8 files changed

+27
-2
lines changed

8 files changed

+27
-2
lines changed

extensions/positron-python/src/client/api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export type KnownEnvironmentTools =
268268
| 'Venv'
269269
| 'VirtualEnvWrapper'
270270
| 'Pyenv'
271+
| 'Hatch'
271272
| 'Unknown';
272273

273274
/**

extensions/positron-python/src/client/environmentApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ function convertKind(kind: PythonEnvKind): EnvironmentTools | undefined {
338338
return 'Pipenv';
339339
case PythonEnvKind.Poetry:
340340
return 'Poetry';
341+
case PythonEnvKind.Hatch:
342+
return 'Hatch';
341343
case PythonEnvKind.VirtualEnvWrapper:
342344
return 'VirtualEnvWrapper';
343345
case PythonEnvKind.VirtualEnv:

extensions/positron-python/src/client/interpreter/configuration/environmentTypeComparer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ function getPrioritizedEnvironmentType(): EnvironmentType[] {
281281
EnvironmentType.Poetry,
282282
EnvironmentType.Pipenv,
283283
EnvironmentType.VirtualEnvWrapper,
284+
EnvironmentType.Hatch,
284285
EnvironmentType.Venv,
285286
EnvironmentType.VirtualEnv,
286287
EnvironmentType.ActiveState,

extensions/positron-python/src/client/interpreter/configuration/interpreterSelector/commands/setInterpreter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export namespace EnvGroups {
7474
export const Pyenv = 'Pyenv';
7575
export const Venv = 'Venv';
7676
export const Poetry = 'Poetry';
77+
export const Hatch = 'Hatch';
7778
export const VirtualEnvWrapper = 'VirtualEnvWrapper';
7879
export const ActiveState = 'ActiveState';
7980
export const Recommended = Common.recommended;

extensions/positron-python/src/client/pythonEnvironments/base/locators/composite/envsResolver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { cloneDeep } from 'lodash';
55
import { Event, EventEmitter } from 'vscode';
6-
import { identifyEnvironment } from '../../../common/environmentIdentifier';
6+
import { isIdentifierRegistered, identifyEnvironment } from '../../../common/environmentIdentifier';
77
import { IEnvironmentInfoService } from '../../info/environmentInfoService';
88
import { PythonEnvInfo, PythonEnvKind } from '../../info';
99
import { getEnvPath, setEnvDisplayString } from '../../info/env';
@@ -156,6 +156,10 @@ async function setKind(env: BasicEnvInfo, environmentKinds: Map<string, PythonEn
156156
const { path } = getEnvPath(env.executablePath, env.envPath);
157157
let kind = environmentKinds.get(path);
158158
if (!kind) {
159+
if (!isIdentifierRegistered(env.kind)) {
160+
// If identifier is not registered, skip setting env kind.
161+
return;
162+
}
159163
kind = await identifyEnvironment(path);
160164
environmentKinds.set(path, kind);
161165
}

extensions/positron-python/src/client/pythonEnvironments/common/environmentIdentifier.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import {
1717
import { isMicrosoftStoreEnvironment } from './environmentManagers/microsoftStoreEnv';
1818
import { isActiveStateEnvironment } from './environmentManagers/activestate';
1919

20+
const notImplemented = () => Promise.resolve(false);
21+
2022
function getIdentifiers(): Map<PythonEnvKind, (path: string) => Promise<boolean>> {
21-
const notImplemented = () => Promise.resolve(false);
2223
const defaultTrue = () => Promise.resolve(true);
2324
const identifier: Map<PythonEnvKind, (path: string) => Promise<boolean>> = new Map();
2425
Object.values(PythonEnvKind).forEach((k) => {
@@ -39,6 +40,15 @@ function getIdentifiers(): Map<PythonEnvKind, (path: string) => Promise<boolean>
3940
return identifier;
4041
}
4142

43+
export function isIdentifierRegistered(kind: PythonEnvKind): boolean {
44+
const identifiers = getIdentifiers();
45+
const identifier = identifiers.get(kind);
46+
if (identifier === notImplemented) {
47+
return false;
48+
}
49+
return true;
50+
}
51+
4252
/**
4353
* Returns environment type.
4454
* @param {string} path : Absolute path to the python interpreter binary or path to environment.

extensions/positron-python/src/client/pythonEnvironments/info/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export enum EnvironmentType {
1919
Venv = 'Venv',
2020
MicrosoftStore = 'MicrosoftStore',
2121
Poetry = 'Poetry',
22+
Hatch = 'Hatch',
2223
VirtualEnvWrapper = 'VirtualEnvWrapper',
2324
ActiveState = 'ActiveState',
2425
Global = 'Global',
@@ -28,6 +29,7 @@ export enum EnvironmentType {
2829
export const virtualEnvTypes = [
2930
EnvironmentType.Poetry,
3031
EnvironmentType.Pipenv,
32+
EnvironmentType.Hatch,
3133
EnvironmentType.Venv,
3234
EnvironmentType.VirtualEnvWrapper,
3335
EnvironmentType.Conda,
@@ -115,6 +117,9 @@ export function getEnvironmentTypeName(environmentType: EnvironmentType): string
115117
case EnvironmentType.Poetry: {
116118
return 'Poetry';
117119
}
120+
case EnvironmentType.Hatch: {
121+
return 'Hatch';
122+
}
118123
case EnvironmentType.VirtualEnvWrapper: {
119124
return 'virtualenvwrapper';
120125
}

extensions/positron-python/src/client/pythonEnvironments/legacyIOC.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const convertedKinds = new Map(
3838
[PythonEnvKind.VirtualEnv]: EnvironmentType.VirtualEnv,
3939
[PythonEnvKind.Pipenv]: EnvironmentType.Pipenv,
4040
[PythonEnvKind.Poetry]: EnvironmentType.Poetry,
41+
[PythonEnvKind.Hatch]: EnvironmentType.Hatch,
4142
[PythonEnvKind.Venv]: EnvironmentType.Venv,
4243
[PythonEnvKind.VirtualEnvWrapper]: EnvironmentType.VirtualEnvWrapper,
4344
[PythonEnvKind.ActiveState]: EnvironmentType.ActiveState,

0 commit comments

Comments
 (0)