Remove UNC prefixes on Windows (#1086)

## Summary

This PR adds a `NormalizedDisplay` trait that we can use for user-facing
paths, to strip the UNC prefix on Windows.

On other platforms, the implementation is a no-op (vs. `Display`).

I audited all usages of `.display()`, and changed any that were
user-facing, either via `println!` or `eprintln!`, or by way of being
included in error messages. I did _not_ change uses that were only in
tests or only went to tracing.

Closes https://github.com/astral-sh/puffin/issues/1084.
This commit is contained in:
Charlie Marsh 2024-01-25 08:44:22 -08:00 committed by GitHub
parent 035cd81ac8
commit f4939e50a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 98 additions and 43 deletions

View file

@ -24,6 +24,7 @@ distribution-filename = { path = "../distribution-filename" }
pep440_rs = { path = "../pep440-rs" }
platform-host = { path = "../platform-host" }
puffin-normalize = { path = "../puffin-normalize" }
puffin-fs = { path = "../puffin-fs" }
pypi-types = { path = "../pypi-types" }
clap = { workspace = true, optional = true, features = ["derive", "env"] }

View file

@ -5,6 +5,8 @@ use fs2::FileExt;
use fs_err::File;
use tracing::{error, warn};
use puffin_fs::NormalizedDisplay;
const INSTALL_LOCKFILE: &str = "install-wheel-rs.lock";
/// I'm not sure that's the right way to normalize here, but it's a single place to change
@ -55,7 +57,7 @@ impl Drop for LockedDir {
if let Err(err) = self.lockfile.file().unlock() {
error!(
"Failed to unlock {}: {}",
self.lockfile.path().display(),
self.lockfile.path().normalized_display(),
err
);
}

View file

@ -22,6 +22,7 @@ use zip::{ZipArchive, ZipWriter};
use distribution_filename::WheelFilename;
use pep440_rs::Version;
use puffin_fs::NormalizedDisplay;
use puffin_normalize::PackageName;
use pypi_types::DirectUrl;
@ -236,7 +237,7 @@ fn unpack_wheel_files<R: Read + Seek>(
.ok_or_else(|| {
Error::RecordFile(format!(
"Missing hash for {} (expected {})",
relative.display(),
relative.normalized_display(),
encoded_hash
))
})?;
@ -244,7 +245,7 @@ fn unpack_wheel_files<R: Read + Seek>(
if relative.as_os_str().to_string_lossy().starts_with("torch-") {
error!(
"Hash mismatch for {}. Recorded: {}, Actual: {}",
relative.display(),
relative.normalized_display(),
recorded_hash,
encoded_hash,
);
@ -256,7 +257,7 @@ fn unpack_wheel_files<R: Read + Seek>(
}
return Err(Error::RecordFile(format!(
"Hash mismatch for {}. Recorded: {}, Actual: {}",
relative.display(),
relative.normalized_display(),
recorded_hash,
encoded_hash,
)));
@ -499,7 +500,7 @@ fn bytecode_compile(
io::ErrorKind::NotFound,
format!(
"Didn't find pyc generated by compileall: {}",
site_packages.join(&pyc_path).display()
site_packages.join(&pyc_path).normalized_display()
),
)));
}
@ -593,9 +594,9 @@ pub fn relative_to(path: &Path, base: &Path) -> Result<PathBuf, Error> {
Error::Io(io::Error::new(
io::ErrorKind::Other,
format!(
"trivial strip case should have worked: {} vs {}",
path.display(),
base.display()
"Trivial strip failed: {} vs. {}",
path.normalized_display(),
base.normalized_display()
),
))
})?;
@ -717,8 +718,8 @@ fn install_script(
// This should be possible to occur at this point, but filesystems and such
Error::RecordFile(format!(
"Could not find entry for {} ({})",
relative_to_site_packages.display(),
path.display()
relative_to_site_packages.normalized_display(),
path.normalized_display()
))
})?;
entry.path = target_path.display().to_string();