From 92c5b0ed4f4f73c169fcfbceb2bb82dee650c383 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 4 Oct 2024 01:29:22 +1000 Subject: [PATCH] Avoid prefixing with home when unnecessary (#24230) Fixes https://github.com/microsoft/vscode-python/issues/24133 --- .../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); }