Skip to content

Commit 9f56b48

Browse files
Use a map for converting the env kinds.
1 parent 9f65238 commit 9f56b48

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/client/pythonEnvironments/legacyIOC.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ import { WorkspaceVirtualEnvWatcherService } from './discovery/locators/services
5858
import { EnvironmentType, PythonEnvironment } from './info';
5959
import { EnvironmentInfoService, IEnvironmentInfoService } from './info/environmentInfoService';
6060

61+
const convertedKinds = new Map(Object.entries({
62+
[PythonEnvKind.System]: EnvironmentType.System,
63+
[PythonEnvKind.MacDefault]: EnvironmentType.System,
64+
[PythonEnvKind.WindowsStore]: EnvironmentType.WindowsStore,
65+
[PythonEnvKind.Pyenv]: EnvironmentType.Pyenv,
66+
[PythonEnvKind.Conda]: EnvironmentType.Conda,
67+
[PythonEnvKind.CondaBase]: EnvironmentType.Conda,
68+
[PythonEnvKind.VirtualEnv]: EnvironmentType.VirtualEnv,
69+
[PythonEnvKind.Pipenv]: EnvironmentType.Pipenv,
70+
[PythonEnvKind.Venv]: EnvironmentType.Venv,
71+
}));
72+
6173
function convertEnvInfo(info: PythonEnvInfo): PythonEnvironment {
6274
const {
6375
name,
@@ -79,29 +91,17 @@ function convertEnvInfo(info: PythonEnvInfo): PythonEnvironment {
7991
architecture: arch,
8092
};
8193

82-
if (kind === PythonEnvKind.System) {
83-
env.envType = EnvironmentType.System;
84-
} else if (kind === PythonEnvKind.MacDefault) {
85-
env.envType = EnvironmentType.System;
86-
} else if (kind === PythonEnvKind.WindowsStore) {
87-
env.envType = EnvironmentType.WindowsStore;
88-
} else if (kind === PythonEnvKind.Pyenv) {
89-
env.envType = EnvironmentType.Pyenv;
90-
} else if (kind === PythonEnvKind.Conda) {
91-
env.envType = EnvironmentType.Conda;
92-
} else if (kind === PythonEnvKind.CondaBase) {
93-
env.envType = EnvironmentType.Conda;
94-
} else if (kind === PythonEnvKind.VirtualEnv) {
95-
env.envType = EnvironmentType.VirtualEnv;
96-
} else if (kind === PythonEnvKind.Pipenv) {
97-
env.envType = EnvironmentType.Pipenv;
98-
if (searchLocation !== undefined) {
94+
const envType = convertedKinds.get(kind);
95+
if (envType !== undefined) {
96+
env.envType = envType;
97+
}
98+
// Otherwise it stays Unknown.
99+
100+
if (searchLocation !== undefined) {
101+
if (kind === PythonEnvKind.Pipenv) {
99102
env.pipEnvWorkspaceFolder = searchLocation.fsPath;
100103
}
101-
} else if (kind === PythonEnvKind.Venv) {
102-
env.envType = EnvironmentType.Venv;
103104
}
104-
// Otherwise it stays Unknown.
105105

106106
if (version !== undefined) {
107107
const { release, sysVersion } = version;

0 commit comments

Comments
 (0)