main
John Lauer
Review component pin functions and validate isolated library model and hole corrections
7fb4d36
"""Restore the missing exact MPN in a separate board candidate; no native mutation."""
from pathlib import Path
import hashlib,json,uuid
import sexp
root=Path(__file__).resolve().parents[1]
src=root/'aiflow/run/board-24.kicad_pcb'
out=root/'checkpoints/library-metadata-review'
raw=src.read_bytes();tree=sexp.parse(raw.decode())
fp=next(f for f in sexp.find(tree,'footprint') if any(p[1:3]==['Reference','D1'] for p in sexp.find(f,'property')))
props={p[1]:p[2] for p in sexp.find(fp,'property')}
assert 'MPN' not in props and props['Value']=='SBR10U45SP5-13'
assert fp[1]=='Load:SBR10U45SP5-13'
start=raw.index(b'\t(footprint "Load:SBR10U45SP5-13"')
end=raw.index(b'\t\t(attr smd)',start)
nl=b'\r\n' if b'\r\n' in raw else b'\n'
uid=str(uuid.uuid5(uuid.NAMESPACE_URL,'adom-custom-electronic-load/D1/MPN'))
addition=('\t\t(property "MPN" "SBR10U45SP5-13"\n'
'\t\t\t(at 0 0 180)\n\t\t\t(layer "F.Fab")\n\t\t\t(hide yes)\n'
f'\t\t\t(uuid "{uid}")\n'
'\t\t\t(effects (font (size 1 1) (thickness 0.15)))\n\t\t)\n').encode().replace(b'\n',nl)
result=raw[:end]+addition+raw[end:]
assert result.replace(addition,b'',1)==raw
candidate=out/'d1-mpn-candidate.kicad_pcb';candidate.write_bytes(result)
new=sexp.parse(result.decode())
newfp=next(f for f in sexp.find(new,'footprint') if any(p[1:3]==['Reference','D1'] for p in sexp.find(f,'property')))
prop=next(p for p in sexp.find(newfp,'property') if p[1]=='MPN');newfp.remove(prop)
assert new==tree
report={'source':str(src.relative_to(root)),'sourceSha256':hashlib.sha256(raw).hexdigest(),'candidate':str(candidate.relative_to(root)),'candidateSha256':hashlib.sha256(result).hexdigest(),'finding':'D1 dedicated MPN property missing; Value and footprint already exact SBR10U45SP5-13','change':'Add hidden MPN property only','bytePreservationOutsideInsertion':True,'parsedBoardUnchangedExceptProperty':True,'nativeApplied':False,'nativeValidation':'pending','qualification':'No electrical, thermal, geometry or manufacturing qualification implied'}
(out/'review.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report,indent=2))