Skip to content

Commit a20fece

Browse files
Strip fragments from direct source URLs in lockfile (#7061)
## Summary In resolving #7059, I noticed that we left the fragment on the `source = { url = "..." }`.
1 parent 1f7a9a7 commit a20fece

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

crates/uv-resolver/src/lock/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,14 +2280,14 @@ impl Source {
22802280

22812281
fn from_direct_built_dist(direct_dist: &DirectUrlBuiltDist) -> Source {
22822282
Source::Direct(
2283-
UrlString::from(&direct_dist.url),
2283+
normalize_url(direct_dist.url.to_url()),
22842284
DirectSource { subdirectory: None },
22852285
)
22862286
}
22872287

22882288
fn from_direct_source_dist(direct_dist: &DirectUrlSourceDist) -> Source {
22892289
Source::Direct(
2290-
UrlString::from(&direct_dist.url),
2290+
normalize_url(direct_dist.url.to_url()),
22912291
DirectSource {
22922292
subdirectory: direct_dist
22932293
.subdirectory

crates/uv/tests/lock.rs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12492,3 +12492,92 @@ fn lock_python_upper_bound() -> Result<()> {
1249212492

1249312493
Ok(())
1249412494
}
12495+
12496+
#[test]
12497+
fn lock_strip_fragment() -> Result<()> {
12498+
let context = TestContext::new("3.12");
12499+
12500+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
12501+
pyproject_toml.write_str(
12502+
r#"
12503+
[project]
12504+
name = "project"
12505+
version = "0.1.0"
12506+
requires-python = ">=3.12"
12507+
dependencies = ["iniconfig @ https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl#sha256=b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"]
12508+
12509+
[build-system]
12510+
requires = ["setuptools>=42"]
12511+
build-backend = "setuptools.build_meta"
12512+
"#,
12513+
)?;
12514+
12515+
uv_snapshot!(context.filters(), context.lock(), @r###"
12516+
success: true
12517+
exit_code: 0
12518+
----- stdout -----
12519+
12520+
----- stderr -----
12521+
Resolved 2 packages in [TIME]
12522+
"###);
12523+
12524+
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
12525+
12526+
insta::with_settings!({
12527+
filters => context.filters(),
12528+
}, {
12529+
assert_snapshot!(
12530+
lock, @r###"
12531+
version = 1
12532+
requires-python = ">=3.12"
12533+
12534+
[options]
12535+
exclude-newer = "2024-03-25T00:00:00Z"
12536+
12537+
[[package]]
12538+
name = "iniconfig"
12539+
version = "2.0.0"
12540+
source = { url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl" }
12541+
wheels = [
12542+
{ url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374" },
12543+
]
12544+
12545+
[[package]]
12546+
name = "project"
12547+
version = "0.1.0"
12548+
source = { editable = "." }
12549+
dependencies = [
12550+
{ name = "iniconfig" },
12551+
]
12552+
12553+
[package.metadata]
12554+
requires-dist = [{ name = "iniconfig", url = "https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl#sha256=b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374" }]
12555+
"###
12556+
);
12557+
});
12558+
12559+
// Re-run with `--locked`.
12560+
uv_snapshot!(context.filters(), context.lock().arg("--locked"), @r###"
12561+
success: true
12562+
exit_code: 0
12563+
----- stdout -----
12564+
12565+
----- stderr -----
12566+
Resolved 2 packages in [TIME]
12567+
"###);
12568+
12569+
// Install from the lockfile.
12570+
uv_snapshot!(context.filters(), context.sync().arg("--frozen"), @r###"
12571+
success: true
12572+
exit_code: 0
12573+
----- stdout -----
12574+
12575+
----- stderr -----
12576+
Prepared 2 packages in [TIME]
12577+
Installed 2 packages in [TIME]
12578+
+ iniconfig==2.0.0 (from https://files.pythonhosted.org/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl)
12579+
+ project==0.1.0 (from file://[TEMP_DIR]/)
12580+
"###);
12581+
12582+
Ok(())
12583+
}

0 commit comments

Comments
 (0)