From 05e9a5bf5f7bfa12248673666bed965d5a401db0 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Thu, 3 Oct 2024 10:32:18 -0700 Subject: [PATCH] Avoid prefixing with home when unnecessary (#24232) Fixes https://github.com/microsoft/vscode-python/issues/24133 Co-authored-by: Don Jayamanne --- .../base/locators/common/nativePythonFinder.ts | 5 ++++- .../base/locators/lowLevel/customVirtualEnvLocator.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts index a05fcb8b4de4..55c5ed9f83a3 100644 --- a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts +++ b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts @@ -422,7 +422,10 @@ function getCustomVirtualEnvDirs(): string[] { const venvFolders = getPythonSettingAndUntildify(VENVFOLDERS_SETTING_KEY) ?? []; const homeDir = getUserHomeDir(); if (homeDir) { - venvFolders.map((item) => path.join(homeDir, item)).forEach((d) => venvDirs.push(d)); + venvFolders + .map((item) => (item.startsWith(homeDir) ? item : path.join(homeDir, item))) + .forEach((d) => venvDirs.push(d)); + venvFolders.forEach((item) => venvDirs.push(untildify(item))); } return Array.from(new Set(venvDirs)); } diff --git a/src/client/pythonEnvironments/base/locators/lowLevel/customVirtualEnvLocator.ts b/src/client/pythonEnvironments/base/locators/lowLevel/customVirtualEnvLocator.ts index 4c6a05af4acc..6aa83bbc376b 100644 --- a/src/client/pythonEnvironments/base/locators/lowLevel/customVirtualEnvLocator.ts +++ b/src/client/pythonEnvironments/base/locators/lowLevel/customVirtualEnvLocator.ts @@ -41,7 +41,10 @@ async function getCustomVirtualEnvDirs(): Promise { const venvFolders = getPythonSetting(VENVFOLDERS_SETTING_KEY) ?? []; const homeDir = getUserHomeDir(); if (homeDir && (await pathExists(homeDir))) { - venvFolders.map((item) => path.join(homeDir, item)).forEach((d) => venvDirs.push(d)); + venvFolders + .map((item) => (item.startsWith(homeDir) ? item : path.join(homeDir, item))) + .forEach((d) => venvDirs.push(d)); + venvFolders.forEach((item) => venvDirs.push(untildify(item))); } return asyncFilter(uniq(venvDirs), pathExists); }