Skip to content
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

Document what happens when venv is run using existing directory #124113

Open
piotr-kubiak opened this issue Sep 16, 2024 · 2 comments
Open

Document what happens when venv is run using existing directory #124113

piotr-kubiak opened this issue Sep 16, 2024 · 2 comments
Labels
docs Documentation in the Doc dir topic-venv Related to the venv module

Comments

@piotr-kubiak
Copy link

Documentation

Please consider specifying the behavior of venv module when the ENV_DIR already exists, and/or is not empty and/or contains an existing virtual environment. Currently the docs mentions only: “running this command creates the target directory”, and “creates” implies the command should be executed when ENV_DIR is not present [1].

However, I am able to run python -m venv .venv twice, and there is no error. There is no mention in the docs what happens when the directory is already there. Does venv skips creation of virtual environment? Does it try to create it anyways? What if ENV_DIR content is already a virtual environment? What if it is somewhat broken, does venv try to “fix” it?

[1] On the other hand, there are options --clear, --update, --update-deps, and those imply the ENV_DIR should be present. But it contradicts the previous assumption.

@piotr-kubiak piotr-kubiak added the docs Documentation in the Doc dir label Sep 16, 2024
@Eclips4 Eclips4 added the topic-venv Related to the venv module label Sep 16, 2024
@hugovk
Copy link
Member

hugovk commented Sep 16, 2024

Hello, the same paragraph in the docs ends with:

If an existing directory is specified, it will be re-used.

https://docs.python.org/3/library/venv.html#creating-virtual-environments

How does that sound? To me, re-use implies no error and no recreation.

@piotr-kubiak
Copy link
Author

How does that sound? To me, re-use implies no error and no recreation.

The problem is with what "re-use" means.
The more obvious cases:

  • How re-using empty directory works?
  • How re-using directory that already contains virtual environment works?

The more complicated ones:

  • How re-using directory that is not empty, but contains something other than virtual environment?
  • How re-using directory that contains virtual environment created with other python version works?
  • How re-using directory that contains virtual environment with missing "site-packages" directory works?

And the list goes.

@brettcannon brettcannon changed the title what happens when venv is run using existing directory Document what happens when venv is run using existing directory Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-venv Related to the venv module
Projects
None yet
Development

No branches or pull requests

3 participants