X Tutup
Skip to content

Commit dff9e25

Browse files
committed
Closes python#19139: Changed usage of __VENV_NAME__ and added __VENV_PROMPT__.
1 parent 7c411a4 commit dff9e25

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

Doc/library/venv.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ creation according to their needs, the :class:`EnvBuilder` class.
187187
* ``__VENV_NAME__`` is replaced with the environment name (final path
188188
segment of environment directory).
189189

190+
* ``__VENV_PROMPT__`` is replaced with the prompt (the environment
191+
name surrounded by parentheses and with a following space)
192+
190193
* ``__VENV_BIN_NAME__`` is replaced with the name of the bin directory
191194
(either ``bin`` or ``Scripts``).
192195

Lib/venv/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ def replace_variables(self, text, context):
261261
being processed.
262262
"""
263263
text = text.replace('__VENV_DIR__', context.env_dir)
264-
text = text.replace('__VENV_NAME__', context.prompt)
264+
text = text.replace('__VENV_NAME__', context.env_name)
265+
text = text.replace('__VENV_PROMPT__', context.prompt)
265266
text = text.replace('__VENV_BIN_NAME__', context.bin_name)
266267
text = text.replace('__VENV_PYTHON__', context.env_exe)
267268
return text

Lib/venv/scripts/nt/Activate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $env:VIRTUAL_ENV="__VENV_DIR__"
3434
function global:_OLD_VIRTUAL_PROMPT {""}
3535
copy-item function:prompt function:_OLD_VIRTUAL_PROMPT
3636
function global:prompt {
37-
Write-Host -NoNewline -ForegroundColor Green '__VENV_NAME__'
37+
Write-Host -NoNewline -ForegroundColor Green '__VENV_PROMPT__'
3838
_OLD_VIRTUAL_PROMPT
3939
}
4040

Lib/venv/scripts/nt/activate.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if defined _OLD_VIRTUAL_PYTHONHOME (
1414
)
1515

1616
set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
17-
set "PROMPT=__VENV_NAME__%PROMPT%"
17+
set "PROMPT=__VENV_PROMPT__%PROMPT%"
1818

1919
if defined PYTHONHOME (
2020
set "_OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%"

Lib/venv/scripts/posix/activate

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fi
5454

5555
if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
5656
_OLD_VIRTUAL_PS1="$PS1"
57-
if [ "x__VENV_NAME__" != x ] ; then
58-
PS1="__VENV_NAME__$PS1"
57+
if [ "x__VENV_PROMPT__" != x ] ; then
58+
PS1="__VENV_PROMPT__$PS1"
5959
else
6060
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
6161
# special case for Aspen magic directories

Lib/venv/scripts/posix/activate.fish

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
5555
# with the original prompt function renamed, we can override with our own.
5656
function fish_prompt
5757
# Prompt override?
58-
if test -n "__VENV_NAME__"
59-
printf "%s%s%s" "__VENV_NAME__" (set_color normal) (_old_fish_prompt)
58+
if test -n "__VENV_PROMPT__"
59+
printf "%s%s%s" "__VENV_PROMPT__" (set_color normal) (_old_fish_prompt)
6060
return
6161
end
6262
# ...Otherwise, prepend env

0 commit comments

Comments
 (0)
X Tutup