main
John Lauer
Complete exact catalog links for all purchased PCB references and screen library pin sets
e3249a7
"""Read-only structural review of linked catalog libraries against board24.
Does not qualify manufacturer identity, pin functions, model fidelity or process.
"""
from pathlib import Path
import json,hashlib,collections,math
import sexp
root=Path(__file__).resolve().parents[1]
reg=json.loads((root/'aiflow/run/components.json').read_text())
board=sexp.parse((root/reg['board']).read_text())
fps={next(x[2] for x in sexp.find(f,'property') if x[1]=='Reference'):f for f in sexp.find(board,'footprint')}
def pads(f):
out=[]
for p in sexp.find(f,'pad'):
if not p[1]:continue
at=sexp.first(p,'at');sz=sexp.first(p,'size');dr=sexp.first(p,'drill')
out.append({'number':str(p[1]),'type':str(p[2]),'xy':[float(x) for x in at[1:3]],'size':[float(x) for x in sz[1:3]],'drill':[str(x) for x in dr[1:]] if dr else []})
return out
rows=[];groups=collections.defaultdict(list)
for c in reg['components']:
if c['review'].get('wikiPage'):groups[c['review']['wikiPage']].append(c['reference'])
for url,refs in groups.items():
slug=url.rsplit('/',1)[-1];local=root/'components'/slug;page=local/'page.json'
if not page.exists():page=root/'design/component-catalog-audit'/f'{slug}.page.json'
d=json.loads(page.read_text());parts=d['component']['parts'];assets={};issues=[]
for k in ['symbol','footprint']:
path=local/parts[k] if (local/parts[k]).exists() else root/'design/component-catalog-audit/assets'/slug/Path(parts[k]).name
if not path.exists():issues.append('Missing '+k);continue
assets[k]={'path':str(path.relative_to(root)),'sha256':hashlib.sha256(path.read_bytes()).hexdigest()}
row={'wikiPage':url,'references':refs,'mpn':d['component']['mpn'],'assets':assets,'issues':issues,'qualification':'not established'}
if len(assets)==2:
syms=sexp.lib_symbols(root/assets['symbol']['path']);pins={name:[{'number':n,'name':label} for n,label,*_ in sexp.pins(s)] for name,s in syms.items()};row['symbols']=pins
cp=pads(sexp.parse((root/assets['footprint']['path']).read_text()));cn={p['number'] for p in cp};sn={p['number'] for values in pins.values() for p in values};row['symbolFootprintPinSets']={'same':cn==sn,'symbolOnly':sorted(sn-cn),'footprintOnly':sorted(cn-sn)}
row['boardComparisons']={}
for ref in refs:
bp=pads(fps[ref]);bn={p['number'] for p in bp}
spacing=lambda pp:sorted(round(math.dist(a['xy'],b['xy']),4) for i,a in enumerate(pp) for b in pp[i+1:])
row['boardComparisons'][ref]={'padNumberMultisetSame':collections.Counter(p['number'] for p in bp)==collections.Counter(p['number'] for p in cp),'pairwiseSpacingSame':spacing(bp)==spacing(cp),'sizeMultisetSame':sorted(sorted(p['size']) for p in bp)==sorted(sorted(p['size']) for p in cp),'drillMultisetSame':sorted(p['drill'] for p in bp)==sorted(p['drill'] for p in cp),'pinNumberSetSame':bn==cn}
rows.append(row)
report={'board':reg['board'],'boardSha256':hashlib.sha256((root/reg['board']).read_bytes()).hexdigest(),'scope':'Structural catalog checks only. Spacing comparisons are not proof of number-to-position orientation or manufacturer pin functions. No gate mutation.','groups':rows}
out=root/'design/component-catalog-audit/current-assets-screen.json';out.write_text(json.dumps(report,indent=2)+'\n')
print(json.dumps({'groups':len(rows),'references':sum(len(x['references']) for x in rows),'missingAssets':[x['mpn'] for x in rows if x['issues']],'pinSetMismatches':[{'mpn':x['mpn'],'detail':x.get('symbolFootprintPinSets')} for x in rows if not x.get('symbolFootprintPinSets',{}).get('same')],'geometryDifferences':[x['mpn'] for x in rows if any(not all(c.values()) for c in x.get('boardComparisons',{}).values())]},indent=2))