mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Use sys.executable
as python root path (#431)
Previously, we were assuming that `which <python>` return the path to the python executable. This is not true when using pyenv shims, which are bash scripts. Instead, we have to use `sys.executable`. Luckily, we're already querying the python interpreter and can do it in that pass. We are also not allowed to cache the execution of the python interpreter through the shim because pyenv might change the target. As a heuristic, we check whether `sys.executable`, the real binary, is the same our canonicalized `which` result. --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
d3caf9ae86
commit
c0339893e7
12 changed files with 99 additions and 46 deletions
|
@ -78,8 +78,9 @@ fn venv_impl(
|
|||
|
||||
writeln!(
|
||||
printer,
|
||||
"Using Python interpreter: {}",
|
||||
format!("{}", base_python.display()).cyan()
|
||||
"Using Python {} at {}",
|
||||
interpreter_info.version(),
|
||||
format!("{}", interpreter_info.sys_executable().display()).cyan()
|
||||
)
|
||||
.into_diagnostic()?;
|
||||
|
||||
|
@ -95,8 +96,7 @@ fn venv_impl(
|
|||
.into_diagnostic()?;
|
||||
|
||||
// Create the virtual environment.
|
||||
gourgeist::create_venv(path, &base_python, &interpreter_info)
|
||||
.map_err(VenvError::CreationError)?;
|
||||
gourgeist::create_venv(path, &interpreter_info).map_err(VenvError::CreationError)?;
|
||||
|
||||
Ok(ExitStatus::Success)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,8 @@ fn install() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -105,6 +107,8 @@ fn install_copy() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -150,6 +154,8 @@ fn install_hardlink() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -195,6 +201,8 @@ fn install_many() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -238,6 +246,8 @@ fn noop() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -292,6 +302,8 @@ fn link() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -317,6 +329,8 @@ fn link() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -357,6 +371,8 @@ fn add_remove() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -422,6 +438,8 @@ fn install_sequential() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -480,6 +498,8 @@ fn upgrade() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -537,6 +557,8 @@ fn install_url() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -583,6 +605,8 @@ fn install_git_commit() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -629,6 +653,8 @@ fn install_git_tag() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -675,6 +701,8 @@ fn install_git_subdirectories() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -720,6 +748,8 @@ fn install_sdist() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -766,6 +796,8 @@ fn install_url_then_install_url() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -822,6 +854,8 @@ fn install_url_then_install_version() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -882,6 +916,8 @@ fn install_version_then_install_url() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
@ -987,6 +1023,8 @@ fn warn_on_yanked_version() -> Result<()> {
|
|||
.arg(venv.as_os_str())
|
||||
.arg("--cache-dir")
|
||||
.arg(cache_dir.path())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&temp_dir)
|
||||
.assert()
|
||||
.success();
|
||||
|
|
|
@ -4,13 +4,15 @@ info:
|
|||
program: puffin
|
||||
args:
|
||||
- venv
|
||||
- /var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/.tmpn0fxWx/.venv
|
||||
- /var/folders/bc/qlsk3t6x7c9fhhbvvcg68k9c0000gp/T/.tmprOsp0M/.venv
|
||||
- "--python"
|
||||
- python3.12
|
||||
---
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Using Python interpreter: /usr/bin/python3
|
||||
Using Python 3.11 at [PATH]
|
||||
Creating virtual environment at: /home/ferris/project/.venv
|
||||
|
||||
|
|
|
@ -4,12 +4,14 @@ info:
|
|||
program: puffin
|
||||
args:
|
||||
- venv
|
||||
- "--python"
|
||||
- python3.12
|
||||
---
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Using Python interpreter: /usr/bin/python3
|
||||
Using Python 3.11 at [PATH]
|
||||
Creating virtual environment at: .venv
|
||||
|
||||
|
|
|
@ -19,12 +19,15 @@ fn create_venv() -> Result<()> {
|
|||
insta::with_settings!({
|
||||
filters => vec![
|
||||
(r"Using Python interpreter: .+", "Using Python interpreter: /usr/bin/python3"),
|
||||
(r"Using Python 3.12 at .+", "Using Python 3.11 at [PATH]"),
|
||||
(tempdir.to_str().unwrap(), "/home/ferris/project"),
|
||||
]
|
||||
}, {
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.arg("venv")
|
||||
.arg(venv.as_os_str())
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&tempdir));
|
||||
});
|
||||
|
||||
|
@ -41,11 +44,14 @@ fn create_venv_defaults_to_cwd() -> Result<()> {
|
|||
insta::with_settings!({
|
||||
filters => vec![
|
||||
(r"Using Python interpreter: .+", "Using Python interpreter: /usr/bin/python3"),
|
||||
(r"Using Python 3.12 at .+", "Using Python 3.11 at [PATH]"),
|
||||
(tempdir.to_str().unwrap(), "/home/ferris/project"),
|
||||
]
|
||||
}, {
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.arg("venv")
|
||||
.arg("--python")
|
||||
.arg("python3.12")
|
||||
.current_dir(&tempdir));
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue