Bug
add_global_label() stores data correctly into _data["global_label"], but _schematic_data_to_sexp() in core/parser.py never iterates over that key. The data is silently dropped on save().
Reproducer
import kicad_sch_api as ksa
sch = ksa.create_schematic("test")
sch.add_global_label(text="NRESET", position=(80, 50), shape="bidirectional")
sch.save_as("test.kicad_sch")
with open("test.kicad_sch") as f:
content = f.read()
assert "global_label" in content # FAILS — no global_label in output
Root cause
_schematic_data_to_sexp() has loops for labels, hierarchical_labels, no_connects, etc. but no loop for global_label:
# These exist:
for label in schematic_data.get("labels", []):
sexp_data.append(self._label_to_sexp(label))
for hlabel in schematic_data.get("hierarchical_labels", []):
sexp_data.append(self._hierarchical_label_to_sexp(hlabel))
# This is missing:
# for glabel in schematic_data.get("global_label", []):
# sexp_data.append(self._global_label_to_sexp(glabel))
Additionally, label_parser.py has _label_to_sexp() and _hierarchical_label_to_sexp() but no _global_label_to_sexp().
The save() method in schematic.py also lacks a _sync_global_labels_to_data() call (though the text_element_manager writes directly to _data, so sync may not be strictly needed — the serializer loop is the primary gap).
Expected fix
- Add
_global_label_to_sexp() to label_parser.py (same format as _hierarchical_label_to_sexp(), just global_label tag)
- Add the iteration loop in
_schematic_data_to_sexp()
Version
v0.5.6
Bug
add_global_label()stores data correctly into_data["global_label"], but_schematic_data_to_sexp()incore/parser.pynever iterates over that key. The data is silently dropped onsave().Reproducer
Root cause
_schematic_data_to_sexp()has loops forlabels,hierarchical_labels,no_connects, etc. but no loop forglobal_label:Additionally,
label_parser.pyhas_label_to_sexp()and_hierarchical_label_to_sexp()but no_global_label_to_sexp().The
save()method inschematic.pyalso lacks a_sync_global_labels_to_data()call (though the text_element_manager writes directly to_data, so sync may not be strictly needed — the serializer loop is the primary gap).Expected fix
_global_label_to_sexp()tolabel_parser.py(same format as_hierarchical_label_to_sexp(), justglobal_labeltag)_schematic_data_to_sexp()Version
v0.5.6