diff --git a/src/cli/init.rs b/src/cli/init.rs index f022f42c2..5b7899d5e 100644 --- a/src/cli/init.rs +++ b/src/cli/init.rs @@ -375,13 +375,19 @@ mod tests { - pytorch::torchvision - conda-forge::pytest - wheel=0.31.1 + - sel(linux): blabla - pip: - requests - git+https://git@github.com/fsschneider/DeepOBS.git@develop#egg=deepobs - torch==1.8.1 "#; - let conda_env_file_data: CondaEnvFile = - serde_yaml::from_str(example_conda_env_file).unwrap(); + + let f = tempfile::NamedTempFile::new().unwrap(); + let path = f.path(); + let mut file = std::fs::File::create(path).unwrap(); + file.write_all(example_conda_env_file.as_bytes()).unwrap(); + + let conda_env_file_data = CondaEnvFile::from_path(path).unwrap(); assert_eq!(conda_env_file_data.name(), Some("pixi_example_project")); assert_eq!( diff --git a/src/utils/conda_environment_file.rs b/src/utils/conda_environment_file.rs index cd1557259..722c3b6a3 100644 --- a/src/utils/conda_environment_file.rs +++ b/src/utils/conda_environment_file.rs @@ -1,6 +1,6 @@ use miette::IntoDiagnostic; use serde::Deserialize; -use std::path::Path; +use std::{io::BufRead, path::Path}; #[derive(Deserialize, Debug, Clone)] pub struct CondaEnvFile { @@ -34,7 +34,23 @@ impl CondaEnvFile { pub fn from_path(path: &Path) -> miette::Result { let file = std::fs::File::open(path).into_diagnostic()?; let reader = std::io::BufReader::new(file); - let env_file = serde_yaml::from_reader(reader).into_diagnostic()?; + + let lines = reader + .lines() + .collect::, _>>() + .into_diagnostic()?; + let mut s = String::new(); + for line in lines { + if line.contains("- sel(") { + tracing::warn!("Skipping micromamba sel(...) in line: \"{}\"", line.trim()); + tracing::warn!("Please add the dependencies manually"); + continue; + } + s.push_str(&line); + s.push('\n'); + } + + let env_file = serde_yaml::from_str(&s).into_diagnostic()?; Ok(env_file) } }