main
John Lauer
Adopt native-reviewed marked IC models and retain shared catalog repairs with inspection clip
d7a7dc9
"""Bind reviewed exact-MPN marked models; change no electrical geometry."""
from pathlib import Path
import json,copy,shutil,hashlib
import sexp
root=Path(__file__).resolve().parents[1];src=root/'aiflow/run/board-25.kicad_pcb';out=root/'checkpoints/marked-ic-review';out.mkdir(exist_ok=True)
entries={'U1':('stm32g0b1kct6','stm32g0b1kct6.step'),'U2':('dac60501zdgsr','dac60501zdgsr-etched.step'),'U3':('opa189idbvr','opa189idbvr-marked.step'),'U4':('ina226aidgst','ina226aidgst-etched.step'),'U5':('tps61040dbvr','tps61040dbvr-etched.step'),'U6':('stwd100nywy3f','stwd100nywy3f-etched.step'),'U7':('lm339bidr','lm339bidr.step'),'U8':('sn74lvc1g175dbvr','sn74lvc1g175dbvr-etched.step'),'U9':('tlv75533pdbvr','tlv75533pdbvr-etched.step'),'U10':('usblc6-2sc6','usblc6-2sc6-etched.step')}
for folder in ['3d','lib']:shutil.copytree(root/'aiflow/run'/folder,out/folder,dirs_exist_ok=True)
shutil.copyfile(root/'aiflow/run/fp-lib-table',out/'fp-lib-table')
b=sexp.parse(src.read_text());old=copy.deepcopy(b);rows=[]
for f in sexp.find(b,'footprint'):
props={p[1]:p[2] for p in sexp.find(f,'property')};ref=props['Reference']
if ref not in entries:continue
slug,name=entries[ref];p=root/'components'/slug/name;assert p.is_file(),p
model=sexp.find(f,'model');assert len(model)==1,(ref,model)
oldpath=model[0][1];model[0][1]='${KIPRJMOD}/3d/'+name;shutil.copyfile(p,out/'3d'/name)
rows.append({'reference':ref,'mpn':props['MPN'],'source':str(p.relative_to(root)),'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'oldBinding':oldpath,'newBinding':model[0][1],'transformsUnchanged':True})
assert len(rows)==10
board=out/'marked-ic-candidate.kicad_pcb';board.write_text(sexp.dump(b)+'\n');assert sexp.parse(board.read_text())==b
for f in sexp.find(b,'footprint'):
ref=next(p[2] for p in sexp.find(f,'property') if p[1]=='Reference')
if ref in entries:sexp.find(f,'model')[0][1]=next(r['oldBinding'] for r in rows if r['reference']==ref)
assert b==old,'Unexpected non-model edit'
for ext in ['kicad_pro','kicad_dru']:shutil.copyfile(src.with_suffix('.'+ext),board.with_suffix('.'+ext))
r={'source':str(src.relative_to(root)),'sourceSha256':hashlib.sha256(src.read_bytes()).hexdigest(),'candidateSha256':hashlib.sha256(board.read_bytes()).hexdigest(),'electricalGeometryUnchanged':True,'components':rows,'nativeReview':'pending','adopted':False,'scope':'Virtual identification; not factory marking or physical qualification. USBLC source corrected; registry release pending.'}
(out/'selection-review.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps({'candidate':str(board),'icCount':len(rows),'electricalGeometryUnchanged':True}))