feat: Error on dependency object specifier (#12811)

## Summary

This PR errors out when an Unknown Dependency Object Specifier is used
in dependency groups.


Fixes #12638 

## Test Plan

The current behaviour is as follows:

```bash
➜  example git:(12638/dependency-object-specifier) ✗ cargo run -- sync
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s
     Running `/home/luna/Documents/uv/target/debug/uv sync`
error: Failed to generate package metadata for `example==0.1.0 @ virtual+.`
  Caused by: Group `bar` contains a Dependency Object Specifier, which is not supported by uv
  ```


And the pyproject.toml to produce this is:

```toml
[project]
name = "example"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13.2"
dependencies = []

[dependency-groups]
foo = ["pyparsing"]
bar = [{set-phasers-to = "stun"}]
```
This commit is contained in:
Chandra Kiran G 2025-04-11 02:26:47 +05:30 committed by GitHub
parent 713c0053ef
commit c117acf905
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 9 deletions

View file

@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use std::str::FromStr;
use thiserror::Error;
use tracing::warn;
use tracing::error;
use uv_normalize::{GroupName, DEV_DEPENDENCIES};
use uv_pep508::Pep508Error;
@ -74,9 +74,10 @@ impl FlatDependencyGroups {
.extend(resolved.get(include_group).into_iter().flatten().cloned());
}
DependencyGroupSpecifier::Object(map) => {
warn!(
"Ignoring Dependency Object Specifier referenced by `{name}`: {map:?}"
);
return Err(DependencyGroupError::DependencyObjectSpecifierNotSupported(
name.clone(),
map.clone(),
));
}
}
}
@ -154,6 +155,8 @@ pub enum DependencyGroupError {
DevGroupInclude(GroupName),
#[error("Detected a cycle in `dependency-groups`: {0}")]
DependencyGroupCycle(Cycle),
#[error("Group `{0}` contains an unknown dependency object specifier: {1:?}")]
DependencyObjectSpecifierNotSupported(GroupName, BTreeMap<String, String>),
}
impl DependencyGroupError {

View file

@ -20832,14 +20832,15 @@ fn lock_group_invalid_entry_table() -> Result<()> {
"#,
)?;
uv_snapshot!(context.filters(), context.lock(), @r###"
success: true
exit_code: 0
uv_snapshot!(context.filters(), context.lock(), @r#"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
Resolved 2 packages in [TIME]
"###);
× Failed to build `project @ file://[TEMP_DIR]/`
Group `foo` contains an unknown dependency object specifier: {"bar": "unknown"}
"#);
Ok(())
}