Skip to content

Commit 0983e96

Browse files
turbomamclaude
andcommitted
lint: address Copilot review on #460 (encoding, docstring, CURIE-parent DEF-FORM)
- check_definition_form now compares the genus only against LABEL-form parents; CURIE-form parents (governed by PARENT/HOUSE-STYLE) no longer trigger a spurious DEF-FORM mismatch. - baseline write_text/read_text use encoding='utf-8' for deterministic CI. - docstring corrected: the ratchet is '--baseline PATH --write-baseline'. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b0a8abc commit 0983e96

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

metpo/scripts/metpo_proposal_lint.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
via CURIE form, and definitions whose genus disagrees with the asserted parent
2121
(DEF-FORM; the hierarchy/label/definition compatibility principle, #64/#377).
2222
23-
Baseline ratchet: ``--write-baseline PATH`` records the currently-accepted findings;
23+
Baseline ratchet: ``--baseline PATH --write-baseline`` records the currently-accepted findings;
2424
a later run with ``--baseline PATH`` fails only on findings BEYOND that floor, so a
2525
large existing-debt audit can gate new additions without first paying down the debt.
2626
Regenerate the baseline as debt is fixed -- the count can only go down.
@@ -316,21 +316,25 @@ def check_definition_form(rid, typ, definition, parent_cell, mode):
316316
]
317317
genus = m.group(1).strip()
318318
glow = genus.lower()
319+
# CURIE-form parents (e.g. METPO:1000000) are governed by PARENT/HOUSE-STYLE;
320+
# the genus is compared only against LABEL-form parents (the sheet convention),
321+
# so a CURIE parent does not trigger a spurious DEF-FORM mismatch.
322+
label_parents = [p for p in parents if not re.match(r"^[A-Za-z][\w.]*:\S", p)]
319323
# Accept the parent label itself, or the parent label qualified as a head noun
320324
# ("a <parent> phenotype/preference in which ..."). For adjectival parents (e.g.
321325
# 'halophilic', 'anaerobic') the natural genus is "<parent> phenotype", which is
322326
# still hierarchy/label/definition compatible.
323327
_heads = ("phenotype", "preference", "quality")
324328
genus_ok = any(
325-
glow == p.lower() or glow in {f"{p.lower()} {h}" for h in _heads} for p in parents
329+
glow == p.lower() or glow in {f"{p.lower()} {h}" for h in _heads} for p in label_parents
326330
)
327-
if parents and not genus_ok:
331+
if label_parents and not genus_ok:
328332
return [
329333
Finding(
330334
sev,
331335
"DEF-FORM",
332336
rid,
333-
f"definition genus '{genus}' does not match asserted parent(s) {parents} "
337+
f"definition genus '{genus}' does not match asserted parent(s) {label_parents} "
334338
"(hierarchy/label/definition must be compatible)",
335339
)
336340
]
@@ -537,13 +541,15 @@ def _fp(f):
537541
if write_baseline:
538542
if not baseline:
539543
raise click.UsageError("--write-baseline requires --baseline PATH")
540-
Path(baseline).write_text(json.dumps(sorted({_fp(f) for f in findings}), indent=1) + "\n")
544+
Path(baseline).write_text(
545+
json.dumps(sorted({_fp(f) for f in findings}), indent=1) + "\n", encoding="utf-8"
546+
)
541547
click.echo(f"# wrote baseline: {baseline} ({len(findings)} findings recorded)")
542548
raise SystemExit(0)
543549

544550
baseline_set = set()
545551
if baseline and Path(baseline).exists():
546-
baseline_set = set(json.loads(Path(baseline).read_text()))
552+
baseline_set = set(json.loads(Path(baseline).read_text(encoding="utf-8")))
547553
new_findings = [f for f in findings if _fp(f) not in baseline_set]
548554
baselined = len(findings) - len(new_findings)
549555
# When a baseline is in play, only findings beyond it count toward pass/fail.

tests/test_metpo_proposal_lint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def test_cli_warn_only_exits_zero(tmp_path):
115115
"METPO:1007104\tin-which ok\towl:Class\ttrophic type\tA trophic type in which an organism fixes carbon.\tPMID:1\n"
116116
"METPO:1007105\tcharacterized ok\towl:Class\tcell shape\tA cell shape characterized by a rod morphology.\tPMID:1\n"
117117
"METPO:1007106\tparent phenotype genus\towl:Class\thalophilic\tA halophilic phenotype in which an organism requires high salt.\tPMID:1\n"
118+
"METPO:1007107\tcurie parent\towl:Class\tMETPO:9999999\tA phenotype that is observable.\tPMID:1\n"
118119
)
119120

120121

@@ -140,6 +141,8 @@ def test_def_form(tmp_path):
140141
# 'in which' / 'characterized by' are valid connectors when genus == parent
141142
assert "DEF-FORM" not in by_id.get("METPO:1007104", set())
142143
assert "DEF-FORM" not in by_id.get("METPO:1007105", set())
144+
# CURIE-form parent: genus comparison is skipped (PARENT/HOUSE-STYLE governs it)
145+
assert "DEF-FORM" not in by_id.get("METPO:1007107", set())
143146
# genus "<parent> phenotype" (adjectival parent) is accepted
144147
assert "DEF-FORM" not in by_id.get("METPO:1007106", set())
145148

0 commit comments

Comments
 (0)