Avoid canonicalizing user-provided interpreters (#2072)

## Summary

We shouldn't be resolving symlinks on the provided interpreter;
otherwise we break `pyenv`, since running `cargo run pip install mypy
--python .venv/bin/python` will immediately resolve to (e.g.)
`/Users/crmarsh/.pyenv/versions/3.10.2/bin/python3.10`, and pyenv relies
on the path to do its lookups.

Instead, the canonicalizing happens when we query the interpreter
metadata.

Closes https://github.com/astral-sh/uv/issues/2068.

## Test Plan

Ran `cargo run pip install mypy --python .venv/bin/python -v -n` with a
virtualenv created using a pyenv Python; verified that Mypy was
installed into the virtual environment, rather than into the global
environment.
This commit is contained in:
Charlie Marsh 2024-02-28 21:32:52 -05:00 committed by GitHub
parent ef15098288
commit 1f19ef670b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 35 deletions

View file

@ -8,6 +8,7 @@ use tracing::{debug, instrument};
use platform_host::Platform;
use uv_cache::Cache;
use uv_fs::normalize_path;
use crate::{Error, Interpreter};
@ -63,7 +64,8 @@ pub fn find_requested_python(
Interpreter::query(&executable, platform.clone(), cache).map(Some)
} else {
// `-p /home/ferris/.local/bin/python3.10`
let executable = fs_err::canonicalize(request)?;
let executable = normalize_path(request);
Interpreter::query(&executable, platform.clone(), cache).map(Some)
}
}