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: Handle custom channels when importing from env yaml #901

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Changes from 2 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
39 changes: 22 additions & 17 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,25 @@
let channels = parse_channels(env_info.channels().clone());
let (conda_deps, pip_deps, mut extra_channels) =
parse_dependencies(env_info.dependencies().clone())?;
let channel_config = ChannelConfig::default();
extra_channels.extend(
channels
.into_iter()
.map(|c| Arc::new(Channel::from_str(c, &ChannelConfig::default()).unwrap())),
.map(|c| Arc::new(Channel::from_str(c, &channel_config).unwrap())),
);
let mut channels: Vec<_> = extra_channels
.into_iter()
.unique()
.map(|c| c.name().to_string())
.map(|c| {
if c.base_url()
.as_str()
.starts_with(channel_config.channel_alias.as_str())
{
c.name().to_string()
} else {
c.base_url().to_string()
}
})
.collect();
if channels.is_empty() {
channels = DEFAULT_CHANNELS
Expand Down Expand Up @@ -369,8 +379,7 @@
mod tests {
use super::*;
use crate::cli::init::get_dir;
use itertools::Itertools;

Check failure on line 382 in src/cli/init.rs

View workflow job for this annotation

GitHub Actions / Linux-x86_64

unused import: `itertools::Itertools`

Check failure on line 382 in src/cli/init.rs

View workflow job for this annotation

GitHub Actions / macOS-x86_64

unused import: `itertools::Itertools`

Check failure on line 382 in src/cli/init.rs

View workflow job for this annotation

GitHub Actions / Windows-x86_64

unused import: `itertools::Itertools`
use rattler_conda_types::ChannelConfig;
use std::io::Read;
use std::path::{Path, PathBuf};
use tempfile::tempdir;
Expand All @@ -381,6 +390,7 @@
name: pixi_example_project
channels:
- conda-forge
- https://custom-server.com/channel
dependencies:
- python
- pytorch::torchvision
Expand All @@ -403,26 +413,21 @@
assert_eq!(conda_env_file_data.name(), Some("pixi_example_project"));
assert_eq!(
conda_env_file_data.channels(),
&vec!["conda-forge".to_string()]
&vec![
"conda-forge".to_string(),
"https://custom-server.com/channel".to_string()
]
);

let (conda_deps, pip_deps, mut channels) =
parse_dependencies(conda_env_file_data.dependencies().clone()).unwrap();

channels.extend(
conda_env_file_data
.channels()
.into_iter()
.map(|c| Arc::new(Channel::from_str(c, &ChannelConfig::default()).unwrap())),
);
let channels = channels.into_iter().unique().collect::<Vec<_>>();
let (conda_deps, pip_deps, channels) = conda_env_to_manifest(conda_env_file_data).unwrap();

assert_eq!(
channels,
vec![
Arc::new(Channel::from_str("pytorch", &ChannelConfig::default()).unwrap()),
Arc::new(Channel::from_str("conda-forge", &ChannelConfig::default()).unwrap())
],
"pytorch".to_string(),
"conda-forge".to_string(),
"https://custom-server.com/channel/".to_string()
]
);

println!("{conda_deps:?}");
Expand Down
Loading