Search PATH when python can't be found with py#1711
Merged
MichaReiser merged 7 commits intomainfrom Feb 22, 2024
Merged
Conversation
0b1c7e7 to
2275997
Compare
17d8b2e to
e580f5a
Compare
MichaReiser
commented
Feb 20, 2024
| cache: &Cache, | ||
| ) -> Result<Option<Interpreter>, Error> { | ||
| #[allow(non_snake_case)] | ||
| let UV_TEST_PYTHON_PATH = env::var_os("UV_TEST_PYTHON_PATH"); |
Member
Author
There was a problem hiding this comment.
I intentionally removed the TEST early return. We want that as much code as possible in this function is run during tests.
e580f5a to
65418f8
Compare
MichaReiser
commented
Feb 20, 2024
MichaReiser
commented
Feb 20, 2024
200263d to
3bd2d59
Compare
Warchant
reviewed
Feb 21, 2024
konstin
approved these changes
Feb 21, 2024
| cache, | ||
| ), | ||
| // SAFETY: Guaranteed by the Ok(versions) guard | ||
| _ => unreachable!(), |
Member
There was a problem hiding this comment.
Can request be empty? I just realized then we could hit this path
Member
Author
There was a problem hiding this comment.
pub fn main() {
let versions = ""
.splitn(3, '.')
.map(str::parse::<u8>)
.collect::<Result<Vec<_>, _>>();
dbg!(versions);
}
gives me
[src/main.rs:8:9] versions = Err(
ParseIntError {
kind: Empty,
},
)
So we're good
| for name in possible_names.iter().flatten() { | ||
| if let Ok(paths) = which::which_in_global(&**name, Some(&path)) { | ||
| for path in paths { | ||
| if checked_installs.contains(&path) { |
Member
There was a problem hiding this comment.
When do we see a path multiple times?
Member
Author
There was a problem hiding this comment.
I copied that over from virtualenv but I'm not sure. Let's remove it for now.
6031209 to
8ef394b
Compare
8ef394b to
6cd76fd
Compare
6cd76fd to
55b0bd8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves uv's compatibility with PIP when discovering python installations.
PIP runs the following step
-pis a path, resolve that specific instancesys.executablematches the requested version (or if no version was requested, always use it)python{major}.{minor}.{patch},python{major}.{minor},python{major},pythonOur existing implementation already did some of that but not all. We now
python3.9python3.9.3for Windows and Unixpy)pyenvshims (that's a hack)I merged most of the implementation between windows and unix because they are the same in
venvtoo. The only real difference is that Windows must supportpy(PEP514) and shims are awkward.Fixes #1310
Fixes #1660
Fixes #1168
Test Plan
uv venvon Windows with no Python installed but the Windows shims activate fails with an error that Python wasn't found rather than invoking the shimuv venvwith a local pyenv environment activate selects that Python version (because it is the first in the path)python.exeon path and thepython.batshim, then the installation takes thepython.exe(avoid indirection) except if thepython.exedoesn't satisfy the requested version.uv venvpicks up the different python versions (including pyenv)