import csv from math import ceil from pathlib import Path from typing import List from ee.part.bom import load_bom, check_bom, generate_bom, join_refs __all__ = ["create_bom"] def create_bom(bom_path: Path, part_files: List[Path], out_path: Path, allow_incomplete, quantity: float): bom_parts, supplier_parts = load_bom(bom_path, part_files) check_bom(bom_parts, supplier_parts) bom = generate_bom(allow_incomplete, bom_parts, supplier_parts) if bom is None: return with out_path.open("w") as f: w = csv.writer(f) w.writerow(["Digi-Key Part Number", "Manufacturer Part Number", "Quantity", "Reference Designator"]) for line in bom.lines: line = [ line.part.get_exactly_one_spn().valueProp, line.part.get_exactly_one_mpn().valueProp, int(ceil(len(line.refs) * quantity)), join_refs(line.refs)] w.writerow([str(cell) for cell in line])