uv icon indicating copy to clipboard operation
uv copied to clipboard

Support `venv --prompt`

Open methane opened this issue 1 year ago • 3 comments
trafficstars

Summary

  • Add --prompt option to venv
  • --prompt . (default) uses current directory name

Fixes #1445

Test Plan

This is my first Rust code and I don't know how to write tests yet. I just checked the behavior manually:

$ cargo build
$ mkdir t
$ cd t
$ ../target/debug/uv venv -p 3.11
$ rg -w t .venv/bin/acti*
.venv/bin/activate.csh
13:setenv VIRTUAL_ENV '/Users/inada-n/work/uv/t/.venv'
20:if ('t' != "") then
21:    setenv VIRTUAL_ENV_PROMPT 't'
23:    setenv VIRTUAL_ENV_PROMPT "$VIRTUAL_ENV:t:q"
38:    # in which case, $prompt is undefined and we wouldn't

.venv/bin/activate
48:VIRTUAL_ENV='/Users/inada-n/work/uv/t/.venv'
59:    VIRTUAL_ENV_PROMPT="t"

.venv/bin/activate.fish
61:set -gx VIRTUAL_ENV '/Users/inada-n/work/uv/t/.venv'
73:if test -n 't'
74:    set -gx VIRTUAL_ENV_PROMPT 't'

.venv/bin/activate.ps1
40:if ("t" -ne "") {
41:    $env:VIRTUAL_ENV_PROMPT = "t"

.venv/bin/activate.nu
6:# but then simply `deactivate` won't work because it is just an alias to hide
35:    let virtual_env = '/Users/inada-n/work/uv/t/.venv'
50:    let virtual_env_prompt = (if ('t' | is-empty) {
53:        't'

methane avatar Feb 17 '24 04:02 methane

Also congrats on your first Rust pull request ❤️

zanieb avatar Feb 17 '24 04:02 zanieb

When name is specified

~/work/uv/t (git)-[support-prompt] % ../target/debug/uv venv -p 3.11 hoge
Using Python 3.11.7 interpreter at /opt/homebrew/opt/[email protected]/bin/python3.11
Creating virtualenv at: hoge
~/work/uv/t (git)-[support-prompt] % grep prompt hoge/pyvenv.cfg
prompt = hoge

When name is omitted (.venv)

~/work/uv/t (git)-[support-prompt] % ../target/debug/uv venv -p 3.11
Using Python 3.11.7 interpreter at /opt/homebrew/opt/[email protected]/bin/python3.11
Creating virtualenv at: .venv
~/work/uv/t (git)-[support-prompt] % grep prompt .venv/pyvenv.cfg
prompt = t

methane avatar Feb 17 '24 07:02 methane

Nice. We now also support batch files. Could you add the same logic to the activation.bat file?

MichaReiser avatar Feb 18 '24 09:02 MichaReiser

@methane Thanks a lot for initiating this effort! I made some small tweaks at the end to accommodate Micha's recommendation:

  1. Expanding the CLI flag documentation
  2. Using a custom enum Prompt
  3. Updated the PR description to list down the workflow

Congrats on landing your first PR and welcome to Astral! 🥳

dhruvmanila avatar Feb 19 '24 19:02 dhruvmanila

Great job guys !

frague59 avatar Feb 21 '24 21:02 frague59