gh-89427: Provide the original prompt value for VIRTUAL_ENV_PROMPT (G… · python/cpython@8edc802 · GitHub
Skip to content

Commit 8edc802

Browse files
authored
gh-89427: Provide the original prompt value for VIRTUAL_ENV_PROMPT (GH-106726)
This improves the implementation in gh-106643. Previously, venv passed "(<prompt>) " to the activation scripts, but we want to provide the original value so that users can inspect it in the $VIRTUAL_ENV_PROMPT env var. Note: Lib/venv/scripts/common/Activate.ps1 surrounded the prompt value with parens a second time, so no change was necessary in that file.
1 parent b822b85 commit 8edc802

6 files changed

Lines changed: 9 additions & 10 deletions

File tree

Lib/test/test_venv.py

Lines changed: 4 additions & 4 deletions

Lib/venv/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ def create_if_needed(d):
129129
context = types.SimpleNamespace()
130130
context.env_dir = env_dir
131131
context.env_name = os.path.split(env_dir)[1]
132-
prompt = self.prompt if self.prompt is not None else context.env_name
133-
context.prompt = '(%s) ' % prompt
132+
context.prompt = self.prompt if self.prompt is not None else context.env_name
134133
create_if_needed(env_dir)
135134
executable = sys._base_executable
136135
if not executable: # see gh-96861

Lib/venv/scripts/common/activate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fi
6666

6767
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
6868
_OLD_VIRTUAL_PS1="${PS1:-}"
69-
PS1="__VENV_PROMPT__${PS1:-}"
69+
PS1="(__VENV_PROMPT__) ${PS1:-}"
7070
export PS1
7171
fi
7272

Lib/venv/scripts/nt/activate.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
1616
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%
1717

1818
set _OLD_VIRTUAL_PROMPT=%PROMPT%
19-
set PROMPT=__VENV_PROMPT__%PROMPT%
19+
set PROMPT=(__VENV_PROMPT__) %PROMPT%
2020

2121
if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
2222
set PYTHONHOME=

Lib/venv/scripts/posix/activate.csh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ setenv VIRTUAL_ENV_PROMPT "__VENV_PROMPT__"
1919
set _OLD_VIRTUAL_PROMPT="$prompt"
2020

2121
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
22-
set prompt = "__VENV_PROMPT__$prompt"
22+
set prompt = "(__VENV_PROMPT__) $prompt"
2323
endif
2424

2525
alias pydoc python -m pydoc

Lib/venv/scripts/posix/activate.fish

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)