From 60047b24a0e0692e4ee866198af39c6bc1dbf47d Mon Sep 17 00:00:00 2001 From: Olivier Lacroix Date: Sun, 31 Mar 2024 14:09:50 +1100 Subject: [PATCH] Add a "default" SolveGroup to the default Environment (if not redefined) --- docs/configuration.md | 7 +++++++ src/cli/init.rs | 1 - src/project/manifest/mod.rs | 23 +++++++++++++---------- src/project/solve_group.rs | 6 +++--- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 51f2d5454..e764e4d4e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -564,6 +564,13 @@ prod = {features = ["prod"], solve-group = "test"} lint = ["lint"] ``` +Unless the `default` environment is redefined, it is included in the `default` solve group. That is, the following is implied unless overridden in the manifest's `[environments]` table: +```toml title="default environment" +[environments] +default = { features = [], solve-group = "default" } # the default environment includes the 'default' feature only +``` + + ## Global configuration The global configuration options are documented in the [global configuration](advanced/global_configuration.md) section. diff --git a/src/cli/init.rs b/src/cli/init.rs index d2fd30c82..05b2b32e9 100644 --- a/src/cli/init.rs +++ b/src/cli/init.rs @@ -68,7 +68,6 @@ platforms = {{ platforms }} {%- if loop.first %} [tool.pixi.environments] -default = { features = [], solve-group = "default" } {%- endif %} {{env}} = { features = {{ features }}, solve-group = "default" } {%- endfor %} diff --git a/src/project/manifest/mod.rs b/src/project/manifest/mod.rs index 8cb16fe8f..ba9dd7b27 100644 --- a/src/project/manifest/mod.rs +++ b/src/project/manifest/mod.rs @@ -750,6 +750,17 @@ impl SolveGroups { pub fn iter(&self) -> impl Iterator + '_ { self.solve_groups.iter() } + + /// Inserts a SolveGroup based on a name and an environment index + pub fn insert(&mut self, name: &str, environment_idx: usize) -> usize { + let idx = self.solve_groups.len(); + self.solve_groups.push(SolveGroup { + name: name.to_string(), + environments: vec![environment_idx], + }); + self.by_name.insert(name.to_string(), idx); + idx + } } /// Describes the contents of a project manifest. @@ -1022,7 +1033,7 @@ impl<'de> Deserialize<'de> for ProjectManifest { name: EnvironmentName::Default, features: Vec::new(), features_source_loc: None, - solve_group: None, + solve_group: Some(solve_groups.insert("default", 0)), }); environments.by_name.insert(EnvironmentName::Default, 0); } @@ -1049,15 +1060,7 @@ impl<'de> Deserialize<'de> for ProjectManifest { .push(environment_idx); *idx } - None => { - let idx = solve_groups.solve_groups.len(); - solve_groups.solve_groups.push(SolveGroup { - name: solve_group.clone(), - environments: vec![environment_idx], - }); - solve_groups.by_name.insert(solve_group, idx); - idx - } + None => solve_groups.insert(&solve_group, environment_idx), }) } else { None diff --git a/src/project/solve_group.rs b/src/project/solve_group.rs index 32671a3af..d48c36ede 100644 --- a/src/project/solve_group.rs +++ b/src/project/solve_group.rs @@ -223,10 +223,10 @@ mod tests { let foo_environment = project.environment("foo").unwrap(); let bar_environment = project.environment("bar").unwrap(); - let solve_groups = project.solve_groups(); - assert_eq!(solve_groups.len(), 1); + let solve_groups = project.solve_groups(); // contains 'default', 'group1' + assert_eq!(solve_groups.len(), 2); - let solve_group = solve_groups[0].clone(); + let solve_group = solve_groups[1].clone(); // 'group1' solve group let solve_group_envs = solve_group.environments().collect_vec(); assert_eq!(solve_group_envs.len(), 2); assert_eq!(solve_group_envs[0].name(), "foo");