Skip to content

Commit

Permalink
Normalize paths when lowering Git dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 3, 2024
1 parent 90d8105 commit 50637d2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
11 changes: 6 additions & 5 deletions crates/uv-distribution/src/metadata/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ impl LoweredRequirement {
})?;

let source = if let Some(git_member) = &git_member {
// If the workspace comes from a git dependency, all workspace
// members need to be git deps, too.
let subdirectory =
uv_fs::relative_to(member.root(), git_member.fetch_root)
.expect("Workspace member must be relative");
// If the workspace comes from a Git dependency, all workspace
// members need to be Git dependencies, too.
let subdirectory = uv_fs::normalize_path(
&uv_fs::relative_to(member.root(), git_member.fetch_root)
.expect("Workspace member must be relative"),
);
RequirementSource::Git {
repository: git_member.git_source.git.repository().clone(),
reference: git_member.git_source.git.reference().clone(),
Expand Down
7 changes: 5 additions & 2 deletions crates/uv-resolver/src/resolver/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ impl Urls {
fn same_resource(a: &ParsedUrl, b: &ParsedUrl, git: &GitResolver) -> bool {
match (a, b) {
(ParsedUrl::Archive(a), ParsedUrl::Archive(b)) => {
a.subdirectory == b.subdirectory
a.subdirectory.as_deref().map(uv_fs::normalize_path)
== b.subdirectory.as_deref().map(uv_fs::normalize_path)
&& CanonicalUrl::new(&a.url) == CanonicalUrl::new(&b.url)
}
(ParsedUrl::Git(a), ParsedUrl::Git(b)) => {
a.subdirectory == b.subdirectory && git.same_ref(&a.url, &b.url)
a.subdirectory.as_deref().map(uv_fs::normalize_path)
== b.subdirectory.as_deref().map(uv_fs::normalize_path)
&& git.same_ref(&a.url, &b.url)
}
(ParsedUrl::Path(a), ParsedUrl::Path(b)) => {
a.install_path == b.install_path
Expand Down
91 changes: 91 additions & 0 deletions crates/uv/tests/it/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5319,6 +5319,97 @@ fn sync_git_repeated_member_dynamic_metadata() -> Result<()> {
Ok(())
}

/// See: <https://github.com/astral-sh/uv/issues/8887>
#[test]
fn sync_git_repeated_member_backwards_path() -> Result<()> {
let context = TestContext::new("3.13");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "foo"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = ["package", "dependency"]
[tool.uv.sources]
package = { git = "https://github.com/astral-sh/uv-backwards-path-test", subdirectory = "root" }
dependency = { git = "https://github.com/astral-sh/uv-backwards-path-test", subdirectory = "dependency" }
"#,
)?;

uv_snapshot!(context.filters(), context.lock(), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 3 packages in [TIME]
"###);

let lock = context.read("uv.lock");

insta::with_settings!(
{
filters => context.filters(),
},
{
assert_snapshot!(
lock, @r###"
version = 1
requires-python = ">=3.13"
[options]
exclude-newer = "2024-03-25T00:00:00Z"
[[package]]
name = "dependency"
version = "0.1.0"
source = { git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=dependency#4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9" }
[[package]]
name = "foo"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "dependency" },
{ name = "package" },
]
[package.metadata]
requires-dist = [
{ name = "dependency", git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=dependency" },
{ name = "package", git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=root" },
]
[[package]]
name = "package"
version = "0.1.0"
source = { git = "https://github.com/astral-sh/uv-backwards-path-test?subdirectory=root#4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9" }
dependencies = [
{ name = "dependency" },
]
"###
);
}
);

uv_snapshot!(context.filters(), context.sync(), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 3 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ dependency==0.1.0 (from git+https://github.com/astral-sh/uv-backwards-path-test@4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9#subdirectory=dependency)
+ package==0.1.0 (from git+https://github.com/astral-sh/uv-backwards-path-test@4bcc7fcd2e548c2ab7ba6b97b1c4e3ababccc7a9#subdirectory=root)
"###);

Ok(())
}

/// The project itself is marked as an editable dependency, but under the wrong name. The project
/// is a package.
#[test]
Expand Down

0 comments on commit 50637d2

Please sign in to comment.