Skip to content

Add .toml files to option "fromfile" support.#23196

Open
benjyw wants to merge 1 commit intopantsbuild:mainfrom
benjyw:fromfile_toml
Open

Add .toml files to option "fromfile" support.#23196
benjyw wants to merge 1 commit intopantsbuild:mainfrom
benjyw:fromfile_toml

Conversation

@benjyw
Copy link
Contributor

@benjyw benjyw commented Mar 24, 2026

As a reminder, the "fromfile" feature is where an
option value @path/to/file is read from that file.

If the file is .json or .yaml, we deserialize its content
to a list or dict, as needed.

This change adds support for .toml.

A top-level TOML entity must be a table (unlike
JSON/YAML which can have a top-level list).
So we only support this for dict-valued options.

@benjyw benjyw requested a review from tdyas March 24, 2026 05:11

fn try_deserialize<'a, DE: Deserialize<'a>>(
value: &'a str,
fn try_deserialize<DE: DeserializeOwned>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was necessary because toml serde requires it. All our objects own their strings anyway, so this was no loss.

ignore = "0.4.25"
indexmap = { version = "2.13.0", features = ["std", "serde"] }
indicatif = "0.18.4"
indoc = "2.0.7"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were already indirectly depending on indoc, so this does not introduce a new liability.

@benjyw
Copy link
Contributor Author

benjyw commented Mar 24, 2026

A future change will expand this to allow an option of any type to take its value from a specific location inside the .toml file. E.g., @pyproject.toml:project.required-python will take the value of [project].required-python in that toml file, so that you can keep your config in pyproject.toml if you want to, instead of repeating it in pants.toml.

@benjyw
Copy link
Contributor Author

benjyw commented Mar 25, 2026

Gentle ping on this, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants