From 75a042d5ff342de64f43f5f2eb43ea4688168423 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 25 Jul 2024 14:01:41 -0400 Subject: [PATCH] Allow distributions to be absent in deserialization (#5453) ## Summary Closes https://github.com/astral-sh/uv/issues/5434. --- crates/uv-resolver/src/lock.rs | 3 ++- crates/uv/tests/sync.rs | 43 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/crates/uv-resolver/src/lock.rs b/crates/uv-resolver/src/lock.rs index 01e2e07b2..cd781e465 100644 --- a/crates/uv-resolver/src/lock.rs +++ b/crates/uv-resolver/src/lock.rs @@ -571,8 +571,9 @@ impl Lock { #[serde(rename_all = "kebab-case")] struct LockWire { version: u32, - #[serde(rename = "distribution")] + #[serde(rename = "distribution", default)] distributions: Vec, + #[serde(default)] requires_python: Option, #[serde(default)] resolution_mode: ResolutionMode, diff --git a/crates/uv/tests/sync.rs b/crates/uv/tests/sync.rs index eae1c7e12..54c3a7a8f 100644 --- a/crates/uv/tests/sync.rs +++ b/crates/uv/tests/sync.rs @@ -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(()) +}