Skip to content

Commit

Permalink
feat: skip micromamba style selector lines and warn about them (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Feb 23, 2024
1 parent 50766b1 commit 256309a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
20 changes: 18 additions & 2 deletions src/utils/conda_environment_file.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -34,7 +34,23 @@ impl CondaEnvFile {
pub fn from_path(path: &Path) -> miette::Result<Self> {
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::<Result<Vec<String>, _>>()
.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)
}
}

0 comments on commit 256309a

Please sign in to comment.