Allow distributions to be absent in deserialization (#5453)

## Summary

Closes https://github.com/astral-sh/uv/issues/5434.
This commit is contained in:
Charlie Marsh 2024-07-25 14:01:41 -04:00 committed by GitHub
parent 6eb8f85668
commit 75a042d5ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 1 deletions

View File

@ -571,8 +571,9 @@ impl Lock {
#[serde(rename_all = "kebab-case")]
struct LockWire {
version: u32,
#[serde(rename = "distribution")]
#[serde(rename = "distribution", default)]
distributions: Vec<DistributionWire>,
#[serde(default)]
requires_python: Option<RequiresPython>,
#[serde(default)]
resolution_mode: ResolutionMode,

View File

@ -162,3 +162,46 @@ fn frozen() -> Result<()> {
Ok(())
}
#[test]
fn empty() -> Result<()> {
let context = TestContext::new("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r"
[tool.uv.workspace]
members = []
",
)?;
// Running `uv sync` should generate an empty lockfile.
uv_snapshot!(context.filters(), context.sync(), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv sync` is experimental and may change without warning
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
Resolved 0 packages in [TIME]
Audited 0 packages in [TIME]
"###);
assert!(context.temp_dir.child("uv.lock").exists());
// Running `uv sync` again should succeed.
uv_snapshot!(context.filters(), context.sync(), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
warning: `uv sync` is experimental and may change without warning
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
Resolved 0 packages in [TIME]
Audited 0 packages in [TIME]
"###);
Ok(())
}