diff options
author | Jim Porter <826865+jimporter@users.noreply.github.com> | 2024-01-23 08:53:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-23 08:53:04 (GMT) |
commit | 8edc8029def8040ebe1caf75d815439156dd2124 (patch) | |
tree | 320f43aa9dde89fe0e673977003423bfe99d427b /Lib/venv | |
parent | b822b85ac11e73bbe4417bf03ee770ab116bb42d (diff) | |
download | cpython-8edc8029def8040ebe1caf75d815439156dd2124.zip cpython-8edc8029def8040ebe1caf75d815439156dd2124.tar.gz cpython-8edc8029def8040ebe1caf75d815439156dd2124.tar.bz2 |
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.
Diffstat (limited to 'Lib/venv')
-rw-r--r-- | Lib/venv/__init__.py | 3 | ||||
-rw-r--r-- | Lib/venv/scripts/common/activate | 2 | ||||
-rw-r--r-- | Lib/venv/scripts/nt/activate.bat | 2 | ||||
-rw-r--r-- | Lib/venv/scripts/posix/activate.csh | 2 | ||||
-rw-r--r-- | Lib/venv/scripts/posix/activate.fish | 2 |
5 files changed, 5 insertions, 6 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index f04ca8f..4856594 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -129,8 +129,7 @@ class EnvBuilder: context = types.SimpleNamespace() context.env_dir = env_dir context.env_name = os.path.split(env_dir)[1] - prompt = self.prompt if self.prompt is not None else context.env_name - context.prompt = '(%s) ' % prompt + context.prompt = self.prompt if self.prompt is not None else context.env_name create_if_needed(env_dir) executable = sys._base_executable if not executable: # see gh-96861 diff --git a/Lib/venv/scripts/common/activate b/Lib/venv/scripts/common/activate index a4e0609..cbd4873 100644 --- a/Lib/venv/scripts/common/activate +++ b/Lib/venv/scripts/common/activate @@ -66,7 +66,7 @@ fi if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then _OLD_VIRTUAL_PS1="${PS1:-}" - PS1="__VENV_PROMPT__${PS1:-}" + PS1="(__VENV_PROMPT__) ${PS1:-}" export PS1 fi diff --git a/Lib/venv/scripts/nt/activate.bat b/Lib/venv/scripts/nt/activate.bat index c1c3c82..2c98122 100644 --- a/Lib/venv/scripts/nt/activate.bat +++ b/Lib/venv/scripts/nt/activate.bat @@ -16,7 +16,7 @@ if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT% if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME% set _OLD_VIRTUAL_PROMPT=%PROMPT% -set PROMPT=__VENV_PROMPT__%PROMPT% +set PROMPT=(__VENV_PROMPT__) %PROMPT% if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME% set PYTHONHOME= diff --git a/Lib/venv/scripts/posix/activate.csh b/Lib/venv/scripts/posix/activate.csh index 9caf138..c707f19 100644 --- a/Lib/venv/scripts/posix/activate.csh +++ b/Lib/venv/scripts/posix/activate.csh @@ -19,7 +19,7 @@ setenv VIRTUAL_ENV_PROMPT "__VENV_PROMPT__" set _OLD_VIRTUAL_PROMPT="$prompt" if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then - set prompt = "__VENV_PROMPT__$prompt" + set prompt = "(__VENV_PROMPT__) $prompt" endif alias pydoc python -m pydoc diff --git a/Lib/venv/scripts/posix/activate.fish b/Lib/venv/scripts/posix/activate.fish index 565df23..25c4275 100644 --- a/Lib/venv/scripts/posix/activate.fish +++ b/Lib/venv/scripts/posix/activate.fish @@ -57,7 +57,7 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" set -l old_status $status # Output the venv prompt; color taken from the blue of the Python logo. - printf "%s%s%s" (set_color 4B8BBE) "__VENV_PROMPT__" (set_color normal) + printf "%s(%s)%s " (set_color 4B8BBE) "__VENV_PROMPT__" (set_color normal) # Restore the return status of the previous command. echo "exit $old_status" | . |