Skip to content

Commit

Permalink
fix: check duplicates while adding dependencies (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun authored Feb 23, 2024
1 parent 256309a commit dc4289e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/project/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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());

Expand Down

0 comments on commit dc4289e

Please sign in to comment.