Repository navigation
feat(schema): add _sources provenance table (#150) - #182
Merged
Merged
Conversation
Adds [<material>._sources] TOML support for keyed-by-property-path
provenance with `_default` fallback and parent-overlay inheritance.
New module `pymat.sources` defines `Source` (frozen dataclass) and
short-alias resolution (`density` -> `mechanical.density`).
Public API:
- `mat.source_of("mechanical.density")` -> Source | None
- `mat.cite("density")` -> BibTeX entry
- `mat.cite()` -> all sources used by this material, deduplicated
Loader changes (src/pymat/loader.py):
- Explicit `_`-prefix skip in update_properties (was implicit
hasattr() no-op; now documented and prevents silent bug class)
- Parse `_sources` table in _resolve_material_node with
parent-overlay inheritance
Schema choice recorded in docs/decisions/0003-schema-foundation.md
(consolidated from 3 parallel reviews). `mat.density.source`
accessor proposed in #150 was rejected as a direct break of
existing float arithmetic in core.py:403, MCP compute_mass, and
the *_qty Pint properties — `mat.source_of()` and `mat.cite()`
accomplish the same goal additively.
Tests: tests/test_sources.py (16 tests covering parsing,
inheritance, fallback, dedup, BibTeX emission for DOI/QID).
Full suite: 488 passed, 11 skipped, no regressions.
Closes #150
6 tasks
3 tasks done
gerchowl
added a commit
that referenced
this pull request
May 6, 2026
Bundles four schema-foundation feats merged after 3.9.0 plus the Vis public-API clarification into a single release: - feat(schema): _sources provenance table (#150 / #182) - feat(schema): _stddev sibling sugar + ufloat boundary helper (#149 / #183) - feat(policy): data licensing policy + CI license gate (#174 / #184) - feat(schema): T-dependent property curves (#148 / #185) - fix(vis): declare Vis as public API (#98 / #186) Three feats × one fix → minor version bump per semver. The version 3.9.1 originally proposed for the Vis public-API change alone became inconsistent once the four schema feats had landed on main without their own release cut, so they're rolled into 3.10.0 honestly rather than shipped as a misleading patch. CHANGELOG entry for 3.10.0 covers all five items with PR + issue links. .release-please-manifest.json synced to 3.10.0 so the open release-please PR (#80) recomputes correctly going forward.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
[<material>._sources]TOML support for keyed-by-property-path provenance with_defaultfallback and parent-overlay inheritance — the foundation of the schema-expansion milestone.New module
pymat.sourcesdefines:Source(frozen dataclass):citation,kind,ref,license,notedensity→mechanical.density)parse_sources_table/merge_sourceshelpersNew
MaterialAPI:mat.source_of("mechanical.density")→Source | None(resolves_defaultfallback)mat.cite("density")→ BibTeX entry (@miscfor DOI / Wikidata QID / handbook / vendor)mat.cite()→ all sources used by this material, deduplicated by citation keyChanges
src/pymat/sources.py(new)Sourcedataclass, BibTeX emitter, alias table, parserssrc/pymat/core.pyMaterial._sourcesfield;source_of()andcite()methodssrc/pymat/loader.py_-prefix skip inupdate_properties;_sourcesparsing in_resolve_material_nodewith parent-overlay inheritancetests/test_sources.py(new)tests/test_toml_integrity.py_walk_unknown_groupsnow skips reserved underscore keysdocs/decisions/0003-schema-foundation.md(new)Design notes (ADR-0003)
The original issue proposed
mat.density.sourceas the accessor. Rejected because it would changemat.densityfromfloatto a wrapper object — direct break ofcore.py:403(density / 1000),clients/python/pymat-mcp/src/pymat_mcp/tools.py:300(compute_mass), and the*_qtyPint quantity layer (~50 call sites).mat.source_of()andmat.cite()accomplish the same goal additively, with zero changes to existing arithmetic.License field is parsed but not validated in this PR — enforcement comes in #174.
Test plan
pytest tests/test_sources.py— 16 new tests passpytest tests/(full suite minus visual-regression) — 488 passed, 11 skipped, zero regressionsruff checkclean on changed filesruff formatno diffcore.py/loader.py, unrelated to this PR)Risks / regressions considered
AllProperties— explicit testtest_sources_dont_leak_into_propertiesplus loader-levelif key.startswith("_"): continue._sources— fully backwards-compatible;_sourcesdefaults to empty dict; no API surface changes for materials that don't use it.Material.copy()propagation of_sources—_sourceslives on_MaterialInternalas a dataclass field, sodeepcopy(material)carries it for free. Verified bytest_child_overlays_parent._walk_unknown_groupsnow skips underscore-prefixed keys at material-node level (was implicit pass via heuristic; now explicit).Closes #150
Part of the schema foundation series (PR sequence per ADR-0003): #150 → #149 → #148 → #174.