From 9787d6ded397d0266c534853e0a4b9e8a39c3158 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 15 Mar 2024 15:50:02 -0700 Subject: [PATCH 1/2] Respect `VIRTUAL_ENV_PROMPT` when calculating `PS1` --- src/client/terminals/envCollectionActivation/service.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/terminals/envCollectionActivation/service.ts b/src/client/terminals/envCollectionActivation/service.ts index 447150c0f818..f06ebe91dd24 100644 --- a/src/client/terminals/envCollectionActivation/service.ts +++ b/src/client/terminals/envCollectionActivation/service.ts @@ -347,7 +347,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ const interpreter = await this.interpreterService.getActiveInterpreter(resource); const shouldSetPS1 = shouldPS1BeSet(interpreter?.type, env); if (shouldSetPS1) { - const prompt = getPromptForEnv(interpreter); + const prompt = getPromptForEnv(interpreter, env); if (prompt) { return prompt; } @@ -456,7 +456,7 @@ function shouldSkip(env: string) { ].includes(env); } -function getPromptForEnv(interpreter: PythonEnvironment | undefined) { +function getPromptForEnv(interpreter: PythonEnvironment | undefined, env: EnvironmentVariables) { if (!interpreter) { return undefined; } @@ -465,6 +465,9 @@ function getPromptForEnv(interpreter: PythonEnvironment | undefined) { // If conda base environment is selected, it can lead to "(base)" appearing twice if we return the env name. return undefined; } + if (interpreter.type === PythonEnvType.Virtual && env.VIRTUAL_ENV_PROMPT) { + return `(${env.VIRTUAL_ENV_PROMPT}) `; + } return `(${interpreter.envName}) `; } if (interpreter.envPath) { From 23cf3e3585194de7505bdcb3e9129ded3c80db5a Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 15 Mar 2024 15:53:54 -0700 Subject: [PATCH 2/2] Fix --- src/client/terminals/envCollectionActivation/service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/client/terminals/envCollectionActivation/service.ts b/src/client/terminals/envCollectionActivation/service.ts index f06ebe91dd24..b7ec224828da 100644 --- a/src/client/terminals/envCollectionActivation/service.ts +++ b/src/client/terminals/envCollectionActivation/service.ts @@ -338,6 +338,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ } private async getPS1(shell: string, resource: Resource, env: EnvironmentVariables) { + // PS1 returned by shell is not predictable: #22078 + // Hence calculate it ourselves where possible. Should no longer be needed once #22128 is available. const customShellType = identifyShellFromShellPath(shell); if (this.noPromptVariableShells.includes(customShellType)) { return env.PS1;