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

uv init needlessly tries to discover a venv #9072

Closed
rdaysky opened this issue Nov 12, 2024 · 2 comments · Fixed by #9075
Closed

uv init needlessly tries to discover a venv #9072

rdaysky opened this issue Nov 12, 2024 · 2 comments · Fixed by #9075
Labels
bug Something isn't working

Comments

@rdaysky
Copy link

rdaysky commented Nov 12, 2024

The existence of a directory named .venv in an ancestor of the current directory seems to influence the behavior of uv init. In particular, it will look for the version of Python installed in it and put it into requires-python. This is problematic because:

  1. By definition, uv init is going to create a new project which will define, in its own pyproject.toml, what it wants from the environment it’s going to run in. That some other thing that resides in a parent directory happened to configure its own venv in a particular way is irrelevant.
  2. The directory named .venv isn’t necessarily a fully-functional virtual environment. If it was created within a Docker container and became visible to the host because of a volume mount, the symlinks inside will likely appear to be broken and uv init will fail entirely. Or maybe the user has a ~/.venv directory that’s just a container for various venvs and is not a venv itself.
  3. There doesn’t seem to be a switch to disable this discovery.
  4. It’s undocumented.

Given that uv can install Python like any other package, is there any reason not to follow the same process as with any other package and put the latest version into requires-python, ignoring all .venv directories, at least for --app? (--libs in general require permissive versioning so there should be some heuristic about what to put into requires-python, but that’s a different question.)

@bluss
Copy link
Contributor

bluss commented Nov 12, 2024

This is maybe similar to issue #8092

@zanieb
Copy link
Member

zanieb commented Nov 13, 2024

I think this sounds like a bug, as-in, we should not read from virtual environments when finding an interpreter for uv init.

@zanieb zanieb added the bug Something isn't working label Nov 13, 2024
zanieb added a commit that referenced this issue Nov 13, 2024
…n version for new projects (#9075)

`uv init` shouldn't have been using `EnvironmentPreference::Any` for
discovery of a Python interpreter, it seems like an oversight that it
was reading from virtual environments. I changed it to
`EnvironmentPreference::OnlySystem` so we'll use the first Python on the
`PATH` instead. However, I think we actually do want to respect a
virtual environment's Python version if it's in the target project
directory already, so I've implemented that as well.

Closes #9072
Closes #8092
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants