Skip to content

feat(policy): data licensing policy + CI license gate (#174) - #184

Merged
gerchowl merged 1 commit into
mainfrom
feature/174-data-policy
May 5, 2026
Merged

gerchowl merged 1 commit into
mainfrom
feature/174-data-policy

Conversation

@gerchowl

@gerchowl gerchowl commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Lands the licensing policy + automated enforcement that turns the _sources.<key>.license field (added in #150) from "parsed" into "required for merge."

File Purpose
docs/data-policy.md (new) Full policy: legal context, allowed licenses, off-limits sources, attribution contract
scripts/check_licenses.py (new) stdlib-only CI gate; walks every _sources entry, blocks on missing/unknown/invalid license
.github/license-ratchet.txt (new) Empty placeholder for #175 audit window; self-deletes after audit
.pre-commit-config.yaml New check-licenses local hook on data/ + script/ + ratchet changes
.github/workflows/ci.yml New check-licenses job, threaded into summary.needs
CONTRIBUTING.md Provenance section rewritten — _sources example with license, off-limits summary
LICENSES-DATA.md (new) Generated initial state (no CC-BY sources yet)
tests/test_check_licenses.py (new) 16 tests for the gate

Allowed license values

CC0, PD-USGov, CC-BY-4.0, CC-BY-SA-4.0, proprietary-reference-only. The transitional value unknown is parseable but blocked at merge.

Audit-window strategy (per ADR-0003 §4)

.github/license-ratchet.txt ships empty. During #175 (the one-time corpus sweep), entries can be added as work-in-progress markers. The file MUST be deleted as the final step of #175 — ratchet rather than feature-flag-on-forever, so we can't accidentally leave the gate disabled.

Failure UX

Each error names file:material._sources.key and the offending value:

src/pymat/data/metals.toml:stainless._sources.mechanical.density: license='unknown' — must resolve before merge

Test plan

  • pytest tests/test_check_licenses.py — 16 tests pass
  • python scripts/check_licenses.py — passes against current corpus (no _sources blocks yet)
  • python scripts/check_licenses.py --emit-attributions — produces deterministic output
  • Full suite: 504 passed, 11 skipped, no regressions
  • ruff check clean
  • ruff format no diff

Risks / regressions considered

  1. Stdlib-only script — runs in pre-commit and CI without extra deps; no version drift surface.
  2. Path.relative_to(REPO_ROOT) in tests — handled by try/except ValueError fallback to absolute path so tmp_path test corpora work.
  3. Ratchet behavior — .github/license-ratchet.txt is read at runtime; # comments and blank lines ignored; ships empty.
  4. CI Summary — new job added to needs list and FAILED checks so a failing license gate blocks the rollup status check.
  5. Pre-commit language: python for the local hook — uses isolated interpreter; no need for pymat install.

Closes #174
Part of the schema foundation series: #150 (merged) → #149 (merged) → #148 (queued) → #174.

Lands the licensing policy + automated enforcement that turns the
`_sources.<key>.license` field (added in #150) from "parsed" into
"required for merge."

docs/data-policy.md:
- Legal context (Feist, EU sui generis)
- Allowed licenses: CC0, PD-USGov, CC-BY-4.0, CC-BY-SA-4.0,
  proprietary-reference-only (transitional `unknown` blocked at merge)
- Off-limits sources: MatWeb, CRC Handbook, ASM Handbook bulk,
  Engineering ToolBox, vendor PDFs
- LICENSES-DATA.md auto-generation contract

scripts/check_licenses.py (stdlib-only):
- Walks every `[<material>._sources]` entry across src/pymat/data/*.toml
  (recursively, including nested property-group sub-tables)
- Validates `license` field present + in allow-list, blocks merge on
  missing/unknown/invalid
- `--emit-attributions` mode prints LICENSES-DATA.md content to stdout
  (deterministic, sorted by citation, dedup'd by citation key)

.github/license-ratchet.txt:
- Empty placeholder for #175 audit window. Lists repo-relative TOML
  paths exempted from the gate. MUST be deleted as the final step
  of #175 — ratchet self-deletes rather than feature-flag-on-forever
  (per ADR-0003 §4).

CI wiring:
- .pre-commit-config.yaml: new `check-licenses` local hook (stdlib
  Python, no install needed) on changes to data TOMLs / script /
  ratchet
- .github/workflows/ci.yml: new `check-licenses` job + threaded into
  `summary.needs` so a failing license check blocks the merge

CONTRIBUTING.md: Provenance section rewritten — `_sources` table
example with `license` field, link to data-policy.md, off-limits
summary.

LICENSES-DATA.md: generated initial state (no CC-BY sources yet).

Tests: tests/test_check_licenses.py (16 tests) — empty corpus,
no-sources, valid license, missing license, unknown license,
invalid license, every allowed license, nested sources, ratchet
exemption, emit-attributions (no-CC, with-CC, dedup).

Closes #174
@gerchowl
gerchowl merged commit 00904ad into main May 5, 2026
19 checks passed
@gerchowl
gerchowl deleted the feature/174-data-policy branch May 5, 2026 11:27
@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.
gerchowl added a commit that referenced this pull request May 6, 2026
…) (#203)

Adds `scripts/enrich_from_nist_webbook.py`, a comparison + add-only
writeback enricher for the five fluids that overlap between
`src/pymat/data/{gases,liquids}.toml` and the NIST Chemistry WebBook:
water (liquid), nitrogen, argon, helium, co2 (gas).

NIST has no JSON API; the script hits the IsoBar TSV endpoint
(`fluid.cgi?Action=Data&Type=IsoBar`) at a fixed pressure of 1.01325
bar (1 atm) over a 5 K range straddling the target temperature, then
selects the row matching the target. Targets: T=293.15 K for water
(liquid phase), T=298.15 K for the gases (STP). The (T, P) point and
the `Lemmon REFPROP equation of state` provenance are pinned in every
`_sources.note`.

Properties enriched (only those already in the schema):
  * mechanical.density          (kg/m³ → g/cm³)
  * thermal.specific_heat       (J/(g·K) → J/(kg·K))
  * thermal.thermal_conductivity (W/(m·K), identity)

Viscosity is in the WebBook payload but the runtime schema has no
viscosity field today — skipped rather than invented. Temperature
curves are out of scope (separate Phase-4 follow-up).

Behaviour mirrors the other enrichers (#197/#198/#200/#201):
  * Default: comparison-only (DIFF threshold 2%).
  * --write: ADD-ONLY; existing values are NEVER overwritten.
  * --dry-run / --key / --report flags identical to the siblings.
  * Uses `cached_get_text` (30-day TTL) so NIST's polite-traffic
    expectations are respected; uses `build_source_row` and
    `writeback` from `scripts/_curation.py`.

`_sources` rows: license = "PD-USGov" (allow-listed since #184), kind
= "handbook", citation includes the species, ref pins
`webbook.nist.gov:fluid.cgi?ID=<CAS>`. The report footer carries the
NIST AS-IS notice. Attribution is not legally required for PD-USGov,
and `LICENSES-DATA.md` only enumerates CC-BY/CC-BY-SA sources, so no
edit there.

Live run against the 5 fluids: 0 MISSING (every field is already
curated), 1 DIFF (helium thermal_conductivity at 2.1% vs NIST
0.15531 W/(m·K)). The other 14 cells are within 2% of NIST. All
existing values are preserved.

Tests: `tests/test_nist_webbook_enrichment.py` (11 cases) covers TSV
parsing, fixture-based --dry-run (offline via monkeypatched
`cached_get_text`), --write add-only, no-overwrite semantics, comment
round-trip, --report file output, and the PD-USGov allow-list
canary. Fixture `tests/fixtures/nist_webbook_water.txt` holds a
trimmed real WebBook response (header + 2 rows) so the test suite
runs fully offline.

Closes #159
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.

Data-licensing policy: add docs/data-policy.md + CONTRIBUTING update

1 participant