Skip to content

feat(schema): add _sources provenance table (#150) - #182

Merged
gerchowl merged 2 commits into
mainfrom
feature/150-sources-table
May 5, 2026
Merged

gerchowl merged 2 commits into
mainfrom
feature/150-sources-table

Conversation

@gerchowl

@gerchowl gerchowl commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds [<material>._sources] TOML support for keyed-by-property-path provenance with _default fallback and parent-overlay inheritance — the foundation of the schema-expansion milestone.

New module pymat.sources defines:

  • Source (frozen dataclass): citation, kind, ref, license, note
  • Short-alias resolution (density → mechanical.density)
  • parse_sources_table / merge_sources helpers

New Material API:

  • mat.source_of("mechanical.density") → Source | None (resolves _default fallback)
  • mat.cite("density") → BibTeX entry (@misc for DOI / Wikidata QID / handbook / vendor)
  • mat.cite() → all sources used by this material, deduplicated by citation key

Changes

File What
src/pymat/sources.py (new) Source dataclass, BibTeX emitter, alias table, parsers
src/pymat/core.py Material._sources field; source_of() and cite() methods
src/pymat/loader.py Explicit _-prefix skip in update_properties; _sources parsing in _resolve_material_node with parent-overlay inheritance
tests/test_sources.py (new) 16 tests: parsing, inheritance, fallback, dedup, BibTeX emission
tests/test_toml_integrity.py _walk_unknown_groups now skips reserved underscore keys
docs/decisions/0003-schema-foundation.md (new) ADR consolidating 3 parallel reviews — covers #150, #149, #148, #174 design

Design notes (ADR-0003)

The original issue proposed mat.density.source as the accessor. Rejected because it would change mat.density from float to a wrapper object — direct break of core.py:403 (density / 1000), clients/python/pymat-mcp/src/pymat_mcp/tools.py:300 (compute_mass), and the *_qty Pint quantity layer (~50 call sites). mat.source_of() and mat.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 pass
  • pytest tests/ (full suite minus visual-regression) — 488 passed, 11 skipped, zero regressions
  • ruff check clean on changed files
  • ruff format no diff
  • mypy clean on new code (5 errors are pre-existing in core.py/loader.py, unrelated to this PR)

Risks / regressions considered

  1. Underscore keys leaking into AllProperties — explicit test test_sources_dont_leak_into_properties plus loader-level if key.startswith("_"): continue.
  2. Existing TOMLs without _sources — fully backwards-compatible; _sources defaults to empty dict; no API surface changes for materials that don't use it.
  3. Material.copy() propagation of _sources — _sources lives on _MaterialInternal as a dataclass field, so deepcopy(material) carries it for free. Verified by test_child_overlays_parent.
  4. TOML integrity check — _walk_unknown_groups now 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.

gerchowl added 2 commits May 5, 2026 12:44
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
@gerchowl
gerchowl merged commit 1dfa484 into main May 5, 2026
18 checks passed
@gerchowl
gerchowl deleted the feature/150-sources-table branch May 5, 2026 11:07
@vig-os-release-app vig-os-release-app Bot mentioned this pull request May 5, 2026
6 tasks
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.
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.

Schema: [<material>._sources] provenance table

1 participant