From f11d453c31a7ad85bb10ce1370417c5336c0a51a Mon Sep 17 00:00:00 2001 From: Eugene Mikhantyev Date: Sun, 26 Apr 2026 15:13:47 +0100 Subject: [PATCH] Tidy auto-junction-sync code - Refactor _handle_rotate_schematic_component to use raw sexp throughout and write the schematic once instead of three times - Hoist sexpdata and WireManager imports to module scope; drop the unnecessary underscore aliases in move/rotate handlers - Move WireManager._SUB_UNIT_RE to the top of the class body - Promote the per-call Symbol("symbol")/Symbol("unit") allocations in _parse_lib_pins / _collect_pin_positions to module-level _SYM_* constants - Document the assumption behind _SUB_UNIT_RE's greedy match Co-Authored-By: Claude Opus 4.7 --- python/commands/wire_manager.py | 20 +++--- python/kicad_interface.py | 104 ++++++++++++++++++++------------ 2 files changed, 76 insertions(+), 48 deletions(-) diff --git a/python/commands/wire_manager.py b/python/commands/wire_manager.py index 20c3043..bcbc257 100644 --- a/python/commands/wire_manager.py +++ b/python/commands/wire_manager.py @@ -37,6 +37,8 @@ _SYM_LIB_SYMBOLS = Symbol("lib_symbols") _SYM_LIB_ID = Symbol("lib_id") _SYM_MIRROR = Symbol("mirror") _SYM_PIN = Symbol("pin") +_SYM_SYMBOL = Symbol("symbol") +_SYM_UNIT = Symbol("unit") _IU_PER_MM = 10000 @@ -127,6 +129,11 @@ def _make_sheet_pin_text( class WireManager: """Manage wires in KiCad schematics using S-expression manipulation""" + # Regex to parse sub-unit names like "LM324_2_1" → (base="LM324", unit=2, style=1) + # The sub-unit suffix is __