mirror of https://github.com/astral-sh/uv
Use portable slash paths in lockfile (#4324)
## Summary This would be a lightweight solution to https://github.com/astral-sh/uv/issues/4307 that doesn't fully engage with all the possibilities in the design space (but would unblock cross-platform for now).
This commit is contained in:
parent
74c05683bb
commit
b7fb0b445f
|
|
@ -4864,6 +4864,7 @@ dependencies = [
|
|||
"itertools 0.13.0",
|
||||
"once-map",
|
||||
"owo-colors",
|
||||
"path-slash",
|
||||
"pep440_rs",
|
||||
"pep508_rs",
|
||||
"petgraph",
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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###"
|
||||
|
|
|
|||
Loading…
Reference in New Issue