Skip to content

Refactor netlist shortener#452

Merged
ducky64 merged 7 commits intomasterfrom
cleaner-netlist
Mar 15, 2026
Merged

Refactor netlist shortener#452
ducky64 merged 7 commits intomasterfrom
cleaner-netlist

Conversation

@ducky64
Copy link
Collaborator

@ducky64 ducky64 commented Mar 14, 2026

Instead of calculating the short path in the design crawl, this calculates it during netlist generation.

Also changes the algorithm to eliminate path components with no footprint-containing siblings. Previously, it approximated this, but was brittle to sub-blocks even if they contained no leaf footprints. This is needed for compositional passive, where there are going to be nested pseudoblocks.

Removes Pathname mode for netlisting. It's effectively superseded by PathnameAsValue mode.

Reference netlists are unchanged.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors netlist path shortening so it’s computed during KiCad netlist generation (instead of during the design crawl), and updates the shortening algorithm to be robust to nested pseudoblocks while removing the deprecated Pathname refdes mode.

Changes:

  • Replace precomputed NetBlock.path / NetBlock.class_path with NetBlock.path_classes (full-path, index-aligned) and introduce PathShortener to compute shortened paths at netlist emit time.
  • Remove RefdesMode.Pathname support and adjust KiCad netlist generation to always reference components by refdes.
  • Update unit tests’ expected NetBlock shapes and hierarchy class-path expectations.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
edg/electronics_model/NetlistGenerator.py Removes crawl-time short-path calculation; adds PathShortener; changes NetBlock schema to carry full-path classes.
edg/electronics_model/footprint.py Uses PathShortener during KiCad netlist generation; removes Pathname mode and short-path fields usage.
edg/electronics_model/NetlistBackend.py Removes backend argument mapping for the deleted pathName refdes mode.
edg/electronics_model/test_netlist.py Updates test helper constructor and expectations for full-path-aligned class lists.
edg/electronics_model/test_netlist_wrapper.py Updates wrapper netlist expectations to match new NetBlock structure.
edg/electronics_model/test_multipack_netlist.py Updates multipack netlist expectations for full-path class lists.
edg/electronics_model/test_bundle_netlist.py Updates bundle netlist expectations to match new NetBlock structure.
edg/electronics_model/test_partplacer.py Updates test fixtures to new NetBlock field name (path_classes).
edg/abstract_parts/test_kicad_import_netlist.py Updates KiCad import netlist expectations to match new NetBlock structure.
Comments suppressed due to low confidence (1)

edg/electronics_model/footprint.py:92

  • The block_exp docstring says it takes a dictionary of block names, but the function signature now takes a List[NetBlock] plus a PathShortener. Update the docstring to reflect the current inputs to avoid misleading future maintenance.
def block_exp(blocks: List[NetBlock], shortener: PathShortener, refdes_mode: RefdesMode) -> str:
    """Given a dictionary of block_names (strings) as keys and Blocks (namedtuples) as corresponding values

    Example:
    (components

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 146 to 168
@@ -170,7 +163,7 @@ def net_exp(nets: List[Net], blocks: List[NetBlock], refdes_mode: RefdesMode) ->
for i, net in enumerate(nets):
result += "\n" + gen_net_header(i + 1, net.name)
for pin in net.pins:
result += "\n " + gen_net_pin(block_name(block_dict[pin.block_path], refdes_mode), pin.pin_name)
result += "\n " + gen_net_pin(block_dict[pin.block_path].refdes, pin.pin_name)
result += ")"
return result + ")"
def shorten(
self, path: TransformUtil.Path, classes: List[edgir.LibraryPath]
) -> Tuple[List[str], List[edgir.LibraryPath]]:
assert len(path.blocks) == len(classes)
Comment on lines 21 to 31
def NetBlock(
footprint: str, refdes: str, part: str, value: str, full_path: List[str], path: List[str], class_path: List[str]
footprint: str, refdes: str, part: str, value: str, full_path: List[str], class_path: List[str]
) -> RawNetBlock:
return RawNetBlock(
footprint,
refdes,
part,
value,
TransformUtil.Path(tuple(full_path), (), (), ()),
path,
[edgir.libpath(cls) for cls in class_path],
)
Comment on lines 10 to 17
u1 = NetBlock(
footprint="Package_QFP:LQFP-48-1EP_7x7mm_P0.5mm_EP3.6x3.6mm",
refdes="U1",
part="",
value="",
full_path=TransformUtil.Path.empty().append_block("U1"),
path=[],
class_path=[],
path_classes=[],
)
Comment on lines 46 to 77
u1 = NetBlock(
footprint="Package_QFP:LQFP-48-1EP_7x7mm_P0.5mm_EP3.6x3.6mm",
refdes="U1",
part="",
value="",
full_path=TransformUtil.Path.empty().append_block("A").append_block("U1"),
path=[],
class_path=[],
path_classes=[],
)
r1 = NetBlock(
footprint="Resistor_SMD:R_0603_1608Metric",
refdes="R1",
part="",
value="",
full_path=TransformUtil.Path.empty().append_block("A").append_block("R1"),
path=[],
class_path=[],
path_classes=[],
)
r2 = NetBlock(
footprint="Resistor_SMD:R_0603_1608Metric",
refdes="R2",
part="",
value="",
full_path=TransformUtil.Path.empty().append_block("A").append_block("R2"),
path=[],
class_path=[],
path_classes=[],
)
r3 = NetBlock(
footprint="Resistor_SMD:R_0603_1608Metric",
refdes="R3",
part="",
value="",
full_path=TransformUtil.Path.empty().append_block("B").append_block("R3"),
path=[],
class_path=[],
path_classes=[],
)
Comment on lines 129 to 144
r1 = NetBlock(
footprint="Resistor_SMD:R_0603_1608Metric",
refdes="R1",
part="",
value="",
full_path=TransformUtil.Path.empty().append_block("R1"),
path=[],
class_path=[],
path_classes=[],
)
r2 = NetBlock(
footprint="Resistor_SMD:R_0603_1608Metric",
refdes="R2",
part="",
value="",
full_path=TransformUtil.Path.empty().append_block("R2"),
path=[],
class_path=[],
path_classes=[],
)
@ducky64 ducky64 merged commit 11ca30e into master Mar 15, 2026
12 checks passed
@ducky64 ducky64 deleted the cleaner-netlist branch March 15, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants