This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Set a environment variable for venv prompt
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, ZackerySpytz, batisteo, brett.cannon, lys.nikolaou, mafredri, vinay.sajip, xtreak
Priority: normal Keywords: patch

Created on 2018-11-27 16:12 by batisteo, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 10745 closed batisteo, 2018-11-27 16:25
PR 21587 merged ZackerySpytz, 2020-07-21 22:23
PR 22324 open mafredri, 2020-09-19 16:39
Messages (10)
msg330533 - (view) Author: Baptiste Darthenay (batisteo) * Date: 2018-11-27 16:12
When creating a new virtual env with `python3 -m venv .venv --prompt env`, the prompt information is only used to set a temporary PS1.

This information is lost when using custom prompt, for example with ZSH.

I propose to set VIRTUAL_ENV_PROMPT=__VENV_PROMPT__ when activating the newly created venv, to be used by tools and other shells.
msg330542 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2018-11-27 17:55
The current prompt works fine for me on zsh -- what's the bug here?

zsh $ virtualenv venv --prompt '(wat)'
Using real prefix '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7'
New python executable in /private/tmp/venv/bin/python3.7
Also creating executable in /private/tmp/venv/bin/python
Installing setuptools, pip, wheel...done.
zsh $ . venv/bin/activate
(wat)zsh $
msg330548 - (view) Author: Baptiste Darthenay (batisteo) * Date: 2018-11-27 18:49
How the venv prompt name would be displayed in a project like Powerline?

Or in VS Code? https://i.ibb.co/JHYrnk2/Screenshot-from-2018-11-27-19-41-47.png

Or in my custom prompt? https://gist.github.com/batisteo/c5c9bd87a344cdbfb7a6401648c118a2#file-batisteo-zsh-theme-L194
msg333043 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-01-05 05:42
issue34439 seems like a similar proposal. I am adding @vinay.sajip. Since this seems like a new feature I have removed 3.7 from the version list.
msg342860 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2019-05-19 14:28
Is anybody still working on this?
msg343325 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-05-23 20:49
@lys.nikolaou it looks like there was an initial PR, but it only updated things for Bash and not for all the other shells that we support for virtual environments.
msg343327 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2019-05-23 20:55
@brettcannon, yeah I saw that, but there hasn't been any progress since November. I'm still interested in this though. What would the correct workflow be? Pushing commits to the same PR or opening a new one with a co-author?
msg343328 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2019-05-23 21:00
You can open a new PR with co-author or basing off of their fork if it's still around.
msg374481 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-07-28 08:42
New changeset c82dda1e08c4b74ca24f88d6a549d93108c319cf by Zackery Spytz in branch 'master':
bpo-35328: Set VIRTUAL_ENV_PROMPT at venv activation (GH-21587)
https://github.com/python/cpython/commit/c82dda1e08c4b74ca24f88d6a549d93108c319cf
msg377175 - (view) Author: Mathias Fredriksson (mafredri) * Date: 2020-09-19 15:55
I believe GH-21587 does not fully address this issue because VIRTUAL_ENV_PROMPT is being conditionally set only if VIRTUAL_ENV_DISABLE_PROMPT is unset. Shell prompts must set VIRTUAL_ENV_DISABLE_PROMPT to non-empty to prevent venv from hijacking PS1. I'm one of the maintainers of the Pure prompt for zsh, and it would be great if VIRTUAL_ENV_PROMPT could always be set, just as VIRTUAL_ENV is too.
History
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79509
2020-09-21 18:58:02brett.cannonsetstatus: closed -> open
resolution: fixed ->
versions: + Python 3.10, - Python 3.9
2020-09-19 16:39:58mafredrisetpull_requests: + pull_request21368
2020-09-19 15:55:21mafredrisetnosy: + mafredri
messages: + msg377175
2020-09-09 08:02:46vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-07-28 08:42:04vinay.sajipsetmessages: + msg374481
2020-07-21 22:23:30ZackerySpytzsetnosy: + ZackerySpytz
pull_requests: + pull_request20727
2019-10-31 14:19:46vinay.sajipsetversions: + Python 3.9, - Python 3.8
2019-05-23 21:00:26brett.cannonsetmessages: + msg343328
2019-05-23 20:55:25lys.nikolaousetmessages: + msg343327
2019-05-23 20:49:07brett.cannonsetnosy: + brett.cannon
messages: + msg343325
2019-05-19 14:28:21lys.nikolaousetmessages: + msg342860
2019-05-19 14:26:29lys.nikolaousetnosy: + lys.nikolaou
2019-05-19 14:25:41xtreaklinkissue36966 superseder
2019-01-05 05:42:56xtreaksetversions: - Python 3.7
nosy: + vinay.sajip, xtreak

messages: + msg333043

components: + Library (Lib)
type: enhancement
2018-11-27 18:49:37batisteosetmessages: + msg330548
2018-11-27 17:55:11Anthony Sottilesetnosy: + Anthony Sottile
messages: + msg330542
2018-11-27 16:25:05batisteosetkeywords: + patch
stage: patch review
pull_requests: + pull_request9992
2018-11-27 16:12:29batisteocreate