]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154399: Fix venv activate.csh in a non-interactive shell (GH-154400)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 22 Jul 2026 04:05:10 +0000 (07:05 +0300)
committerGitHub <noreply@github.com>
Wed, 22 Jul 2026 04:05:10 +0000 (07:05 +0300)
activate.csh saved the prompt unconditionally, but the prompt variable
only exists in interactive shells, and csh fails on an undefined
variable.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Lib/venv/scripts/posix/activate.csh
Misc/NEWS.d/next/Library/2026-07-21-21-36-59.gh-issue-154399.VSa6oH.rst [new file with mode: 0644]

index 2a3fa835476ab9b44551831ab8b7ad43e86df64b..7226034df0f3941b6916dcc0f6d64ac72ed2f62a 100644 (file)
@@ -16,10 +16,12 @@ setenv PATH "$VIRTUAL_ENV/"__VENV_BIN_NAME__":$PATH"
 setenv VIRTUAL_ENV_PROMPT __VENV_PROMPT__
 
 
-set _OLD_VIRTUAL_PROMPT="$prompt"
+if ($?prompt) then
+    set _OLD_VIRTUAL_PROMPT="$prompt"
 
-if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
-    set prompt = "("__VENV_PROMPT__") $prompt:q"
+    if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
+        set prompt = "("__VENV_PROMPT__") $prompt:q"
+    endif
 endif
 
 alias pydoc python -m pydoc
diff --git a/Misc/NEWS.d/next/Library/2026-07-21-21-36-59.gh-issue-154399.VSa6oH.rst b/Misc/NEWS.d/next/Library/2026-07-21-21-36-59.gh-issue-154399.VSa6oH.rst
new file mode 100644 (file)
index 0000000..598dd26
--- /dev/null
@@ -0,0 +1,3 @@
+Fix :mod:`venv` activation in a non-interactive csh:
+``activate.csh`` no longer fails
+when the ``prompt`` variable is not set.