-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support venv --prompt
#1570
Support venv --prompt
#1570
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your pull request! I have some comments to start.
I'm not sure what the best way to test this is either, you can see our current venv
tests at https://github.com/astral-sh/uv/blob/main/crates/uv/tests/venv.rs — I'd look into adding a snapshot there.
Here's a resource about our snapshotting tool: https://insta.rs/docs/cli/
Also congrats on your first Rust pull request ❤️ |
9e046fd
to
d823d69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for creating this PR!
I was just playing around with venv
/ virtualenv
when I saw this PR. That helped me understand what the original behavior is which means you don't need to fiddle around with other tools ;)
There are a few changes required to be compatible with the --prompt
flag from other tools.
From the implementation side, I'm not exactly sure but you might want to play around with either using Option<&str>
or Option<String>
type for the prompt parameter in the gourgeist::create_bare_venv
function. This is because we need to get the prompt value from the current working directory if it's Some(".")
which could lead into ownership problems. Feel free to ping me if you face any, I'm happy to help :)
When name is specified
When name is omitted (.venv)
|
Nice. We now also support batch files. Could you add the same logic to the activation.bat file? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the default behavior that you proposed. With that in mind, this is the final set of review comments and then it should be good to go.
It's mainly a simplification of using Option
to avoid using is_empty
for every entry in pyvenv.cfg
. This is to keep the invariant that other entries are always going to be written to the file while prompt
is optional.
Thanks for your patience!
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
@methane Thanks a lot for initiating this effort! I made some small tweaks at the end to accommodate Micha's recommendation:
Congrats on landing your first PR and welcome to Astral! 🥳 |
Great job guys ! |
Summary
This PR adds the
--prompt
option tovenv
subcommand.The default behavior for
uv venv
is to create a virtual environment in the current directory with.venv
name. This is different fromvenv
/virtualenv
where a user always needs to provide the virtual environment path. This allows us to define our own behavior in the default scenario (uv venv
). We've decided to use the current directory's name in that case.Workflows:
uv venv
.venv
(default)uv venv project
project
project
uv venv --prompt .
.venv
uv venv --prompt foobar
.venv
foobar
uv venv project --prompt foobar
project
foobar
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: