https://github.com/python/cpython/commit/b0a90a949eef3976644aef8a82af31970e0c6cc4
commit: b0a90a949eef3976644aef8a82af31970e0c6cc4
branch: 3.14
author: Harjoth Khara <[email protected]>
committer: vsajip <[email protected]>
date: 2026-06-10T19:12:18+01:00
summary:
[3.14] gh-109940: Respect VIRTUAL_ENV_DISABLE_PROMPT in activate.bat
(GH-151215) (GH-151264)
(cherry picked from commit 7a014f44c393fda6d1c4bd135608ebcfc21d626c)
files:
A Misc/NEWS.d/next/Library/2026-06-10-00-00-02.gh-issue-109940.Cx1099.rst
M Lib/test/test_venv.py
M Lib/venv/scripts/nt/activate.bat
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index 7f2005597f7cfea..9937acd06a7a016 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -598,6 +598,51 @@ def test_unicode_in_batch_file(self):
)
self.assertEqual(out.strip(), '0')
+ @unittest.skipUnless(os.name == 'nt', 'only relevant on Windows')
+ def test_activate_bat_respects_disable_prompt(self):
+ rmtree(self.env_dir)
+ env_dir = os.path.join(os.path.realpath(self.env_dir), 'venv')
+ builder = venv.EnvBuilder(clear=True)
+ builder.create(env_dir)
+ activate = os.path.join(env_dir, self.bindir, 'activate.bat')
+ test_batch = os.path.join(self.env_dir, 'test_disable_prompt.bat')
+ with open(test_batch, "w") as f:
+ f.write('@echo off\n'
+ 'set "PROMPT=base$G"\n'
+ 'set "VIRTUAL_ENV_DISABLE_PROMPT=1"\n'
+ f'call "{activate}"\n'
+ 'echo ACTIVE_PROMPT:%PROMPT%\n'
+ 'echo VIRTUAL_ENV:%VIRTUAL_ENV%\n'
+ 'set "PROMPT=changed$G"\n'
+ 'call deactivate\n'
+ 'echo FINAL_PROMPT:%PROMPT%\n')
+ out, err = check_output([test_batch])
+ lines = out.splitlines()
+ self.assertEqual(lines[0], b'ACTIVE_PROMPT:base$G')
+ self.assertEndsWith(lines[1], os.fsencode(env_dir))
+ self.assertEqual(lines[2], b'FINAL_PROMPT:changed$G')
+
+ @unittest.skipUnless(os.name == 'nt', 'only relevant on Windows')
+ def test_activate_bat_prefixes_prompt_by_default(self):
+ rmtree(self.env_dir)
+ env_dir = os.path.join(os.path.realpath(self.env_dir), 'venv')
+ builder = venv.EnvBuilder(clear=True)
+ builder.create(env_dir)
+ activate = os.path.join(env_dir, self.bindir, 'activate.bat')
+ test_batch = os.path.join(self.env_dir, 'test_enable_prompt.bat')
+ with open(test_batch, "w") as f:
+ f.write('@echo off\n'
+ 'set "PROMPT=base) $G"\n'
+ 'set "VIRTUAL_ENV_DISABLE_PROMPT="\n'
+ f'call "{activate}"\n'
+ 'echo ACTIVE_PROMPT:%PROMPT%\n'
+ 'call deactivate\n'
+ 'echo FINAL_PROMPT:%PROMPT%\n')
+ out, err = check_output([test_batch])
+ lines = out.splitlines()
+ self.assertEqual(lines[0], b'ACTIVE_PROMPT:(venv) base) $G')
+ self.assertEqual(lines[1], b'FINAL_PROMPT:base) $G')
+
@unittest.skipUnless(os.name == 'nt' and can_symlink(),
'symlinks on Windows')
def test_failed_symlink(self):
diff --git a/Lib/venv/scripts/nt/activate.bat b/Lib/venv/scripts/nt/activate.bat
index 35533e4b551155a..5624a3284d42114 100644
--- a/Lib/venv/scripts/nt/activate.bat
+++ b/Lib/venv/scripts/nt/activate.bat
@@ -15,8 +15,8 @@ if not defined PROMPT set PROMPT=$P$G
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%"
+if not defined VIRTUAL_ENV_DISABLE_PROMPT set "_OLD_VIRTUAL_PROMPT=%PROMPT%"
+if not defined VIRTUAL_ENV_DISABLE_PROMPT set "PROMPT=(__VENV_PROMPT__)
%PROMPT%"
if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=
diff --git
a/Misc/NEWS.d/next/Library/2026-06-10-00-00-02.gh-issue-109940.Cx1099.rst
b/Misc/NEWS.d/next/Library/2026-06-10-00-00-02.gh-issue-109940.Cx1099.rst
new file mode 100644
index 000000000000000..130dc780b612864
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-06-10-00-00-02.gh-issue-109940.Cx1099.rst
@@ -0,0 +1,2 @@
+Fix Windows :mod:`venv` activation in ``cmd.exe`` to respect
+``VIRTUAL_ENV_DISABLE_PROMPT``.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]