Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions crates/uv-python/src/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ pub enum Error {
#[error("Failed to create canonical Python executable")]
CanonicalizeExecutable(#[source] io::Error),
#[error("Failed to create Python executable link")]
LinkExecutable {
to: PathBuf,
#[source]
err: io::Error,
},
LinkExecutable(#[source] io::Error),
#[error("Failed to create Python minor version link directory")]
PythonMinorVersionLinkDirectory(#[source] io::Error),
#[error("Failed to create directory for Python executable link")]
Expand Down Expand Up @@ -927,10 +923,7 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
Err(err) if err.kind() == io::ErrorKind::NotFound => {
Err(Error::MissingExecutable(executable.to_path_buf()))
}
Err(err) => Err(Error::LinkExecutable {
to: link.to_path_buf(),
err,
}),
Err(err) => Err(Error::LinkExecutable(err)),
}
} else if cfg!(windows) {
use uv_trampoline_builder::windows_python_launcher;
Expand All @@ -944,10 +937,7 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
{
std::fs::File::create_new(link)
.and_then(|mut file| file.write_all(launcher.as_ref()))
.map_err(|err| Error::LinkExecutable {
to: link.to_path_buf(),
err,
})
.map_err(Error::LinkExecutable)
}
} else {
unimplemented!("Only Windows and Unix are supported.")
Expand All @@ -964,19 +954,13 @@ pub fn replace_link_to_executable(link: &Path, executable: &Path) -> Result<(),
fs_err::create_dir_all(link_parent).map_err(Error::ExecutableDirectory)?;

if cfg!(unix) {
replace_symlink(executable, link).map_err(|err| Error::LinkExecutable {
to: link.to_path_buf(),
err,
})
replace_symlink(executable, link).map_err(Error::LinkExecutable)
} else if cfg!(windows) {
use uv_trampoline_builder::windows_python_launcher;

let launcher = windows_python_launcher(executable, false)?;

uv_fs::write_atomic_sync(link, &*launcher).map_err(|err| Error::LinkExecutable {
to: link.to_path_buf(),
err,
})
uv_fs::write_atomic_sync(link, &*launcher).map_err(Error::LinkExecutable)
} else {
unimplemented!("Only Windows and Unix are supported.")
}
Expand Down
12 changes: 6 additions & 6 deletions crates/uv/src/commands/python/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ fn create_bin_links(
.or_default()
.insert(target.clone());
}
Err(uv_python::managed::Error::LinkExecutable { to, err })
Err(uv_python::managed::Error::LinkExecutable(err))
if err.kind() == ErrorKind::AlreadyExists =>
{
debug!(
Expand Down Expand Up @@ -1059,7 +1059,7 @@ fn create_bin_links(
if upgrade {
warn_user!(
"Executable already exists at `{}` but is not managed by uv; use `uv python install {}.{}{} --force` to replace it",
to.simplified_display(),
target.simplified_display(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh we have the target still around at this point, convenient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently haha, I was surprised too. I actually didn't realize to was used downstream. We might even want to keep it as it's "definitely" correct whereas target could drift? 🤷‍♀️

installation.key().major(),
installation.key().minor(),
installation.key().variant().display_suffix()
Expand All @@ -1070,7 +1070,7 @@ fn create_bin_links(
installation.key().clone(),
anyhow::anyhow!(
"Executable already exists at `{}` but is not managed by uv; use `--force` to replace it",
to.simplified_display()
target.simplified_display()
),
));
}
Expand Down Expand Up @@ -1133,7 +1133,7 @@ fn create_bin_links(
debug!(
"Executable already exists for `{}` at `{}`. Use `--force` to replace it",
existing.key(),
to.simplified_display()
target.simplified_display()
);
continue;
}
Expand All @@ -1142,13 +1142,13 @@ fn create_bin_links(
}

// Replace the existing link
if let Err(err) = fs_err::remove_file(&to) {
if let Err(err) = fs_err::remove_file(&target) {
errors.push((
InstallErrorKind::Bin,
installation.key().clone(),
anyhow::anyhow!(
"Executable already exists at `{}` but could not be removed: {err}",
to.simplified_display()
target.simplified_display()
),
));
continue;
Expand Down