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
79 changes: 15 additions & 64 deletions crates/uv-python/src/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,49 +54,24 @@ pub enum Error {
ExtractError(#[from] uv_extract::Error),
#[error(transparent)]
SysconfigError(#[from] sysconfig::Error),
#[error("Failed to copy to: {0}", to.user_display())]
CopyError {
to: PathBuf,
#[source]
err: io::Error,
},
#[error("Missing expected Python executable at {}", _0.user_display())]
MissingExecutable(PathBuf),
#[error("Missing expected target directory for Python minor version link at {}", _0.user_display())]
MissingPythonMinorVersionLinkTargetDirectory(PathBuf),
#[error("Failed to create canonical Python executable at {} from {}", to.user_display(), from.user_display())]
CanonicalizeExecutable {
from: PathBuf,
to: PathBuf,
#[source]
err: io::Error,
},
Comment on lines -67 to -73
Copy link
Member

Choose a reason for hiding this comment

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

Here you both dropped to and from, aren't we going to lose context in this error message?

#[error("Failed to create Python executable link at {} from {}", to.user_display(), from.user_display())]
#[error("Failed to create canonical Python executable")]
CanonicalizeExecutable(#[source] io::Error),
#[error("Failed to create Python executable link")]
LinkExecutable {
from: PathBuf,
to: PathBuf,
Comment on lines +63 to 65
Copy link
Member

Choose a reason for hiding this comment

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

Here it looks like you retained to but dropped from and to is no longer used in the error message?

#[source]
err: io::Error,
},
#[error("Failed to create Python minor version link directory at {} from {}", to.user_display(), from.user_display())]
PythonMinorVersionLinkDirectory {
from: PathBuf,
to: PathBuf,
#[source]
err: io::Error,
},
#[error("Failed to create directory for Python executable link at {}", to.user_display())]
ExecutableDirectory {
to: PathBuf,
#[source]
err: io::Error,
},
#[error("Failed to read Python installation directory: {0}", dir.user_display())]
ReadError {
dir: PathBuf,
#[source]
err: io::Error,
},
#[error("Failed to create Python minor version link directory")]
PythonMinorVersionLinkDirectory(#[source] io::Error),
#[error("Failed to create directory for Python executable link")]
ExecutableDirectory(#[source] io::Error),
#[error("Failed to read Python installation directory")]
ReadError(#[source] io::Error),
#[error("Failed to find a directory to install executables into")]
NoExecutableDirectory,
#[error(transparent)]
Expand Down Expand Up @@ -241,18 +216,12 @@ impl ManagedPythonInstallations {
Err(err) => Some(Err(err)),
})
.collect::<Result<_, io::Error>>()
.map_err(|err| Error::ReadError {
dir: self.root.clone(),
err,
})?;
.map_err(Error::ReadError)?;
directories
}
Err(err) if err.kind() == io::ErrorKind::NotFound => vec![],
Err(err) => {
return Err(Error::ReadError {
dir: self.root.clone(),
err,
});
return Err(Error::ReadError(err));
}
};
let scratch = self.scratch();
Expand Down Expand Up @@ -573,11 +542,7 @@ impl ManagedPythonInstallation {
}
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {}
Err(err) => {
return Err(Error::CanonicalizeExecutable {
from: executable,
to: python,
err,
});
return Err(Error::CanonicalizeExecutable(err));
}
}
}
Expand Down Expand Up @@ -862,11 +827,7 @@ impl PythonMinorVersionLink {
}
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {}
Err(err) => {
return Err(Error::PythonMinorVersionLinkDirectory {
from: self.symlink_directory.clone(),
to: self.target_directory.clone(),
err,
});
return Err(Error::PythonMinorVersionLinkDirectory(err));
}
}
Ok(())
Expand Down Expand Up @@ -957,10 +918,7 @@ fn executable_path_from_base(
/// If the file already exists at the link path, an error will be returned.
pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), Error> {
let link_parent = link.parent().ok_or(Error::NoExecutableDirectory)?;
fs_err::create_dir_all(link_parent).map_err(|err| Error::ExecutableDirectory {
to: link_parent.to_path_buf(),
err,
})?;
fs_err::create_dir_all(link_parent).map_err(Error::ExecutableDirectory)?;

if cfg!(unix) {
// Note this will never copy on Unix — we use it here to allow compilation on Windows
Expand All @@ -970,7 +928,6 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
Err(Error::MissingExecutable(executable.to_path_buf()))
}
Err(err) => Err(Error::LinkExecutable {
from: executable.to_path_buf(),
to: link.to_path_buf(),
err,
}),
Expand All @@ -988,7 +945,6 @@ 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 {
from: executable.to_path_buf(),
to: link.to_path_buf(),
err,
})
Expand All @@ -1005,14 +961,10 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
/// See [`create_link_to_executable`] for a variant that errors if the link already exists.
pub fn replace_link_to_executable(link: &Path, executable: &Path) -> Result<(), Error> {
let link_parent = link.parent().ok_or(Error::NoExecutableDirectory)?;
fs_err::create_dir_all(link_parent).map_err(|err| Error::ExecutableDirectory {
to: link_parent.to_path_buf(),
err,
})?;
fs_err::create_dir_all(link_parent).map_err(Error::ExecutableDirectory)?;

if cfg!(unix) {
replace_symlink(executable, link).map_err(|err| Error::LinkExecutable {
from: executable.to_path_buf(),
to: link.to_path_buf(),
err,
})
Expand All @@ -1022,7 +974,6 @@ pub fn replace_link_to_executable(link: &Path, executable: &Path) -> Result<(),
let launcher = windows_python_launcher(executable, false)?;

uv_fs::write_atomic_sync(link, &*launcher).map_err(|err| Error::LinkExecutable {
from: executable.to_path_buf(),
to: link.to_path_buf(),
err,
})
Expand Down
2 changes: 1 addition & 1 deletion 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 { from: _, to, err })
Err(uv_python::managed::Error::LinkExecutable { to, err })
if err.kind() == ErrorKind::AlreadyExists =>
{
debug!(
Expand Down
Loading