Skip to content

Commit

Permalink
fix: default to the default environment if possible (prefix-dev#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts authored Mar 5, 2024
1 parent 035191e commit cd4b16c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/task/task_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'p, D: TaskDisambiguation<'p>> SearchEnvironments<'p, D> {
source: FindTaskSource<'p>,
) -> Result<TaskAndEnvironment<'p>, FindTaskError> {
// If no explicit environment was specified
if matches!(source, FindTaskSource::CmdArgs) && self.explicit_environment.is_none() {
if self.explicit_environment.is_none() {
let default_env = self.project.default_environment();
// If the default environment has the task
if let Ok(default_env_task) = default_env.task(&name, self.platform) {
Expand Down
57 changes: 57 additions & 0 deletions src/task/task_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,61 @@ mod test {
vec![r#"python train.py --cuda"#, r#"python test.py --cuda"#]
);
}

#[test]
fn test_multi_env_defaults() {
// It should select foobar and foo in the default environment
assert_eq!(
commands_in_order(
r#"
[project]
name = "pixi"
channels = ["conda-forge"]
platforms = ["linux-64", "osx-64", "win-64", "osx-arm64"]
[tasks]
foo = "echo foo"
foobar = { cmd = "echo bar", depends_on = ["foo"] }
[feature.build.tasks]
build = "echo build"
[environments]
build = ["build"]
"#,
&["foobar"],
None,
None
),
vec![r#"echo foo"#, r#"echo bar"#]
);
}

#[test]
#[should_panic]
fn test_multi_env_defaults_ambigu() {
// As foo is really ambiguous it should panic
commands_in_order(
r#"
[project]
name = "pixi"
channels = ["conda-forge"]
platforms = ["linux-64", "osx-64", "win-64", "osx-arm64"]
[tasks]
foo = "echo foo"
foobar = { cmd = "echo bar", depends_on = ["foo"] }
[feature.build.tasks]
build = "echo build"
foo = "echo foo abmiguity"
[environments]
build = ["build"]
"#,
&["foobar"],
None,
None,
);
}
}

0 comments on commit cd4b16c

Please sign in to comment.