From 64bbc1500a1e15d01e2ee59a18be73de7b981b77 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:44:40 -0700 Subject: [PATCH 1/2] support pipenv path setting --- src/features/settings/settingHelpers.ts | 76 ++++++++++++++++++++++++- src/managers/pipenv/pipenvUtils.ts | 11 +++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/features/settings/settingHelpers.ts b/src/features/settings/settingHelpers.ts index f8692f89..bad55368 100644 --- a/src/features/settings/settingHelpers.ts +++ b/src/features/settings/settingHelpers.ts @@ -10,7 +10,7 @@ import { import { PythonProject } from '../../api'; import { DEFAULT_ENV_MANAGER_ID, DEFAULT_PACKAGE_MANAGER_ID } from '../../common/constants'; import { traceError, traceInfo, traceWarn } from '../../common/logging'; -import { getWorkspaceFile, getWorkspaceFolders } from '../../common/workspace.apis'; +import { getConfiguration, getWorkspaceFile, getWorkspaceFolders } from '../../common/workspace.apis'; import { PythonProjectManager, PythonProjectSettings } from '../../internal.api'; function getSettings( @@ -393,3 +393,77 @@ export async function removePythonProjectSetting(edits: EditProjectSettings[]): }); await Promise.all(promises); } + +/** + * Gets user-configured setting for window-scoped settings. + * Priority order: globalRemoteValue > globalLocalValue > globalValue + * @param section - The configuration section (e.g., 'python-envs') + * @param key - The configuration key (e.g., 'terminal.autoActivationType') + * @returns The user-configured value or undefined if not set by user + */ +export function getSettingWindowScope(section: string, key: string): T | undefined { + const config = getConfiguration(section); + const inspect = config.inspect(key); + if (!inspect) { + return undefined; + } + + const inspectRecord = inspect as Record; + if ('globalRemoteValue' in inspect && inspectRecord.globalRemoteValue !== undefined) { + return inspectRecord.globalRemoteValue as T; + } + if ('globalLocalValue' in inspect && inspectRecord.globalLocalValue !== undefined) { + return inspectRecord.globalLocalValue as T; + } + if (inspect.globalValue !== undefined) { + return inspect.globalValue; + } + return undefined; +} + +/** + * Gets user-configured setting for workspace-scoped settings. + * Priority order: workspaceFolderValue > workspaceValue > globalValue + * @param section - The configuration section (e.g., 'python') + * @param key - The configuration key (e.g., 'pipenvPath') + * @param scope - Optional URI scope for workspace folder-specific settings + * @returns The user-configured value or undefined if not set by user + */ +export function getSettingWorkspaceScope(section: string, key: string, scope?: Uri): T | undefined { + const config = getConfiguration(section, scope); + const inspect = config.inspect(key); + if (!inspect) { + return undefined; + } + + if (inspect.workspaceFolderValue !== undefined) { + return inspect.workspaceFolderValue; + } + if (inspect.workspaceValue !== undefined) { + return inspect.workspaceValue; + } + if (inspect.globalValue !== undefined) { + return inspect.globalValue; + } + return undefined; +} + +/** + * Gets user-configured setting for user-scoped settings. + * Only checks globalValue (ignores defaultValue). + * @param section - The configuration section (e.g., 'python') + * @param key - The configuration key (e.g., 'pipenvPath') + * @returns The user-configured value or undefined if not set by user + */ +export function getSettingUserScope(section: string, key: string): T | undefined { + const config = getConfiguration(section); + const inspect = config.inspect(key); + if (!inspect) { + return undefined; + } + + if (inspect.globalValue !== undefined) { + return inspect.globalValue; + } + return undefined; +} diff --git a/src/managers/pipenv/pipenvUtils.ts b/src/managers/pipenv/pipenvUtils.ts index ac3ef828..3c1a19e4 100644 --- a/src/managers/pipenv/pipenvUtils.ts +++ b/src/managers/pipenv/pipenvUtils.ts @@ -13,6 +13,7 @@ import { import { ENVS_EXTENSION_ID } from '../../common/constants'; import { traceError, traceInfo } from '../../common/logging'; import { getWorkspacePersistentState } from '../../common/persistentState'; +import { getSettingWorkspaceScope } from '../../features/settings/settingHelpers'; import { isNativeEnvInfo, NativeEnvInfo, @@ -46,6 +47,12 @@ export async function clearPipenvCache(): Promise { pipenvPath = undefined; } +function getPipenvPathFromSettings(): Uri[] { + // python.pipenvPath is a workspace-scoped setting + const pipenvPath = getSettingWorkspaceScope('python', 'pipenvPath'); + return pipenvPath ? [Uri.file(pipenvPath)] : []; +} + export async function getPipenv(native?: NativePythonFinder): Promise { if (pipenvPath) { return pipenvPath; @@ -140,7 +147,9 @@ export async function refreshPipenv( manager: EnvironmentManager, ): Promise { traceInfo('Refreshing pipenv environments'); - const data = await nativeFinder.refresh(hardRefresh); + + const searchUris = getPipenvPathFromSettings(); + const data = await nativeFinder.refresh(hardRefresh, searchUris.length > 0 ? searchUris : undefined); let pipenv = await getPipenv(); From 086f319d7d58cbce6bd91235a5730d66efdf8e1a Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Tue, 7 Oct 2025 21:16:30 -0700 Subject: [PATCH 2/2] . --- src/managers/pipenv/pipenvUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/managers/pipenv/pipenvUtils.ts b/src/managers/pipenv/pipenvUtils.ts index 3c1a19e4..f7045da7 100644 --- a/src/managers/pipenv/pipenvUtils.ts +++ b/src/managers/pipenv/pipenvUtils.ts @@ -48,7 +48,6 @@ export async function clearPipenvCache(): Promise { } function getPipenvPathFromSettings(): Uri[] { - // python.pipenvPath is a workspace-scoped setting const pipenvPath = getSettingWorkspaceScope('python', 'pipenvPath'); return pipenvPath ? [Uri.file(pipenvPath)] : []; }