Skip to content
Open
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
51 changes: 42 additions & 9 deletions crates/pixi_utils/src/conda_environment_file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use itertools::Itertools;
use miette::{Context, Diagnostic, IntoDiagnostic, NamedSource, SourceSpan};
use pixi_config::Config;
use pixi_config::{Config, default_channel_config};
use rattler_conda_types::{MatchSpec, NamedChannelOrUrl, ParseStrictness::Lenient};
use serde::Deserialize;
use std::collections::HashMap;
Expand Down Expand Up @@ -137,7 +137,18 @@ impl CondaEnvFile {
parse_dependencies(self.dependencies().clone())?;

channels.extend(extra_channels);
let mut channels: Vec<_> = channels.into_iter().unique().collect();
// Dedup by resolved base url: a name and its equivalent url don't compare equal.
let channel_config = default_channel_config();
let mut channels: Vec<_> = channels
.into_iter()
.unique_by(|channel| {
channel
.clone()
.into_base_url(&channel_config)
.map(|url| url.as_str().to_string())
.unwrap_or_else(|_| channel.as_str().to_string())
})
.collect();
if channels.is_empty() {
channels = config.default_channels();
}
Expand Down Expand Up @@ -248,6 +259,7 @@ mod tests {
let config = Config::default();
let (conda_deps, pip_deps, channels) = conda_env_file_data.to_manifest(&config).unwrap();

// `conda-forge` appears once despite the `conda-forge::pytest` dependency.
assert_eq!(
channels,
vec![
Expand All @@ -260,13 +272,6 @@ mod tests {
.as_str()
)
.unwrap(),
NamedChannelOrUrl::from_str(
Channel::from_str("conda-forge", &channel_config)
.unwrap()
.base_url
.as_str()
)
.unwrap(),
]
);

Expand Down Expand Up @@ -333,6 +338,34 @@ mod tests {
}
}

#[test]
fn test_import_dedups_channel_declared_by_name_and_referenced_by_dependency_prefix() {
let example_conda_env_file = r#"
name: bismark
channels:
- conda-forge
- bioconda
dependencies:
- bioconda::bismark=3.1.0
"#;

let mut f = tempfile::NamedTempFile::new().unwrap();
f.write_all(example_conda_env_file.as_bytes()).unwrap();
let (_file, path) = f.into_parts();

let conda_env_file_data = CondaEnvFile::from_path(&path).unwrap();
let config = Config::default();
let (_, _, channels) = conda_env_file_data.to_manifest(&config).unwrap();

assert_eq!(
channels,
vec![
NamedChannelOrUrl::from_str("conda-forge").unwrap(),
NamedChannelOrUrl::from_str("bioconda").unwrap(),
]
);
}

#[test]
fn test_parse_conda_env_file_with_explicit_pip_dep() {
let example_conda_env_file = r#"
Expand Down
Loading