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

feat: skip micromamba style selector lines and warn about them #830

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
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
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)
}
}
Loading