MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / _element_lines

Function _element_lines

SLiCAP/schematic/netlist.py:35–78  ·  view source on GitHub ↗

Element lines (one per non-annotation component) in netlist order. Raises NetlistError if any unresolved "?" placeholder remains (missing value, model, reference or connection), so a netlist containing "?" — which would only make the SLiCAP parser fail later — is never produced. All

(components: list, node_fn)

Source from the content-addressed store, hash-verified

33
34
35def _element_lines(components: list, node_fn) -> list[str]:
36 """Element lines (one per non-annotation component) in netlist order.
37
38 Raises NetlistError if any unresolved "?" placeholder remains (missing
39 value, model, reference or connection), so a netlist containing "?" — which
40 would only make the SLiCAP parser fail later — is never produced. All
41 problems across all components are collected and reported together."""
42 lines: list[str] = []
43 errors: list[str] = []
44 for comp in components:
45 if comp.symbol_name in _ANNOTATION:
46 continue
47
48 pins = PIN_POSITIONS.get(comp.symbol_name, [])
49 nodes = [node_fn(comp, px, py) for px, py in pins]
50 refs = list(comp.refs)
51 model = comp.model
52 params = [(k, v) for k, v in comp.params.items() if v.strip()]
53
54 cid = comp.instance_id
55 if any("?" in n for n in nodes):
56 errors.append(f"{cid}: missing connection — '?' found in a node name.")
57 if any("?" in r for r in refs):
58 errors.append(f"{cid}: missing reference — '?' found in a referenced element name.")
59 if "?" in model:
60 errors.append(f"{cid}: missing model — '?' found in the model name.")
61 for k, v in params:
62 if "?" in v:
63 errors.append(f"{cid}: missing value — '?' found in parameter '{k}'.")
64
65 parts = [cid]
66 if nodes:
67 parts.extend(nodes)
68 if refs:
69 parts.extend(refs)
70 if model:
71 parts.append(model)
72 parts.extend(f"{k}={wrap_braces(v)}" for k, v in params)
73
74 lines.append(" ".join(parts))
75
76 if errors:
77 raise NetlistError(errors)
78 return lines
79
80
81def build_netlist(

Callers 2

build_netlistFunction · 0.85
build_subcircuitFunction · 0.85

Calls 2

wrap_bracesFunction · 0.85
NetlistErrorClass · 0.85

Tested by

no test coverage detected