Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/uv-resolver/src/lock/export/pylock_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,10 @@ impl<'lock> PylockToml {
};
doc.insert("attestation-identities", value(attestation_identities));
}
if !self.packages.is_empty() {
if self.packages.is_empty() {
// `packages` is a required key in PEP 751, even when empty.
doc.insert("packages", value(Array::new()));
} else {
let mut packages = ArrayOfTables::new();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use this branch's default case as zero [[packages]] sections is a missing packages key.

for dist in &self.packages {
packages.push(dist.to_toml()?);
Expand Down
35 changes: 35 additions & 0 deletions crates/uv/tests/project/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4074,6 +4074,41 @@ fn pep_751_dependency() -> Result<()> {
Ok(())
}

/// `packages` is a required key in PEP 751, even when there are no packages to export.
#[test]
fn pep_751_no_packages() -> Result<()> {
let context = uv_test::test_context!("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
"#,
)?;

context.lock().assert().success();

uv_snapshot!(context.filters(), context.export().arg("--format").arg("pylock.toml").arg("--no-emit-project"), @r#"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv export --cache-dir [CACHE_DIR] --format pylock.toml --no-emit-project
lock-version = "1.0"
created-by = "uv"
requires-python = ">=3.12"
packages = []

----- stderr -----
Resolved 1 package in [TIME]
"#);

Ok(())
}

#[test]
fn pep_751_export_no_header() -> Result<()> {
let context = uv_test::test_context!("3.12");
Expand Down
Loading