Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check duplicates while adding dependencies #829

Merged
merged 5 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading