From 9f56b4854f11e9691bee2f87759b9370fa6bb79b Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 16 Sep 2020 13:28:42 -0600 Subject: [PATCH] Use a map for converting the env kinds. --- src/client/pythonEnvironments/legacyIOC.ts | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/client/pythonEnvironments/legacyIOC.ts b/src/client/pythonEnvironments/legacyIOC.ts index d306f20d78174..24cf4e357ece5 100644 --- a/src/client/pythonEnvironments/legacyIOC.ts +++ b/src/client/pythonEnvironments/legacyIOC.ts @@ -58,6 +58,18 @@ import { WorkspaceVirtualEnvWatcherService } from './discovery/locators/services import { EnvironmentType, PythonEnvironment } from './info'; import { EnvironmentInfoService, IEnvironmentInfoService } from './info/environmentInfoService'; +const convertedKinds = new Map(Object.entries({ + [PythonEnvKind.System]: EnvironmentType.System, + [PythonEnvKind.MacDefault]: EnvironmentType.System, + [PythonEnvKind.WindowsStore]: EnvironmentType.WindowsStore, + [PythonEnvKind.Pyenv]: EnvironmentType.Pyenv, + [PythonEnvKind.Conda]: EnvironmentType.Conda, + [PythonEnvKind.CondaBase]: EnvironmentType.Conda, + [PythonEnvKind.VirtualEnv]: EnvironmentType.VirtualEnv, + [PythonEnvKind.Pipenv]: EnvironmentType.Pipenv, + [PythonEnvKind.Venv]: EnvironmentType.Venv, +})); + function convertEnvInfo(info: PythonEnvInfo): PythonEnvironment { const { name, @@ -79,29 +91,17 @@ function convertEnvInfo(info: PythonEnvInfo): PythonEnvironment { architecture: arch, }; - if (kind === PythonEnvKind.System) { - env.envType = EnvironmentType.System; - } else if (kind === PythonEnvKind.MacDefault) { - env.envType = EnvironmentType.System; - } else if (kind === PythonEnvKind.WindowsStore) { - env.envType = EnvironmentType.WindowsStore; - } else if (kind === PythonEnvKind.Pyenv) { - env.envType = EnvironmentType.Pyenv; - } else if (kind === PythonEnvKind.Conda) { - env.envType = EnvironmentType.Conda; - } else if (kind === PythonEnvKind.CondaBase) { - env.envType = EnvironmentType.Conda; - } else if (kind === PythonEnvKind.VirtualEnv) { - env.envType = EnvironmentType.VirtualEnv; - } else if (kind === PythonEnvKind.Pipenv) { - env.envType = EnvironmentType.Pipenv; - if (searchLocation !== undefined) { + const envType = convertedKinds.get(kind); + if (envType !== undefined) { + env.envType = envType; + } + // Otherwise it stays Unknown. + + if (searchLocation !== undefined) { + if (kind === PythonEnvKind.Pipenv) { env.pipEnvWorkspaceFolder = searchLocation.fsPath; } - } else if (kind === PythonEnvKind.Venv) { - env.envType = EnvironmentType.Venv; } - // Otherwise it stays Unknown. if (version !== undefined) { const { release, sysVersion } = version;