Skip to content

Commit

Permalink
Respect VIRTUAL_ENV_DISABLE_PROMPT when activating virtual envs (mi…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj authored and eleanorjboyd committed Oct 2, 2023
1 parent 8d4e30d commit 6d82e6d
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { EnvironmentVariables } from '../../common/variables/types';
import { TerminalShellType } from '../../common/terminal/types';
import { OSType } from '../../common/utils/platform';
import { normCase } from '../../common/platform/fs-paths';
import { PythonEnvType } from '../../pythonEnvironments/base/info';

@injectable()
export class TerminalEnvVarCollectionService implements IExtensionActivationService, ITerminalEnvVarCollectionService {
Expand Down Expand Up @@ -264,8 +265,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
if (this.platform.osType !== OSType.Windows) {
// These shells are expected to set PS1 variable for terminal prompt for virtual/conda environments.
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
const shouldPS1BeSet = interpreter?.type !== undefined;
if (shouldPS1BeSet && !env.PS1) {
const shouldSetPS1 = shouldPS1BeSet(interpreter?.type, env);
if (shouldSetPS1 && !env.PS1) {
// PS1 should be set but no PS1 was set.
return;
}
Expand All @@ -291,8 +292,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
if (this.platform.osType !== OSType.Windows) {
// These shells are expected to set PS1 variable for terminal prompt for virtual/conda environments.
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
const shouldPS1BeSet = interpreter?.type !== undefined;
if (shouldPS1BeSet && !env.PS1) {
const shouldSetPS1 = shouldPS1BeSet(interpreter?.type, env);
if (shouldSetPS1 && !env.PS1) {
// PS1 should be set but no PS1 was set.
return getPromptForEnv(interpreter);
}
Expand Down Expand Up @@ -367,6 +368,15 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
}
}

function shouldPS1BeSet(type: PythonEnvType | undefined, env: EnvironmentVariables): boolean {
if (type === PythonEnvType.Virtual) {
const promptDisabledVar = env.VIRTUAL_ENV_DISABLE_PROMPT;
const isPromptDisabled = promptDisabledVar && promptDisabledVar !== undefined;
return !isPromptDisabled;
}
return type !== undefined;
}

function shouldSkip(env: string) {
return ['_', 'SHLVL'].includes(env);
}
Expand Down

0 comments on commit 6d82e6d

Please sign in to comment.