@@ -21,7 +21,7 @@ use uv_distribution::DistributionDatabase;
2121use uv_distribution_types:: { Index , IndexName , UnresolvedRequirement , VersionId } ;
2222use uv_fs:: Simplified ;
2323use uv_git:: { GitReference , GIT_STORE } ;
24- use uv_normalize:: PackageName ;
24+ use uv_normalize:: { PackageName , DEV_DEPENDENCIES } ;
2525use uv_pep508:: { ExtraName , Requirement , UnnamedRequirement , VersionOrUrl } ;
2626use uv_pypi_types:: { redact_credentials, ParsedUrl , RequirementSource , VerbatimParsedUrl } ;
2727use uv_python:: {
@@ -463,8 +463,32 @@ pub(crate) async fn add(
463463 _ => source,
464464 } ;
465465
466+ // Determine the dependency type.
467+ let dependency_type = match & dependency_type {
468+ DependencyType :: Production => DependencyType :: Production ,
469+ DependencyType :: Optional ( extra) => DependencyType :: Optional ( extra. clone ( ) ) ,
470+ // If the requirement already exists in `dev-dependencies`; use that. Otherwise,
471+ // use `dependency-groups.dev`.
472+ DependencyType :: Dev => {
473+ if toml. find_dependency ( & requirement. name , None ) . is_empty ( ) {
474+ DependencyType :: Group ( DEV_DEPENDENCIES . clone ( ) )
475+ } else {
476+ DependencyType :: Dev
477+ }
478+ }
479+ DependencyType :: Group ( group) => {
480+ if group == & * DEV_DEPENDENCIES
481+ && !toml. find_dependency ( & requirement. name , None ) . is_empty ( )
482+ {
483+ DependencyType :: Dev
484+ } else {
485+ DependencyType :: Group ( group. clone ( ) )
486+ }
487+ }
488+ } ;
489+
466490 // Update the `pyproject.toml`.
467- let edit = match dependency_type {
491+ let edit = match & dependency_type {
468492 DependencyType :: Production => toml. add_dependency ( & requirement, source. as_ref ( ) ) ?,
469493 DependencyType :: Dev => toml. add_dev_dependency ( & requirement, source. as_ref ( ) ) ?,
470494 DependencyType :: Optional ( ref extra) => {
@@ -478,7 +502,7 @@ pub(crate) async fn add(
478502 // If the edit was inserted before the end of the list, update the existing edits.
479503 if let ArrayEdit :: Add ( index) = & edit {
480504 for edit in & mut edits {
481- if * edit. dependency_type == dependency_type {
505+ if edit. dependency_type == dependency_type {
482506 match & mut edit. edit {
483507 ArrayEdit :: Add ( existing) => {
484508 if * existing >= * index {
@@ -496,7 +520,7 @@ pub(crate) async fn add(
496520 }
497521
498522 edits. push ( DependencyEdit {
499- dependency_type : & dependency_type ,
523+ dependency_type,
500524 requirement,
501525 source,
502526 edit,
@@ -646,7 +670,7 @@ pub(crate) async fn add(
646670async fn lock_and_sync (
647671 mut project : VirtualProject ,
648672 toml : & mut PyProjectTomlMut ,
649- edits : & [ DependencyEdit < ' _ > ] ,
673+ edits : & [ DependencyEdit ] ,
650674 venv : & PythonEnvironment ,
651675 state : SharedState ,
652676 locked : bool ,
@@ -983,8 +1007,8 @@ impl Target {
9831007}
9841008
9851009#[ derive( Debug , Clone ) ]
986- struct DependencyEdit < ' a > {
987- dependency_type : & ' a DependencyType ,
1010+ struct DependencyEdit {
1011+ dependency_type : DependencyType ,
9881012 requirement : Requirement ,
9891013 source : Option < Source > ,
9901014 edit : ArrayEdit ,
0 commit comments