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.

Title: venv --prompt argument is ignored
Type: Stage: resolved
Components: Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: andream, vinay.sajip, xtreak
Priority: normal Keywords:

Created on 2020-02-07 09:08 by andream, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (7)
msg361548 - (view) Author: Andrea (andream) Date: 2020-02-07 09:08
In creating a new virtual environment, the help suggest a --prompt argument to specify a different name by the time the environment is active.

The argument is apparently ignored as the folder name always appears instead to whatever is specified in the prompt.
Checking at the config file content there nothing written inside, thought I'm not sure this should be the case.
msg361553 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-02-07 09:47
Can you please add a reproducer of the steps along with the operating system and python version? The --prompt was modified in 3.9 to accept "." so that the current folder name is used in issue38901.

# Use custom name as testing for the prompt

➜  cpython git:(master) ./python.exe -m venv foo-venv --prompt testing
➜  cpython git:(master) ✗ source foo-venv/bin/activate
(testing) ➜  cpython git:(master) ✗ deactivate

# Delete to recreate with prompt as . so that basename is used

➜  cpython git:(master) ✗ rm -rf foo-venv
➜  cpython git:(master) ./python.exe -m venv foo-venv --prompt .
➜  cpython git:(master) ✗ source foo-venv/bin/activate
(cpython) ➜  cpython git:(master) ✗
msg361766 - (view) Author: Andrea (andream) Date: 2020-02-11 00:46
Operative system is OS X 10.15.3 (19D76) Catalina
Python 3.7.4 installed via HomeBrew

If I do this python -m venv ciao --prompt NewOne by the time I activate the environment, the prompt looks like (ciao) andreamoro@MacBookAir:~/Python

Am I misunderstanding the behaviour of the prompt argument?

msg361781 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-02-11 05:21
> Am I misunderstanding the behaviour of the prompt argument?

You can see from Karthikeyan's post how it's supposed to work, and how it does work in his example. It may be that something else is overwriting the prompt in your environment - we can't tell without knowing what's in your .bashrc, .profile etc.
msg363054 - (view) Author: Andrea (andream) Date: 2020-03-01 10:58
Apologies for the delays in returning to you.

I have been using ZSH and Oh My ZSH on top. The prompt variable, which I have customised, looks like the following:

% $(virtualenv_info)$fg[magenta]%}%n%{$reset_color%}@%{$fg[yellow]%}$(box_name)%{$reset_color%}:%{$fg_bold[green]%}${PWD/#$HOME/~}%{$reset_color%}$(git_prompt_info)
%(?,,%{${fg_bold[white]}%}[%?]%{$reset_color%} )$ '

Judging from the documentation, I have the correct variable in place, so I'm not sure what's the problem as of now.

What should be the right value in a standard bash or zsh shell?

msg363055 - (view) Author: Andrea (andream) Date: 2020-03-01 11:48
Actually, the virtual_info appears to be a function within the theme, that does the following

function virtualenv_info {
    [ $VIRTUAL_ENV ] && echo '('%F{blue}`basename $VIRTUAL_ENV`%f') '

So, eventually the problems is in the function that retrieves the wrong variable. 

My question at this stage is, where is this "Prompt" variable set?

msg364018 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2020-03-12 12:53
> My question at this stage is, where is this "Prompt" variable set?

If you mean the VIRTUAL_ENV variable, it's set in one of the activation scripts for the venv. In any case, this doesn't look it it's a problem with venv code, more to do with your local environment. So I'll close this issue.
Date User Action Args
2022-04-11 14:59:26adminsetgithub: 83758
2020-03-12 12:53:17vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg364018

stage: resolved
2020-03-01 11:48:13andreamsetmessages: + msg363055
2020-03-01 10:58:01andreamsetmessages: + msg363054
2020-02-11 05:21:51vinay.sajipsetmessages: + msg361781
2020-02-11 00:46:32andreamsetmessages: + msg361766
2020-02-07 09:47:49xtreaksetnosy: + vinay.sajip, xtreak
messages: + msg361553
2020-02-07 09:08:45andreamcreate