Skip to content

Commit

Permalink
Strip UNC
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed May 9, 2024
1 parent 6bd18ce commit 0ebe593
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 37 deletions.
72 changes: 36 additions & 36 deletions crates/requirements-txt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ mod test {
use crate::{calculate_row_column, EditableRequirement, RequirementsTxt};

fn workspace_test_data_dir() -> PathBuf {
PathBuf::from("./test-data").canonicalize().unwrap()
Path::new("./test-data").simple_canonicalize().unwrap()
}

fn safe_filter_path(path: &Path) -> String {
Expand Down Expand Up @@ -1820,41 +1820,41 @@ mod test {
let filter_path = safe_filter_path(temp_dir.path());
let filters = vec![(filter_path.as_str(), "<REQUIREMENTS_DIR>")];
insta::with_settings!({
filters => filters,
}, {
insta::assert_debug_snapshot!(requirements, @r###"
RequirementsTxt {
requirements: [
RequirementEntry {
requirement: Named(
Requirement {
name: PackageName(
"flask",
),
extras: [],
version_or_url: None,
marker: None,
path: Some(
"<REQUIREMENTS_DIR>subdir/sibling.txt",
),
},
),
hashes: [],
path: Some(
"<REQUIREMENTS_DIR>subdir/sibling.txt",
),
},
],
constraints: [],
editables: [],
index_url: None,
extra_index_urls: [],
find_links: [],
no_index: false,
no_binary: None,
only_binary: None,
}
"###);
filters => filters,
}, {
insta::assert_debug_snapshot!(requirements, @r###"
RequirementsTxt {
requirements: [
RequirementEntry {
requirement: Named(
Requirement {
name: PackageName(
"flask",
),
extras: [],
version_or_url: None,
marker: None,
path: Some(
"<REQUIREMENTS_DIR>subdir/sibling.txt",
),
},
),
hashes: [],
path: Some(
"<REQUIREMENTS_DIR>subdir/sibling.txt",
),
},
],
constraints: [],
editables: [],
index_url: None,
extra_index_urls: [],
find_links: [],
no_index: false,
no_binary: None,
only_binary: None,
}
"###);
});

Ok(())
Expand Down
9 changes: 8 additions & 1 deletion crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub trait Simplified {
/// equivalent to [`std::path::Display`].
fn simplified_display(&self) -> std::path::Display;

/// Canonicalize a path without a `\\?\` prefix on Windows.
fn simple_canonicalize(&self) -> std::io::Result<PathBuf>;

/// Render a [`Path`] for user-facing display.
///
/// Like [`simplified_display`], but relativizes the path against the current working directory.
Expand All @@ -37,6 +40,10 @@ impl<T: AsRef<Path>> Simplified for T {
dunce::simplified(self.as_ref()).display()
}

fn simple_canonicalize(&self) -> std::io::Result<PathBuf> {
dunce::canonicalize(self.as_ref())
}

fn user_display(&self) -> std::path::Display {
let path = dunce::simplified(self.as_ref());
path.strip_prefix(CWD.simplified())
Expand Down Expand Up @@ -136,7 +143,7 @@ pub fn normalize_path(path: &Path) -> Result<PathBuf, std::io::Error> {
pub fn absolutize_path(path: &Path) -> Result<Cow<Path>, std::io::Error> {
use path_absolutize::Absolutize;

path.absolutize_from(&*CWD)
path.absolutize_from(CWD.simplified())
}

/// Like `fs_err::canonicalize`, but with permissive failures on Windows.
Expand Down

0 comments on commit 0ebe593

Please sign in to comment.