uv icon indicating copy to clipboard operation
uv copied to clipboard

Request: Support uv venv --prompt

Open frague59 opened this issue 1 year ago • 5 comments

Hi, venv has an mainly undocumented feature :

$ python3.9 -m venv --prompt=<my prompt> ./venv

This command creates the virtuelenv, and append a prompt parameter ti the pyvenv.cfg file :

$ cat ./venv/pyvenv.cfg
home = /usr/local/bin
include-system-site-packages = false
version = 3.9.16
prompt = '<my prompt>'

This option is useful when you use several virtualenvs, as the active venv prompt can be displayed by the (linux) prompt, like liquidprompt or starship

Thanks !

frague59 avatar Feb 16 '24 07:02 frague59

I second this. I use --prompt a lot because I have lots of projects. It is easy to forget to deactivate when moving from one to the other. Just seeing (.venv) reinout@mycomputer:~/some/project/ $ doesn't help to spot the difference.

(Note that I suspect there are nicer ways to handle it and perhaps uv could make the prompt default to the directory name etc.... but the idea at the moment is probably to keep everything the same and just mimick pip/venv as good as possible :-) So supporting --prompt is good enough for now.)

reinout avatar Feb 16 '24 10:02 reinout

Please support --prompt . and make it as a default behavior. I use this alias for daily job.

alias mkvenv='python3 -m venv --prompt . .venv

methane avatar Feb 16 '24 11:02 methane

I believe we discussed this multiple times internally, not sure why it didn't happen.

zanieb avatar Feb 16 '24 18:02 zanieb

I'm also on a mac, which matches your observation. I'd guess we can expect the same behaviour on linux. So: windows by default does the "right" thing?

reinout avatar Feb 17 '24 01:02 reinout

I'm also on a mac, which matches your observation. I'd guess we can expect the same behaviour on linux. So: windows by default does the "right" thing?

@reinout I was just double checking Windows to add some more info for the PR which is waiting to be merged, when I realised that my comment was incorrect. In my case the venv prompt I was seeing was coming from ohmyposh.

If I run (for example) the old version of Powershell (where I don't have ohmyposh set up) the prompt defaults to the name you gave to the venv (which we know defaults to .venv)

Apologies for the confusion.

greywidget avatar Feb 17 '24 10:02 greywidget

If I read #1570 correctly, the upcoming behaviour is that uv venv even automatically sets the prompt to the name of the current directory (instead of .venv)? That's extra luxurious 👍 Then I won't even need --prompt.

reinout avatar Feb 19 '24 19:02 reinout

@reinout Yes, that's correct. All thanks to @methane for the idea and the PR :)

dhruvmanila avatar Feb 19 '24 19:02 dhruvmanila