fix: support implicit table syntax in pyproject.toml parsing#5580
Conversation
|
@baszalmstra this fixes #5577, please have a look at it and let me know what you think. |
There was a problem hiding this comment.
Pull request overview
This PR updates pixi’s workspace discovery logic so pyproject.toml manifests using TOML implicit-table (dotted key) syntax under [tool.pixi] are treated equivalently to explicit table syntax, fixing workspace discovery failures reported in #5577.
Changes:
- Adjusted the “required sections” pre-check for
pyproject.tomlto recognize dotted keys likeworkspace.channels = .... - Added a new workspace-discovery fixture using implicit table syntax.
- Added/recorded a new insta snapshot for the implicit-table discovery case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/pixi_manifest/src/discovery.rs |
Updates the cheap pre-parse check to treat implicit-table syntax as satisfying required pixi sections; adds a new explicit discovery test case. |
tests/data/workspace-discovery/implicit-tables-pyproject/pyproject.toml |
New fixture demonstrating [tool.pixi] + dotted workspace.* keys. |
crates/pixi_manifest/src/snapshots/pixi_manifest__discovery__test__explicit_workspace_discoverer@implicit-tables-pyproject_pyproject.toml.snap |
New snapshot asserting discovery succeeds for the implicit-table fixture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| source.contains(&format!("[tool.pixi.{section}]")) | ||
| || source.contains(&format!("{section}.")) |
There was a problem hiding this comment.
The new implicit-table detection uses source.contains("{section}."), which is an unscoped substring match and can produce false positives (e.g. myworkspace.channels = ..., a comment/string containing workspace., or workspace.* keys outside [tool.pixi]). That would suppress the intended NoPixiTable diagnostic for explicit discovery. Consider tightening this to only match keys within the [tool.pixi] table and at the start of a key (e.g. line-based trim_start().starts_with("{section}.") within the [tool.pixi] table block), or preferably base the check on the already-parsed toml_span document (e.g. pointers under /tool/pixi/{section}) instead of raw string search.
| source.contains(&format!("[tool.pixi.{section}]")) | |
| || source.contains(&format!("{section}.")) | |
| // Explicit table: [tool.pixi.{section}] | |
| source.contains(&format!("[tool.pixi.{section}]")) | |
| // Implicit table: keys like `{section}.something` inside `[tool.pixi]` | |
| || { | |
| let mut in_pixi_table = false; | |
| source.lines().any(|line| { | |
| let trimmed = line.trim_start(); | |
| if trimmed.starts_with('[') { | |
| // Enter the top-level [tool.pixi] table; any other | |
| // table (including [tool.pixi.*]) ends it. | |
| if trimmed.starts_with("[tool.pixi]") { | |
| in_pixi_table = true; | |
| } else { | |
| in_pixi_table = false; | |
| } | |
| return false; | |
| } | |
| in_pixi_table | |
| && trimmed.starts_with(&format!("{section}.")) | |
| }) | |
| } |
Description
Allow pixi to recognize TOML implicit table syntax like:
[tool.pixi]
workspace.channels = ["conda-forge"]
Previously only explicit syntax was supported:
[tool.pixi.workspace]
channels = ["conda-forge"]
Both are valid TOML and should be treated equally.
Fixes #5577
How Has This Been Tested?
AI Disclosure
Tools: Claude
Checklist: