Skip to content

Commit

Permalink
Recommend [project] table in uv add for non-project directories
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 27, 2024
1 parent 3ee6ca3 commit d1abe56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,14 @@ pub(crate) async fn add(
};

// For non-project workspace roots, allow dev dependencies, but nothing else.
// TODO(charlie): Automatically "upgrade" the project by adding a `[project]` table.
if project.is_non_project() {
match dependency_type {
DependencyType::Production => {
bail!("Found a non-project workspace root; production dependencies are unsupported (instead, use: `{}`)", "uv add --dev".green())
bail!("Project is missing a `[project]` table; add a `[project]` table to support production dependencies, or use `{}`", "uv add --dev".green())
}
DependencyType::Optional(_) => {
bail!("Found a non-project workspace root; optional dependencies are unsupported (instead, use: `{}`)", "uv add --dev".green())
bail!("Project is missing a `[project]` table; add a `[project]` table to support optional dependencies, or use `{}`", "uv add --dev".green())
}
DependencyType::Dev => (),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3530,7 +3530,7 @@ fn add_non_project() -> Result<()> {
----- stdout -----
----- stderr -----
error: Found a non-project workspace root; production dependencies are unsupported (instead, use: `uv add --dev`)
error: Project is missing a `[project]` table; add a `[project]` table to support production dependencies, or use `uv add --dev`
"###);

// Adding `iniconfig` as optional should fail, since virtual workspace roots don't support
Expand All @@ -3541,7 +3541,7 @@ fn add_non_project() -> Result<()> {
----- stdout -----
----- stderr -----
error: Found a non-project workspace root; optional dependencies are unsupported (instead, use: `uv add --dev`)
error: Project is missing a `[project]` table; add a `[project]` table to support optional dependencies, or use `uv add --dev`
"###);

// Adding `iniconfig` as a dev dependency should succeed.
Expand Down

0 comments on commit d1abe56

Please sign in to comment.