Skip to content

Commit

Permalink
Use portable slash paths in lockfile (#4324)
Browse files Browse the repository at this point in the history
## Summary

This would be a lightweight solution to
#4307 that doesn't fully engage
with all the possibilities in the design space (but would unblock
cross-platform for now).
  • Loading branch information
charliermarsh authored Jun 14, 2024
1 parent 74c0568 commit b7fb0b4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/uv-resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ futures = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
owo-colors = { workspace = true }
path-slash = { workspace = true }
petgraph = { workspace = true }
pubgrub = { workspace = true }
rkyv = { workspace = true }
Expand Down
6 changes: 5 additions & 1 deletion crates/uv-resolver/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use either::Either;
use path_slash::PathExt;
use petgraph::visit::EdgeRef;
use rustc_hash::FxHashMap;
use serde::{Deserialize, Deserializer};
Expand Down Expand Up @@ -851,8 +852,11 @@ enum Source {
}

/// A [`PathBuf`], but we show `.` instead of an empty path.
///
/// We also normalize backslashes to forward slashes on Windows, to ensure
/// that the lock file contains portable paths.
fn serialize_path_with_dot(path: &Path) -> Cow<str> {
let path = path.to_string_lossy();
let path = path.to_slash_lossy();
if path.is_empty() {
Cow::Borrowed(".")
} else {
Expand Down
19 changes: 1 addition & 18 deletions crates/uv/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2478,25 +2478,8 @@ fn relative_and_absolute_paths() -> Result<()> {

let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock"))?;

// In this particular test, Windows paths with \ are written to the TOML
// lock file, but because the \ starts an escape sequence in TOML strings,
// this causes the TOML serializer to use single quoted strings. But
// everywhere else, / is used and thus double quoted strings are used.
//
// Making matters more confusing, we have filters that normalize Windows
// paths to Unix paths, which makes it *look* like the TOML in the snapshot
// is needlessly using single quoted strings.
//
// So we add a filter here (that runs after all other filters) that
// replaces single quoted strings with double quoted strings. This isn't
// correct in general, but works for this specific test.
let filters = context
.filters()
.into_iter()
.chain(vec![(r"'([^']+)'", r#""$1""#)])
.collect::<Vec<_>>();
insta::with_settings!({
filters => filters,
filters => context.filters(),
}, {
assert_snapshot!(
lock, @r###"
Expand Down

0 comments on commit b7fb0b4

Please sign in to comment.