Skip to content

feat: add from_data plugin for filling fields from TOML/JSON data files#84

Closed
henryiii wants to merge 1 commit into
mainfrom
feat/from-data-plugin
Closed

feat: add from_data plugin for filling fields from TOML/JSON data files#84
henryiii wants to merge 1 commit into
mainfrom
feat/from-data-plugin

Conversation

@henryiii

@henryiii henryiii commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Adds a bundled from_data plugin that fills a field from a structured data file: path names a .toml or .json file (format inferred from the extension, anything else is an error) and key is a dotted path into the parsed document (e.g. package.version from a Cargo.toml). Like ast, the value keeps its shape, so list/table fields fill directly; a table field can instead name one key after a dot in field (optional-dependencies.test), following from_file. Key segments containing a literal dot are not addressable (documented limitation), and a missing segment errors naming the failing segment.

This is also the first bundled exemplar of the optional build_state hook (a class provider stashing the state on self). The opt-in states setting is a flat list of build states validated against BUILD_STATES:

  • states absent: unconditional, identical to today — no behavior change.
  • Current state not in states: dynamic_metadata returns {}; the field stays in project.dynamic unresolved unless another entry provides it (the docs say to pair a gated entry with one covering the other states).
  • With states set, dynamic_wheel (stateless, per the loader contract) reports the field Dynamic for METADATA 2.2, since a gated field can differ between the SDist and wheel builds; without states nothing is dynamic.
  • field = "version" + states is a hard error — gating the version would leave it unresolvable in other states, and version may never be Dynamic.

The JSON schema needed no change: per-plugin settings are not modeled there (entries are additionalProperties: true).

Reads a value at a dotted key path from a .toml or .json file (format
inferred from the extension); like ast, the value keeps its shape so
list/table fields fill directly, and a table field can name one key
after a dot in 'field'.

Also the first bundled exemplar of the optional build_state hook: an
opt-in 'states' list gates the entry to specific build states. Gated
out, the entry contributes nothing and the field stays unresolved in
project.dynamic; with 'states' set, dynamic_wheel marks the field
Dynamic (METADATA 2.2) since it may differ between SDist and wheel
builds. 'version' combined with 'states' is a hard error, as gating
would leave it unresolvable in other states.

Assisted-by: ClaudeCode:claude-opus-4-8
@henryiii henryiii closed this Jul 3, 2026
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.

1 participant