diff --git a/src/project/manifest/mod.rs b/src/project/manifest/mod.rs index 9d57f7195..a03f3a429 100644 --- a/src/project/manifest/mod.rs +++ b/src/project/manifest/mod.rs @@ -355,8 +355,18 @@ impl Manifest { miette::bail!("pixi does not support wildcard dependencies") }; + // Check for duplicates. + if let Some(table_spec) = dependency_table.get(name.as_normalized()) { + if table_spec.as_value().and_then(|v| v.as_str()) == Some(&spec.to_string()) { + return Err(miette::miette!( + "{} is already added.", + console::style(name.as_normalized()).bold(), + )); + } + } + // Store (or replace) in the document - dependency_table.insert(name.as_source(), Item::Value(spec.to_string().into())); + dependency_table.insert(name.as_normalized(), Item::Value(spec.to_string().into())); // Add the dependency to the manifest as well self.default_feature_mut() @@ -384,6 +394,16 @@ impl Manifest { consts::PYPI_DEPENDENCIES, )?; + // Check for duplicates. + if let Some(table_spec) = dependency_table.get(name.as_str()) { + if table_spec.to_string().trim() == requirement.to_string() { + return Err(miette::miette!( + "{} is already added.", + console::style(name.as_source_str()).bold(), + )); + } + } + // Add the pypi dependency to the table dependency_table.insert(name.as_str(), (*requirement).clone().into());