Skip to content

Commit

Permalink
Avoid creating Empty TOML tables
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-lacroix committed Apr 25, 2024
1 parent f7a5366 commit b1f0596
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 41 deletions.
41 changes: 21 additions & 20 deletions src/project/manifest/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl ManifestSource {

let mut current_table = self.as_table_mut();

for (i, part) in parts.iter().enumerate() {
for part in parts {
current_table = current_table
.entry(part)
.or_insert(Item::Table(Table::new()))
Expand All @@ -92,9 +92,8 @@ impl ManifestSource {
table_name
)
})?;
if i < parts.len() - 1 {
current_table.set_implicit(true);
}
// Avoid creating empty tables
current_table.set_implicit(true);
}
Ok(current_table)
}
Expand Down Expand Up @@ -407,22 +406,24 @@ mod tests {
let mut manifest = Manifest::from_str(Path::new("pixi.toml"), PROJECT_BOILERPLATE).unwrap();
let _ = manifest
.document
.get_or_insert_toml_table(None, &FeatureName::Default, "tasks");
let _ = manifest.document.get_or_insert_toml_table(
Some(Platform::Linux64),
&FeatureName::Default,
"tasks",
);
let _ = manifest.document.get_or_insert_toml_table(
None,
&FeatureName::Named("test".to_string()),
"tasks",
);
let _ = manifest.document.get_or_insert_toml_table(
Some(Platform::Linux64),
&FeatureName::Named("test".to_string()),
"tasks",
);
.get_or_insert_toml_table(None, &FeatureName::Default, "tasks")
.map(|t| t.set_implicit(false));
let _ = manifest
.document
.get_or_insert_toml_table(Some(Platform::Linux64), &FeatureName::Default, "tasks")
.map(|t| t.set_implicit(false));
let _ = manifest
.document
.get_or_insert_toml_table(None, &FeatureName::Named("test".to_string()), "tasks")
.map(|t| t.set_implicit(false));
let _ = manifest
.document
.get_or_insert_toml_table(
Some(Platform::Linux64),
&FeatureName::Named("test".to_string()),
"tasks",
)
.map(|t| t.set_implicit(false));
assert_snapshot!(manifest.document.to_string());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: src/project/manifest/mod.rs
expression: manifest.document.to_string()
---

[project]
name = "foo"
version = "0.1.0"
Expand All @@ -12,8 +11,5 @@ expression: manifest.document.to_string()
[dependencies]
fooz = "*"

[target.win-64.dependencies]

[target.linux-64.build-dependencies]
baz = "*"

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: src/project/manifest/mod.rs
expression: manifest.document.to_string()
---

[project]
name = "foo"
version = "0.1.0"
Expand All @@ -14,6 +13,3 @@ expression: manifest.document.to_string()

[target.win-64.dependencies]
bar = "*"

[target.linux-64.build-dependencies]

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
source: src/project/manifest/mod.rs
expression: manifest.document.to_string()
---

[project]
name = "foo"
version = "0.1.0"
channels = []
platforms = ["linux-64", "win-64"]

[dependencies]

[target.win-64.dependencies]
bar = "*"

[target.linux-64.build-dependencies]
baz = "*"

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ requests = "*"
xpackage = "==1.2.3"
ypackage = {version = ">=1.2.3"}

[feature.test.pypi-dependencies]

[feature.test.target.linux-64.pypi-dependencies]
feature_target_dep = "*"

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ ypackage = {version = ">=1.2.3"}

[feature.test.pypi-dependencies]
feature_dep = "*"

[feature.test.target.linux-64.pypi-dependencies]

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ platforms = ["linux-64", "win-64"]
[dependencies]
python = ">=3.12.1,<3.13"

[pypi-dependencies]

[target.win-64.pypi-dependencies]
jax = { version = "*", extras = ["cpu"] }
requests = "*"
Expand All @@ -26,4 +24,3 @@ feature_dep = "*"

[feature.test.target.linux-64.pypi-dependencies]
feature_target_dep = "*"

0 comments on commit b1f0596

Please sign in to comment.