Automatically detect workspace packages in uv add (#4557)

## Summary

If the package _isn't_ marked as `workspace = true`, locking will fail
given:

```rust
let workspace_package_declared =
    // We require that when you use a package that's part of the workspace, ...
    !workspace.packages().contains_key(&requirement.name)
    // ... it must be declared as a workspace dependency (`workspace = true`), ...
    || matches!(
        source,
        Some(Source::Workspace {
            // By using toml, we technically support `workspace = false`.
            workspace: true,
            ..
        })
    )
    // ... except for recursive self-inclusion (extras that activate other extras), e.g.
    // `framework[machine_learning]` depends on `framework[cuda]`.
    || &requirement.name == project_name;
if !workspace_package_declared {
    return Err(LoweringError::UndeclaredWorkspacePackage);
}
```

Closes https://github.com/astral-sh/uv/issues/4552.
This commit is contained in:
Charlie Marsh 2024-06-26 14:03:23 -04:00 committed by GitHub
parent a328c7b995
commit 45c271d15d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 46 additions and 23 deletions

View file

@ -1749,10 +1749,6 @@ pub struct AddArgs {
#[arg(long)]
pub dev: bool,
/// Add the requirements as workspace dependencies.
#[arg(long)]
pub workspace: bool,
/// Add the requirements as editables.
#[arg(long, default_missing_value = "true", num_args(0..=1))]
pub editable: Option<bool>,