main
John Lauer Review cumulative land candidates and correct complete STEP assembly clearance checks ca3da55
"""Prepare isolated F1/D4 manufacturer land variants; preserve selected bodies and nets."""
from pathlib import Path
import copy,json,hashlib,shutil
import sexp
R=Path(__file__).resolve().parents[1];B=R/'checkpoints/capacitor-library-review';O=R/'checkpoints/fuse-diode-land-review';O.mkdir(exist_ok=True);src=B/'capacitor-land-candidate.kicad_pcb';S=sexp.Sym
spec={'F1':('0466005-nr','Fuse_1206_Littelfuse_466'),'D4':('b140-13-f','D_SMA_Diodes_B140')}
for d in ['lib','3d']:shutil.copytree(B/d,O/d,dirs_exist_ok=True)
shutil.copy2(B/'fp-lib-table',O/'fp-lib-table')
for ext in ['kicad_pro','kicad_dru']:shutil.copy2(B/('capacitor-land-candidate.'+ext),O/('fuse-diode-land-candidate.'+ext))
b=sexp.parse(src.read_text());rows=[]
for f in sexp.find(b,'footprint'):
 pr={p[1]:p[2]for p in sexp.find(f,'property')};ref=pr['Reference']
 if ref not in spec:continue
 slug,name=spec[ref];cp=R/'components'/slug/(slug+'.kicad_mod');cat=sexp.parse(cp.read_text());pads={p[1]:p for p in sexp.find(cat,'pad')};assert set(pads)=={'1','2'};before=[]
 for p in sexp.find(f,'pad'):
  q=pads[p[1]];a=sexp.first(p,'at');sz=sexp.first(p,'size');before.append({'number':p[1],'at':a[1:],'size':sz[1:]});a[1:3]=copy.deepcopy(sexp.first(q,'at')[1:3]);sz[1:]=copy.deepcopy(sexp.first(q,'size')[1:]);p[3]=q[3];p[:]=[v for v in p if not(isinstance(v,list)and v and v[0]=='roundrect_rratio')];p.extend(copy.deepcopy(sexp.find(q,'roundrect_rratio')))
 f[1]='Load:'+name;sexp.first(f,'descr')[1]='Manufacturer recommended lands from exact component catalog. See fuse-diode-land-review; physical process qualification pending.'
 lib=copy.deepcopy(f);lib[1]=name;lib[:]=[v for v in lib if not(isinstance(v,list)and v and(v[0]in ['at','uuid']or(v[0]=='property'and v[1]not in ['Reference','Value','Datasheet','Description'])))]
 for p in sexp.find(lib,'property'):
  if p[1]=='Reference':p[2]='REF**';sexp.first(p,'at')[1:]=[S('0'),S('-2'),S('0')]
  if p[1]=='Value':p[2]=name
 for p in sexp.find(lib,'pad'):
  a=sexp.first(p,'at');a[1:]=a[1:3];p[:]=[v for v in p if not(isinstance(v,list)and v and v[0]in ['net','uuid'])]
 (O/'lib/Load.pretty'/(name+'.kicad_mod')).write_text(sexp.dump(lib)+'\n')
 rows.append({'reference':ref,'mpn':pr['MPN'],'before':before,'catalogFootprintSha256':hashlib.sha256(cp.read_bytes()).hexdigest(),'binding':f[1],'modelChanged':False})
assert len(rows)==2
for z in sexp.find(b,'zone'):z[:]=[v for v in z if not(isinstance(v,list)and v and v[0]=='filled_polygon')]
dst=O/'fuse-diode-land-candidate.kicad_pcb';dst.write_text(sexp.dump(b)+'\n')
for p in B.glob('*.kicad_sch'):
 t=sexp.parse(p.read_text())
 for sy in sexp.find(t,'symbol'):
  pr={v[1]:v for v in sexp.find(sy,'property')};ref=pr.get('Reference',[None,None,None])[2]
  if ref in spec:pr['Footprint'][2]='Load:'+spec[ref][1]
 (O/p.name).write_text(sexp.dump(t)+'\n')
x={'adopted':False,'sourceSha256':hashlib.sha256(src.read_bytes()).hexdigest(),'candidateSha256':hashlib.sha256(dst.read_bytes()).hexdigest(),'inheritedUnadoptedFootprintChanges':36,'references':rows,'sourceReviews':['components/0466005-nr/provenance.json','components/b140-13-f/provenance.json'],'limits':'No placement, copper routing, net or selected-model changes. No native visual or physical qualification and no gate advancement.'};(O/'selection-review.json').write_text(json.dumps(x,indent=2)+'\n');print('Prepared F1/D4 manufacturer land variants; cumulative38unadopted footprint changes')